@elyx-code/project-logic-tree 0.0.6267 → 0.0.6269

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,7 +21,7 @@ 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;`,k6={id:"find-companies-with-multiple-employees-and-bank-account-search-parent-ref-id",type:n.GenericReference,entityId:fe,version:"1",entityType:n.Project},Z6={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},XR={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:L.FixedReturns,index:0,parent:Z6},q6={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},J6={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:XR,writesValues:[],index:0,parent:q6},W6={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:[XR],inputs:[],outputs:[J6],query:x6,successCalls:[],errorCalls:[],error:null,calledByError:[],calledByEntry:[],calledBySuccess:[],x:0,y:0,parent:k6},S6={type:n.GenericReference,id:"employee-mapped-dto-manager-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:GR},z6={type:n.GenericReference,id:"employee-mapped-dto-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},QR={id:Z8,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:S6,parent:z6},Y6={type:n.GenericReference,id:"employee-mapped-dto-department-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:UR},H6={type:n.GenericReference,id:"employee-mapped-dto-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},eD={id:k8,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:Y6,parent:H6},K6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:jR},X6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},tD={id:x8,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:K6,parent:X6},Q6={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:LR},e3={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},iD={id:F8,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:Q6,parent:e3},t3={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:gR},i3={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},rD={id:g8,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:t3,parent:i3},r3={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:np},n3={id:GR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:mi.properties[0],defaultValue:null,index:0,writesValues:[QR],parent:r3},s3={type:n.GenericReference,id:"manager-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:np},a3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,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:Di,asType:!1,isList:!1,parent:s3},o3={type:n.GenericReference,id:"manager-variable-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:$R},l3={type:n.GenericReference,id:"manager-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},nD={constant:!0,required:!0,id:np,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Manager",dataType:a3,description:"A variable holding an inherited manager for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:o3,writesValues:[],inputs:[],outputs:[n3],internalCalls:[],parent:l3,x:0,y:0},d3={type:n.GenericReference,id:"random-company-employee-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},u3={id:$R,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Di.properties[2],index:3,writesValues:[nD],parent:d3},p3={type:n.GenericReference,id:"random-company-employee-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},c3={id:UR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Di.properties[0],index:2,writesValues:[eD],parent:p3},f3={type:n.GenericReference,id:"random-company-employee-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},h3={id:jR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Kt.properties[1],index:1,writesValues:[tD],parent:f3},y3={type:n.GenericReference,id:"random-company-employee-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},m3={id:LR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:mi.properties[0],index:0,writesValues:[iD],parent:y3},v3={type:n.GenericReference,id:"random-company-employee-test-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},T3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,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:Di,asType:!1,isList:!1,parent:v3},E3={type:n.GenericReference,id:"random-company-employee-test-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},I3={constant:!0,required:!0,id:hs,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Company employee",dataType:T3,description:"A variable holding a random company employee for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[m3,h3,c3,u3],internalCalls:[],parent:E3,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:FR},b3={type:n.LiteralValue,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-default-value-id",name:N.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},R3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:On},D3={id:FR,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:b3,index:5,readsValue:null,parent:R3},O3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-decl-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},P3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-called-by-success-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},w3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},C3={id:On,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:O3,calledByError:[],calledByEntry:[],calledBySuccess:[P3],successCalls:[ap,zR,xR],errorCalls:[],readsValue:null,writesValues:[SR],inputs:[D3],outputs:[],internalCalls:[],parent:w3,x:0,y:0},V3={type:n.GenericReference,id:"employee-mapped-dto-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},B3={constant:!0,required:!0,id:Yi,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:[ap,C3],errorCalls:[],readsValue:null,writesValues:[qR],inputs:[rD,iD,tD,eD,QR],outputs:[],internalCalls:[],parent:V3,x:0,y:0},_3={type:n.GenericReference,id:"0e63e617-f9d3-42e8-bde0-1bb0b1df7034",version:"1",entityType:n.VariableDeclaration,entityId:iA},M3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,inferred:!1,id:"e75645ce-d3df-4f07-a897-ae9ef4d917fd",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:Du,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:_3},N3={type:n.GenericReference,id:"e92a8ff5-3fef-4e0c-8d8f-92c930b2890b",version:"1",entityType:n.Project,entityId:fe},sD={constant:!0,required:!0,id:iA,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:M3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:N3},L3={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:NR},j3={id:gR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:mi.properties[0],index:0,writesValues:[rD],parent:L3},U3={type:n.GenericReference,id:"global-user-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},$3={id:NR,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:sD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[j3],internalCalls:[],parent:U3,x:0,y:0},G3={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"},g3={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"},F3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,inferred:!1,id:"is-test-environment-variable-dcl-datatype-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:nr,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:G3},x3={type:n.GenericReference,id:"is-test-environment-variable-dcl-main-project-ref-id",version:"1",entityType:n.Project,entityId:fe},aD={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:N.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:g3},dataType:F3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:x3},k3={type:n.GenericReference,id:"is-test-environment-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},Z3={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:aD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[],internalCalls:[],parent:k3,x:0,y:0},pp={type:n.Project,id:fe,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:[M8],entities:[Ru,mi,Du,Kt,D$,Di,zo,EA,IA,os,rU,Oi,KU,bu,TB,l$,tU],functions:[Kx,kA,xu,ak,yk,eb,ku,Cu,C8,VA,n9],events:[r2],variableDeclarations:[aD,sD,Su,I3,nD,B3],variableInstances:[Z3,$3],conditions:[],operations:[ps],functionCalls:[r4,hG],loops:[F6,ap,zR,B6,xR],searches:[W6]};var oD={exports:{}};(function(r,a){(function(e,t){r.exports=t()})(FC,function(){var e=1e3,t=6e4,i=36e5,s="millisecond",l="second",o="minute",d="hour",u="day",f="week",c="month",E="quarter",I="year",D="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(ve){var ie=["th","st","nd","rd"],Y=ve%100;return"["+ve+(ie[(Y-20)%10]||ie[Y]||ie[0])+"]"}},B=function(ve,ie,Y){var ue=String(ve);return!ue||ue.length>=ie?ve:""+Array(ie+1-ue.length).join(Y)+ve},g={s:B,z:function(ve){var ie=-ve.utcOffset(),Y=Math.abs(ie),ue=Math.floor(Y/60),te=Y%60;return(ie<=0?"+":"-")+B(ue,2,"0")+":"+B(te,2,"0")},m:function ve(ie,Y){if(ie.date()<Y.date())return-ve(Y,ie);var ue=12*(Y.year()-ie.year())+(Y.month()-ie.month()),te=ie.clone().add(ue,c),Ge=Y-te<0,ge=ie.clone().add(ue+(Ge?-1:1),c);return+(-(ue+(Y-te)/(Ge?te-ge:ge-te))||0)},a:function(ve){return ve<0?Math.ceil(ve)||0:Math.floor(ve)},p:function(ve){return{M:c,y:I,w:f,d:u,D,h:d,m:o,s:l,ms:s,Q:E}[ve]||String(ve||"").toLowerCase().replace(/s$/,"")},u:function(ve){return ve===void 0}},q="en",S={};S[q]=G;var Q="$isDayjsObject",pe=function(ve){return ve instanceof gt||!(!ve||!ve[Q])},me=function ve(ie,Y,ue){var te;if(!ie)return q;if(typeof ie=="string"){var Ge=ie.toLowerCase();S[Ge]&&(te=Ge),Y&&(S[Ge]=Y,te=Ge);var ge=ie.split("-");if(!te&&ge.length>1)return ve(ge[0])}else{var ct=ie.name;S[ct]=ie,te=ct}return!ue&&te&&(q=te),te||!ue&&q},X=function(ve,ie){if(pe(ve))return ve.clone();var Y=typeof ie=="object"?ie:{};return Y.date=ve,Y.args=arguments,new gt(Y)},oe=g;oe.l=me,oe.i=pe,oe.w=function(ve,ie){return X(ve,{locale:ie.$L,utc:ie.$u,x:ie.$x,$offset:ie.$offset})};var gt=function(){function ve(Y){this.$L=me(Y.locale,null,!0),this.parse(Y),this.$x=this.$x||Y.x||{},this[Q]=!0}var ie=ve.prototype;return ie.parse=function(Y){this.$d=function(ue){var te=ue.date,Ge=ue.utc;if(te===null)return new Date(NaN);if(oe.u(te))return new Date;if(te instanceof Date)return new Date(te);if(typeof te=="string"&&!/Z$/i.test(te)){var ge=te.match(V);if(ge){var ct=ge[2]-1||0,Rt=(ge[7]||"0").substring(0,3);return Ge?new Date(Date.UTC(ge[1],ct,ge[3]||1,ge[4]||0,ge[5]||0,ge[6]||0,Rt)):new Date(ge[1],ct,ge[3]||1,ge[4]||0,ge[5]||0,ge[6]||0,Rt)}}return new Date(te)}(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 oe},ie.isValid=function(){return this.$d.toString()!==P},ie.isSame=function(Y,ue){var te=X(Y);return this.startOf(ue)<=te&&te<=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,te){return oe.u(Y)?this[ue]:this.set(te,Y)},ie.unix=function(){return Math.floor(this.valueOf()/1e3)},ie.valueOf=function(){return this.$d.getTime()},ie.startOf=function(Y,ue){var te=this,Ge=!!oe.u(ue)||ue,ge=oe.p(Y),ct=function(Fn,ci){var ln=oe.w(te.$u?Date.UTC(te.$y,ci,Fn):new Date(te.$y,ci,Fn),te);return Ge?ln:ln.endOf(u)},Rt=function(Fn,ci){return oe.w(te.toDate()[Fn].apply(te.toDate("s"),(Ge?[0,0,0,0]:[23,59,59,999]).slice(ci)),te)},Lt=this.$W,zt=this.$M,Vi=this.$D,Bs="set"+(this.$u?"UTC":"");switch(ge){case I:return Ge?ct(1,0):ct(31,11);case c:return Ge?ct(1,zt):ct(0,zt+1);case f:var gn=this.$locale().weekStart||0,Wa=(Lt<gn?Lt+7:Lt)-gn;return ct(Ge?Vi-Wa:Vi+(6-Wa),zt);case u:case D:return Rt(Bs+"Hours",0);case d:return Rt(Bs+"Minutes",1);case o:return Rt(Bs+"Seconds",2);case l:return Rt(Bs+"Milliseconds",3);default:return this.clone()}},ie.endOf=function(Y){return this.startOf(Y,!1)},ie.$set=function(Y,ue){var te,Ge=oe.p(Y),ge="set"+(this.$u?"UTC":""),ct=(te={},te[u]=ge+"Date",te[D]=ge+"Date",te[c]=ge+"Month",te[I]=ge+"FullYear",te[d]=ge+"Hours",te[o]=ge+"Minutes",te[l]=ge+"Seconds",te[s]=ge+"Milliseconds",te)[Ge],Rt=Ge===u?this.$D+(ue-this.$W):ue;if(Ge===c||Ge===I){var Lt=this.clone().set(D,1);Lt.$d[ct](Rt),Lt.init(),this.$d=Lt.set(D,Math.min(this.$D,Lt.daysInMonth())).$d}else ct&&this.$d[ct](Rt);return this.init(),this},ie.set=function(Y,ue){return this.clone().$set(Y,ue)},ie.get=function(Y){return this[oe.p(Y)]()},ie.add=function(Y,ue){var te,Ge=this;Y=Number(Y);var ge=oe.p(ue),ct=function(zt){var Vi=X(Ge);return oe.w(Vi.date(Vi.date()+Math.round(zt*Y)),Ge)};if(ge===c)return this.set(c,this.$M+Y);if(ge===I)return this.set(I,this.$y+Y);if(ge===u)return ct(1);if(ge===f)return ct(7);var Rt=(te={},te[o]=t,te[d]=i,te[l]=e,te)[ge]||1,Lt=this.$d.getTime()+Y*Rt;return oe.w(Lt,this)},ie.subtract=function(Y,ue){return this.add(-1*Y,ue)},ie.format=function(Y){var ue=this,te=this.$locale();if(!this.isValid())return te.invalidDate||P;var Ge=Y||"YYYY-MM-DDTHH:mm:ssZ",ge=oe.z(this),ct=this.$H,Rt=this.$m,Lt=this.$M,zt=te.weekdays,Vi=te.months,Bs=te.meridiem,gn=function(ci,ln,Sa,dd){return ci&&(ci[ln]||ci(ue,Ge))||Sa[ln].slice(0,dd)},Wa=function(ci){return oe.s(ct%12||12,ci,"0")},Fn=Bs||function(ci,ln,Sa){var dd=ci<12?"AM":"PM";return Sa?dd.toLowerCase():dd};return Ge.replace(M,function(ci,ln){return ln||function(Sa){switch(Sa){case"YY":return String(ue.$y).slice(-2);case"YYYY":return oe.s(ue.$y,4,"0");case"M":return Lt+1;case"MM":return oe.s(Lt+1,2,"0");case"MMM":return gn(te.monthsShort,Lt,Vi,3);case"MMMM":return gn(Vi,Lt);case"D":return ue.$D;case"DD":return oe.s(ue.$D,2,"0");case"d":return String(ue.$W);case"dd":return gn(te.weekdaysMin,ue.$W,zt,2);case"ddd":return gn(te.weekdaysShort,ue.$W,zt,3);case"dddd":return zt[ue.$W];case"H":return String(ct);case"HH":return oe.s(ct,2,"0");case"h":return Wa(1);case"hh":return Wa(2);case"a":return Fn(ct,Rt,!0);case"A":return Fn(ct,Rt,!1);case"m":return String(Rt);case"mm":return oe.s(Rt,2,"0");case"s":return String(ue.$s);case"ss":return oe.s(ue.$s,2,"0");case"SSS":return oe.s(ue.$ms,3,"0");case"Z":return ge}return null}(ci)||ge.replace(":","")})},ie.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},ie.diff=function(Y,ue,te){var Ge,ge=this,ct=oe.p(ue),Rt=X(Y),Lt=(Rt.utcOffset()-this.utcOffset())*t,zt=this-Rt,Vi=function(){return oe.m(ge,Rt)};switch(ct){case I:Ge=Vi()/12;break;case c:Ge=Vi();break;case E:Ge=Vi()/3;break;case f:Ge=(zt-Lt)/6048e5;break;case u:Ge=(zt-Lt)/864e5;break;case d:Ge=zt/i;break;case o:Ge=zt/t;break;case l:Ge=zt/e;break;default:Ge=zt}return te?Ge:oe.a(Ge)},ie.daysInMonth=function(){return this.endOf(c).$D},ie.$locale=function(){return S[this.$L]},ie.locale=function(Y,ue){if(!Y)return this.$L;var te=this.clone(),Ge=me(Y,ue,!0);return Ge&&(te.$L=Ge),te},ie.clone=function(){return oe.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()},ve}(),ir=gt.prototype;return X.prototype=ir,[["$ms",s],["$s",l],["$m",o],["$H",d],["$W",u],["$M",c],["$y",I],["$D",D]].forEach(function(ve){ir[ve[1]]=function(ie){return this.$g(ie,ve[0],ve[1])}}),X.extend=function(ve,ie){return ve.$i||(ve(ie,gt,X),ve.$i=!0),X},X.locale=me,X.isDayjs=pe,X.unix=function(ve){return X(1e3*ve)},X.en=S[q],X.Ls=S,X.p={},X})})(oD);var q3=oD.exports;const T=NI(q3);var O=(r=>(r.Error="error",r.Warning="warning",r))(O||{}),$=(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))($||{}),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){h(this,"id");h(this,"message");h(this,"issue");h(this,"severity");h(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 $?new Ye({id:this.id,message:this.message,issue:this.issue,severity:this.severity,code:this.code,entity:a}):null}}class Ye{constructor(a){h(this,"id");h(this,"message");h(this,"issue");h(this,"severity");h(this,"code");h(this,"entity");h(this,"firstRelationship");h(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 Ye({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 J3(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 Ye(r)}}function W3(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 Ke(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 fa=v.union([v.string(),v.number(),v.boolean(),v.date()]),lD=v.enum([vt.CurrentDateAndTime,vt.Random,vt.Unique]),ll=v.object({type:lD,rangeStart:fa.nullable(),rangeEnd:fa.nullable()}),ha=ll.extend({type:v.literal(vt.Random),rangeStart:fa,rangeEnd:fa}),cp=ll.extend({type:v.literal(vt.Unique),rangeStart:v.null(),rangeEnd:v.null()}),dD=ll.extend({type:v.literal(vt.CurrentDateAndTime),rangeStart:v.null(),rangeEnd:v.null()}),dl=ha.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),uD=dl.extend({rangeStart:v.number(),rangeEnd:v.null()}),pD=dl.extend({rangeStart:v.null(),rangeEnd:v.number()}),cD=dl.extend({rangeStart:v.number(),rangeEnd:v.number()}),ul=ha.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),fD=ul.extend({rangeStart:v.number(),rangeEnd:v.null()}),hD=ul.extend({rangeStart:v.null(),rangeEnd:v.number()}),yD=ul.extend({rangeStart:v.number(),rangeEnd:v.number()}),pl=ha.extend({rangeStart:v.date().nullable(),rangeEnd:v.date().nullable()}),mD=pl.extend({rangeStart:v.date(),rangeEnd:v.null()}),vD=pl.extend({rangeStart:v.null(),rangeEnd:v.date()}),TD=pl.extend({rangeStart:v.date(),rangeEnd:v.date()}),fp=ha.extend({rangeStart:v.null(),rangeEnd:v.null()}),hp=v.union([fD,hD,yD]),yp=v.union([uD,pD,cD]),mp=v.union([mD,vD,TD,dD]),vp=v.union([hp,yp,mp,cp,fp]);function ya(){return v.union([v.object({type:v.literal(n.ValueDescriptor)}),v.record(v.string(),v.any())])}function ED(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ValueDescriptor)})}function Tp(){return v.object({id:v.string(),type:v.literal(n.ValueDescriptor),name:v.string(),required:v.boolean()})}function S3(){return Tp().merge(v.object({version:v.number(),index:v.number()}))}function z3(){return Tp().merge(v.object({}))}function Y3(){return v.object({dataType:Vn(),parent:wn()})}function H3(){return S3().merge(Y3())}function cl(){return v.union([v.object({type:v.literal(n.PrimitiveEntity)}),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.PrimitiveEntity)})}function hl(){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 K3(){return hl().merge(v.object({version:v.number()}))}function X3(){return hl().merge(v.object({}))}function Q3(){return v.object({properties:v.array(Pn()),methods:v.array(Ti()),abstractMethods:v.array(Hi()),extends:v.array(v.union([cl(),ys()]))})}function e5(){return K3().merge(Q3())}function Pn(){return v.union([v.object({type:v.literal(n.Property)}),v.record(v.string(),v.any())])}function ID(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Property)})}function Ep(){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 t5(){return Ep().merge(v.object({version:v.number(),index:v.number()}))}function i5(){return Ep().merge(v.object({}))}function r5(){return v.object({dataType:Vn(),implements:Pn().nullable(),parent:v.union([Mn(),fl(),yl()])})}function n5(){return t5().merge(r5())}function s5(){return v.enum([W.CRON_JOB,W.EXECUTION,W.HTTP_ENDPOINT,W.PERSISTED_ENTITY,W.RELATIONAL_DATABASE])}function ys(){return v.union([v.object({type:v.literal(n.BuiltInBaseEntity)}),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.BuiltInBaseEntity)})}function Ip(){return v.object({id:v.string(),version:v.number(),type:v.literal(n.BuiltInBaseEntity),name:s5(),description:v.string().nullable(),abstract:v.boolean(),static:v.boolean()})}function a5(){return Ip()}function o5(){return Ip().merge(v.object({}))}function l5(){return v.object({properties:v.array(Pn()),methods:v.array(Ti()),abstractMethods:v.array(Hi()),extends:v.array(v.union([ys(),cl()]))})}function d5(){return a5().merge(l5())}function Hi(){return v.union([v.object({type:v.literal(n.ActionDescriptor)}),v.record(v.string(),v.any())])}function wn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ActionDescriptor)})}function ml(){return v.object({id:v.string(),type:v.literal(n.ActionDescriptor),name:v.string(),description:v.string().nullable()})}function u5(){return ml().merge(v.object({version:v.number()}))}function p5(){return ml().merge(v.object({}))}function c5(){return v.object({inputs:v.array(ya()),outputs:v.array(ya()),parent:v.union([oi(),Mn(),yl(),fl()]).nullable()})}function AD(){return u5().merge(c5())}function ms(){return v.union([v.object({type:v.literal(n.Loop)}),v.record(v.string(),v.any())])}function Ki(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Loop)})}function bD(){return v.object({id:v.string(),type:v.literal(n.Loop)})}function f5(){return bD().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function h5(){return bD().merge(v.object({declaration:v.union([v.string(),Ti()])}))}function y5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),declaration:Hi(),inputs:v.array(Li()),outputs:v.array(ei()),outputsDeclarations:v.array(ya()),successCalls:v.array(Ct()),errorCalls:v.array(Ct()),error:ei(),body:Ti(),parent:v.union([vr(),oi()]),breakStatements:v.array(Is()),continueStatements:v.array(vs())})}function m5(){return f5().merge(y5())}function vs(){return v.union([v.object({type:v.literal(n.ContinueStatement)}),v.record(v.string(),v.any())])}function Ts(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ContinueStatement)})}function Ap(){return v.object({id:v.string(),type:v.literal(n.ContinueStatement)})}function v5(){return Ap().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function T5(){return Ap().merge(v.object({}))}function E5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),outputs:v.array(hr()),throws:v.optional(hr()),parent:Ki()})}function I5(){return v5().merge(E5())}function Cn(){return v.union([v.object({type:v.literal(n.ReturnStatement)}),v.record(v.string(),v.any())])}function Es(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnStatement)})}function bp(){return v.object({id:v.string(),type:v.literal(n.ReturnStatement)})}function A5(){return bp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function b5(){return bp().merge(v.object({}))}function R5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),outputs:v.array(hr()),throws:v.optional(hr()),parent:vr()})}function D5(){return A5().merge(R5())}function hr(){return v.union([v.object({type:v.literal(n.ReturnDeclaration)}),v.record(v.string(),v.any())])}function RD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnDeclaration)})}function Rp(){return v.object({id:v.string(),type:v.literal(n.ReturnDeclaration),name:v.string(),description:v.string().nullable(),isError:v.boolean()})}function O5(){return Rp().merge(v.object({version:v.number(),index:v.number()}))}function P5(){return Rp().merge(v.object({}))}function w5(){return v.object({dataType:Vn().nullable(),readsValue:Aa().nullable(),parent:v.union([Es(),wn(),yr(),Ts()])})}function C5(){return O5().merge(w5())}function Is(){return v.union([v.object({type:v.literal(n.BreakStatement)}),v.record(v.string(),v.any())])}function yr(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.BreakStatement)})}function Dp(){return v.object({id:v.string(),type:v.literal(n.BreakStatement)})}function V5(){return Dp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function B5(){return Dp().merge(v.object({}))}function _5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),outputs:v.array(hr()),throws:v.optional(hr()),parent:Ki()})}function M5(){return V5().merge(_5())}function ei(){return v.union([v.object({type:v.literal(n.OutputMap)}),v.record(v.string(),v.any())])}function Op(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.OutputMap)})}function Pp(){return v.object({id:v.string(),type:v.literal(n.OutputMap)})}function N5(){return Pp().merge(v.object({version:v.number(),index:v.number()}))}function L5(){return Pp().merge(v.object({}))}function j5(){return v.object({writesValues:v.array(mr()),declaration:v.union([hr(),Pn()]),parent:v.union([nt(),Ki(),yr()])})}function U5(){return N5().merge(j5())}function As(){return v.union([v.object({type:v.literal(n.FunctionCall)}),v.record(v.string(),v.any())])}function ma(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionCall)})}function wp(){return v.object({id:v.string(),type:v.literal(n.FunctionCall)})}function $5(){return wp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function G5(){return wp().merge(v.object({}))}function g5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),writesValues:v.array(mr()),declaration:Ti(),inputs:v.array(Li()),outputs:v.array(ei()),error:v.optional(ei()),parent:v.union([vr(),oi()])})}function F5(){return $5().merge(g5())}function x5(){return v.enum([ft.Equal,ft.NotEqual,ft.MoreThan,ft.MoreThanOrEqual,ft.LessThan,ft.LessThanOrEqual,ft.And,ft.Or,bi.Empty,bi.NotEmpty])}function va(){return v.union([v.object({type:v.literal(n.Condition)}),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.Condition)})}function Cp(){return v.object({id:v.string(),type:v.literal(n.Condition)})}function k5(){return Cp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function Z5(){return Cp().merge(v.object({}))}function q5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),leftValue:Li(),rightValue:Li().nullable(),operator:x5(),parent:v.union([vr(),oi()])})}function J5(){return k5().merge(q5())}function Ta(){return v.union([v.object({type:v.literal(n.Search)}),v.record(v.string(),v.any())])}function Ea(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Search)})}function Vp(){return v.object({id:v.string(),type:v.literal(n.Search),name:v.string(),query:v.any(),description:v.string().nullable()})}function W5(){return Vp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function S5(){return Vp().merge(v.object({}))}function z5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),inputsDeclarations:v.array(_n()),inputs:v.array(Li()),outputsDeclarations:v.array(ya()),outputs:v.array(ei()),parent:v.union([vr(),oi()]),error:ei().nullable()})}function Y5(){return W5().merge(z5())}function Ia(){return v.union([v.object({type:v.literal(n.InternalCall)}),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.InternalCall)})}function _p(){return v.object({id:v.string(),type:v.literal(n.InternalCall),index:v.number()})}function H5(){return _p().merge(v.object({version:v.number(),index:v.number()}))}function K5(){return _p().merge(v.object({declaration:v.union([v.string(),Ti()])}))}function X5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),writesValues:v.array(mr()),declaration:Ti(),inputs:v.array(Li()),outputs:v.array(ei()),parent:jr(),error:v.optional(ei())})}function Q5(){return H5().merge(X5())}function Li(){return v.union([v.object({type:v.literal(n.InputMap)}),v.record(v.string(),v.any())])}function Tl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InputMap)})}function Mp(){return v.object({id:v.string(),type:v.literal(n.InputMap),name:v.string().nullable().optional(),description:v.string().nullable().optional()})}function eZ(){return Mp().merge(v.object({version:v.number(),index:v.number()}))}function tZ(){return Mp().merge(v.object({}))}function iZ(){return v.object({defaultValue:Np().nullable(),declaration:v.union([_n(),Pn()]).nullable(),readsValue:Aa().nullable(),parent:v.union([nt(),Tl(),Ki(),yr()])})}function rZ(){return eZ().merge(iZ())}function bs(){return v.union([v.object({type:v.literal(n.Operation)}),v.record(v.string(),v.any())])}function Rs(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Operation)})}function El(){return v.object({id:v.string(),type:v.literal(n.Operation)})}function nZ(){return El().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function sZ(){return El().merge(v.object({}))}function aZ(){return El().merge(v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),writesValues:v.array(mr()),declaration:Hi(),inputs:v.array(Li()),outputs:v.array(ei()),error:v.array(ei()),parent:v.union([vr(),oi()])}))}function oZ(){return nZ().merge(aZ())}function Il(){return v.union([v.string(),v.number(),v.boolean(),v.null(),v.date()])}function DD(){return v.record(v.string(),Il())}function lZ(){return v.array(v.union([Il(),DD()]))}function OD(){return v.union([Il(),DD(),lZ()])}function PD(){return v.union([Il(),OD()])}function wD(){return v.enum([N.String,N.Number,N.Boolean,N.Null,N.Date,N.KeyValue,N.Enum,N.File,N.UUID,N.EntityTemplate,N.ActionDescriptor])}function CD(){return v.union([Mn(),Rs(),ba()])}function dZ(){return v.object({id:v.string(),name:wD(),type:v.literal(n.LiteralValue),value:PD(),autogeneration:vp.nullable()})}function uZ(){return dZ().merge(v.object({}))}function ji(){return v.object({id:v.string(),version:v.number(),name:wD(),type:v.literal(n.LiteralValue),value:PD(),valueAsTypeList:v.array(CD()).nullable(),valueAsTypeSingle:CD().nullable(),autogeneration:vp.nullable(),parent:v.union([Lp(),Tl()])})}function pZ(){return ji().extend({name:v.literal(N.String),value:v.string(),autogeneration:hp.nullable()})}function cZ(){return ji().extend({name:v.literal(N.Number),value:v.number(),autogeneration:yp.nullable()})}function fZ(){return ji().extend({name:v.literal(N.Boolean),value:v.boolean(),autogeneration:fp.nullable()})}function hZ(){return ji().extend({name:v.literal(N.Null),value:v.null(),autogeneration:v.null()})}function yZ(){return ji().extend({name:v.literal(N.Date),value:v.date(),autogeneration:mp.nullable()})}function mZ(){return ji().extend({name:v.literal(N.KeyValue),value:OD(),autogeneration:v.null()})}function vZ(){return ji().extend({name:v.literal(N.Enum),value:v.string(),autogeneration:v.null()})}function TZ(){return ji().extend({name:v.literal(N.File),value:v.string(),autogeneration:v.null()})}function EZ(){return ji().extend({name:v.literal(N.UUID),value:v.string(),autogeneration:cp.nullable()})}function IZ(){return ji().extend({name:v.literal(N.EntityTemplate),value:Mn(),autogeneration:v.null()})}function AZ(){return ji().extend({name:v.literal(N.ActionDescriptor),value:ba(),autogeneration:v.null()})}function Np(){return v.union([pZ(),cZ(),fZ(),hZ(),yZ(),mZ(),vZ(),TZ(),EZ(),IZ(),AZ()])}function Vn(){return v.union([v.object({type:v.literal(n.DataType)}),v.record(v.string(),v.any())])}function Lp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DataType)})}function jp(){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 bZ(){return jp().merge(v.object({version:v.number()}))}function RZ(){return jp().merge(v.object({}))}function DZ(){return v.object({defaultValue:Np().nullable(),entity:v.union([Ds(),ys(),cl(),Hi()]).nullable(),parent:v.union([ID(),_D(),ED()])})}function OZ(){return bZ().merge(DZ())}function Up(){return v.union([v.object({type:v.literal(n.VariableDeclaration)}),v.record(v.string(),v.any())])}function PZ(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableDeclaration)})}function $p(){return v.object({id:v.string(),type:v.literal(n.VariableDeclaration),name:v.string(),description:v.string().nullable()})}function wZ(){return $p().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function CZ(){return $p().merge(v.object({}))}function VZ(){return v.object({dataType:Vn().nullable(),readsValue:Aa().nullable(),writesValues:v.array(mr()),inputs:v.array(Li()),outputs:v.array(ei()),successCalls:v.array(Ct()),errorCalls:v.array(Ct()),internalCalls:v.array(Ia()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),parent:v.union([vr(),oi()])})}function BZ(){return wZ().merge(VZ())}function VD(){return v.union([v.object({type:v.literal(n.VariableInstance)}),v.record(v.string(),v.any())])}function _Z(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableInstance)})}function Gp(){return v.object({id:v.string(),type:v.literal(n.VariableInstance)})}function MZ(){return Gp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function NZ(){return Gp().merge(v.object({}))}function LZ(){return v.object({declaration:Up(),dataType:Vn().nullable(),readsValue:Aa().nullable(),writesValues:v.array(mr()),inputs:v.array(Li()),outputs:v.array(ei()),successCalls:v.array(Ct()),errorCalls:v.array(Ct()),internalCalls:v.array(Ia()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),parent:v.union([vr(),oi()])})}function jZ(){return MZ().merge(LZ())}function gp(){return v.union([v.object({type:v.literal(n.InstalledProject)}),v.record(v.string(),v.any())])}function Al(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InstalledProject)})}function UZ(){return v.object({id:v.string(),type:v.literal(n.InstalledProject)})}function $Z(){return v.object({version:v.number(),x:v.number(),y:v.number()})}function GZ(){return v.object({})}function gZ(){return v.object({implements:oi(),description:v.string().nullable(),functions:v.array(Ti()),events:v.array(Fp()),parent:oi()})}function FZ(){return $Z().merge(gZ())}function Fp(){return v.union([v.object({type:v.literal(n.GlobalEvent)}),v.record(v.string(),v.any())])}function xZ(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.GlobalEvent)})}function bl(){return v.object({id:v.string(),type:v.literal(n.GlobalEvent),name:v.string(),collapsed:v.boolean()})}function kZ(){return bl().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function ZZ(){return bl().merge(v.object({}))}function qZ(){return bl().merge(v.object({returnStatements:v.array(Cn()),implements:v.array(AD()),inputs:v.array(_n()),calls:v.array(Ct()),parent:v.union([oi(),Al()])}))}function JZ(){return kZ().merge(qZ())}function Bn(){return v.union([Up(),VD()])}function jr(){return v.union([PZ(),_Z()])}function mr(){return v.union([Bn(),Li(),hr()])}function BD(){return v.union([jr(),Tl(),RD()])}function Aa(){return v.union([Bn(),_n(),ei(),bs(),Ia(),As()])}function WZ(){return v.union([jr(),xp(),Op(),Rs(),Bp(),ma()])}function SZ(){return v.union([_n(),ei(),mr()])}function _D(){return v.union([xp(),Op(),BD()])}function Rl(){return Fp()}function Dl(){return xZ()}function Ol(){return v.union([bs(),As(),va(),Ta(),Bn(),Ia(),ms()])}function nt(){return v.union([Rs(),ma(),vl(),Ea(),jr(),Bp(),Ki()])}function Pl(){return v.union([bs(),As(),va(),Ta(),Bn(),ms()])}function wl(){return v.union([Rs(),ma(),vl(),Ea(),jr(),Ki()])}function MD(){return v.union([Ol(),Cn(),Is(),vs()])}function Ct(){return v.union([nt(),Es(),yr(),Ts()])}function ND(){return v.union([Pl(),Cn(),Is(),vs()])}function LD(){return v.union([wl(),Es(),yr(),Ts()])}function Ur(){return v.union([Ti(),Rl()])}function Ot(){return v.union([ba(),Dl()])}function zZ(){return v.union([Ol(),Ur()])}function YZ(){return v.union([nt(),Ot()])}function HZ(){return v.union([Pl(),Ur()])}function KZ(){return v.union([wl(),Ot()])}function XZ(){return v.union([MD(),Ur()])}function QZ(){return v.union([Ct(),Ot()])}function e7(){return v.union([ND(),Ur()])}function t7(){return v.union([LD(),Ot()])}function i7(){return v.union([Ur(),ms()])}function vr(){return v.union([Ot(),Ki()])}function r7(){return v.union([Ol(),Ur()])}function n7(){return v.union([nt(),Ot()])}function s7(){return v.union([Pl(),Ur()])}function a7(){return v.union([wl(),Ot()])}function o7(){return v.union([Cn(),Is(),vs()])}function l7(){return v.union([Es(),yr(),Ts()])}function d7(){return v.union([ys(),A7(),gp(),Ds(),Ti(),Rl(),Bn(),Li(),ei(),va(),bs(),As(),hr(),_n(),cl(),Vn(),Pn(),Hi(),Cn(),vs(),Is(),ms(),Ta(),Hi(),Hi(),ya(),Ia()])}function u7(){return v.union([yl(),oi(),Al(),Mn(),ba(),Dl(),jr(),Tl(),Op(),vl(),Rs(),ma(),RD(),xp(),fl(),Lp(),ID(),wn(),Es(),Ts(),yr(),Ki(),Ea(),wn(),wn(),ED(),Bp()])}function p7(){return v.union([gp(),Ds(),Ti(),Rl(),Bn(),va(),bs(),As(),Cn(),vs(),Is(),ms(),Ta()])}function c7(){return v.union([Al(),Mn(),ba(),Dl(),jr(),vl(),Rs(),ma(),Es(),Ts(),yr(),Ki(),Ea()])}function _n(){return v.union([v.object({type:v.literal(n.ArgumentDeclaration)}),v.record(v.string(),v.any())])}function xp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ArgumentDeclaration)})}function kp(){return v.object({id:v.string(),type:v.literal(n.ArgumentDeclaration)})}function f7(){return kp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function h7(){return kp().merge(v.object({}))}function y7(){return v.object({dataType:Vn().nullable(),writesValues:v.array(mr()),parent:v.union([Ot(),wn(),wn(),Ea(),yr()])})}function m7(){return f7().merge(y7())}function Ti(){return v.union([v.object({type:v.literal(n.FunctionDeclaration)}),v.record(v.string(),v.any())])}function ba(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionDeclaration)})}function Zp(){return v.object({id:v.string(),type:v.literal(n.FunctionDeclaration),name:v.string(),description:v.string().nullable()})}function v7(){return Zp().merge(v.object({version:v.number(),x:v.number(),y:v.number(),index:v.number().nullable()}))}function T7(){return Zp()}function E7(){return v.object({inputs:v.array(_n()),implements:Hi().nullable(),returnStatements:v.array(Cn()),parent:v.union([oi(),Al(),Mn(),Ki(),yl(),fl()])})}function I7(){return v7().merge(E7())}function A7(){return v.union([v.object({type:v.literal(n.Project)}),v.record(v.string(),v.any())])}function oi(){return v.object({entityType:v.literal(n.Project),entityId:v.string(),id:v.string(),type:v.literal(n.GenericReference)})}function qp(){return v.object({id:v.string(),type:v.literal(n.Project),name:v.string(),description:v.string().nullable()})}function b7(){return qp().merge(v.object({version:v.number()}))}function R7(){return qp()}function D7(){return v.object({entities:v.array(Ds()),functions:v.array(Ti()),events:v.array(Fp()),projects:v.array(gp()),variableDeclarations:v.array(Up()),variableInstances:v.array(VD()),conditions:v.array(va()),operations:v.array(bs()),functionCalls:v.array(As()),loops:v.array(ms()),searches:v.array(Ta())})}function O7(){return b7().merge(D7())}function Ds(){return v.union([v.object({type:v.literal(n.DefinitionEntity)}),v.record(v.string(),v.any())])}function Mn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DefinitionEntity)})}function Jp(){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 P7(){return Jp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function w7(){return Jp().merge(v.object({}))}function C7(){return v.union([oi(),Lp()])}function V7(){return v.object({properties:v.array(Pn()),methods:v.array(Ti()),abstractMethods:v.array(Hi()),extends:v.array(v.union([Ds(),ys()])),implements:v.array(v.union([Ds(),ys()])),parent:C7()})}function B7(){return P7().merge(V7())}function _7(r){return r instanceof Error&&r.name==="ZodError"&&"issues"in r&&Array.isArray(r.issues)}var M7=class extends Error{constructor(a,e){super(a,e);h(this,"name");h(this,"details");this.name="ZodValidationError",this.details=N7(e)}toString(){return this.message}};function N7(r){if(r){const a=r.cause;if(_7(a))return a.issues}return[]}function L7(r){return r.length!==0}var j7=/[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;function U7(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+'["'+$7(e)+'"]';if(!j7.test(e))return a+'["'+e+'"]';const t=a.length===0?"":".";return a+t+e},"")}function $7(r){return r.replace(/"/g,'\\"')}var G7="; ",g7=99,jD="Validation error",F7=": ",x7=", or ";function k7(r={}){const{issueSeparator:a=G7,unionSeparator:e=x7,prefixSeparator:t=F7,prefix:i=jD,includePath:s=!0,maxIssuesInMessage:l=g7}=r;return o=>{const d=o.slice(0,l).map(u=>Cl({issue:u,issueSeparator:a,unionSeparator:e,includePath:s})).join(a);return Z7(d,i,t)}}function Cl(r){const{issue:a,issueSeparator:e,unionSeparator:t,includePath:i}=r;if(a.code===Z.invalid_union)return a.unionErrors.reduce((s,l)=>{const o=l.issues.map(d=>Cl({issue:d,issueSeparator:e,unionSeparator:t,includePath:i})).join(e);return s.includes(o)||s.push(o),s},[]).join(t);if(a.code===Z.invalid_arguments)return[a.message,...a.argumentsError.issues.map(s=>Cl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(a.code===Z.invalid_return_type)return[a.message,...a.returnTypeError.issues.map(s=>Cl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(i&&L7(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 "${U7(a.path)}"`}return a.message}function Z7(r,a,e){return a!==null?r.length>0?[a,r].join(e):a:r.length>0?r:jD}function q7(r,a={}){const t=J7(a)([r]);return new M7(t,{cause:new ai([r])})}function J7(r){return"messageBuilder"in r?r.messageBuilder:k7(r)}var UD="1.13.7",$D=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global||Function("return this")()||{},Vl=Array.prototype,Wp=Object.prototype,GD=typeof Symbol<"u"?Symbol.prototype:null,W7=Vl.push,Ra=Vl.slice,Da=Wp.toString,S7=Wp.hasOwnProperty,gD=typeof ArrayBuffer<"u",z7=typeof DataView<"u",Y7=Array.isArray,FD=Object.keys,xD=Object.create,kD=gD&&ArrayBuffer.isView,H7=isNaN,K7=isFinite,ZD=!{toString:null}.propertyIsEnumerable("toString"),qD=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],X7=Math.pow(2,53)-1;function li(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 $r(r){var a=typeof r;return a==="function"||a==="object"&&!!r}function Q7(r){return r===null}function JD(r){return r===void 0}function WD(r){return r===!0||r===!1||Da.call(r)==="[object Boolean]"}function eq(r){return!!(r&&r.nodeType===1)}function Jt(r){var a="[object "+r+"]";return function(e){return Da.call(e)===a}}const Sp=Jt("String"),SD=Jt("Number"),tq=Jt("Date"),iq=Jt("RegExp"),rq=Jt("Error"),zD=Jt("Symbol"),YD=Jt("ArrayBuffer");var HD=Jt("Function"),nq=$D.document&&$D.document.childNodes;typeof/./!="function"&&typeof Int8Array!="object"&&typeof nq!="function"&&(HD=function(r){return typeof r=="function"||!1});const ti=HD,KD=Jt("Object");var XD=z7&&(!/\[native code\]/.test(String(DataView))||KD(new DataView(new ArrayBuffer(8)))),zp=typeof Map<"u"&&KD(new Map),sq=Jt("DataView");function aq(r){return r!=null&&ti(r.getInt8)&&YD(r.buffer)}const Bl=XD?aq:sq,Nn=Y7||Jt("Array");function Gr(r,a){return r!=null&&S7.call(r,a)}var Yp=Jt("Arguments");(function(){Yp(arguments)||(Yp=function(r){return Gr(r,"callee")})})();const Hp=Yp;function oq(r){return!zD(r)&&K7(r)&&!isNaN(parseFloat(r))}function QD(r){return SD(r)&&H7(r)}function eO(r){return function(){return r}}function tO(r){return function(a){var e=r(a);return typeof e=="number"&&e>=0&&e<=X7}}function iO(r){return function(a){return a==null?void 0:a[r]}}const _l=iO("byteLength"),lq=tO(_l);var dq=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;function uq(r){return kD?kD(r)&&!Bl(r):lq(r)&&dq.test(Da.call(r))}const rO=gD?uq:eO(!1),di=iO("length");function pq(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 nO(r,a){a=pq(a);var e=qD.length,t=r.constructor,i=ti(t)&&t.prototype||Wp,s="constructor";for(Gr(r,s)&&!a.contains(s)&&a.push(s);e--;)s=qD[e],s in r&&r[s]!==i[s]&&!a.contains(s)&&a.push(s)}function Nt(r){if(!$r(r))return[];if(FD)return FD(r);var a=[];for(var e in r)Gr(r,e)&&a.push(e);return ZD&&nO(r,a),a}function Oa(r){if(r==null)return!0;var a=di(r);return typeof a=="number"&&(Nn(r)||Sp(r)||Hp(r))?a===0:di(Nt(r))===0}function sO(r,a){var e=Nt(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 Xe(r){if(r instanceof Xe)return r;if(!(this instanceof Xe))return new Xe(r);this._wrapped=r}Xe.VERSION=UD,Xe.prototype.value=function(){return this._wrapped},Xe.prototype.valueOf=Xe.prototype.toJSON=Xe.prototype.value,Xe.prototype.toString=function(){return String(this._wrapped)};function aO(r){return new Uint8Array(r.buffer||r,r.byteOffset||0,_l(r))}var oO="[object DataView]";function Kp(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:lO(r,a,e,t)}function lO(r,a,e,t){r instanceof Xe&&(r=r._wrapped),a instanceof Xe&&(a=a._wrapped);var i=Da.call(r);if(i!==Da.call(a))return!1;if(XD&&i=="[object Object]"&&Bl(r)){if(!Bl(a))return!1;i=oO}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 GD.valueOf.call(r)===GD.valueOf.call(a);case"[object ArrayBuffer]":case oO:return lO(aO(r),aO(a),e,t)}var s=i==="[object Array]";if(!s&&rO(r)){var l=_l(r);if(l!==_l(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&&!(ti(o)&&o instanceof o&&ti(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(!Kp(r[u],a[u],e,t))return!1}else{var f=Nt(r),c;if(u=f.length,Nt(a).length!==u)return!1;for(;u--;)if(c=f[u],!(Gr(a,c)&&Kp(r[c],a[c],e,t)))return!1}return e.pop(),t.pop(),!0}function cq(r,a){return Kp(r,a)}function Pa(r){if(!$r(r))return[];var a=[];for(var e in r)a.push(e);return ZD&&nO(r,a),a}function Xp(r){var a=di(r);return function(e){if(e==null)return!1;var t=Pa(e);if(di(t))return!1;for(var i=0;i<a;i++)if(!ti(e[r[i]]))return!1;return r!==pO||!ti(e[Qp])}}var Qp="forEach",dO="has",ec=["clear","delete"],uO=["get",dO,"set"],fq=ec.concat(Qp,uO),pO=ec.concat(uO),hq=["add"].concat(ec,Qp,dO);const yq=zp?Xp(fq):Jt("Map"),mq=zp?Xp(pO):Jt("WeakMap"),vq=zp?Xp(hq):Jt("Set"),Tq=Jt("WeakSet");function Os(r){for(var a=Nt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=r[a[i]];return t}function Eq(r){for(var a=Nt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=[a[i],r[a[i]]];return t}function cO(r){for(var a={},e=Nt(r),t=0,i=e.length;t<i;t++)a[r[e[t]]]=e[t];return a}function tc(r){var a=[];for(var e in r)ti(r[e])&&a.push(e);return a.sort()}function ic(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 fO=ic(Pa),Ml=ic(Nt),hO=ic(Pa,!0);function Iq(){return function(){}}function yO(r){if(!$r(r))return{};if(xD)return xD(r);var a=Iq();a.prototype=r;var e=new a;return a.prototype=null,e}function Aq(r,a){var e=yO(r);return a&&Ml(e,a),e}function bq(r){return $r(r)?Nn(r)?r.slice():fO({},r):r}function Rq(r,a){return a(r),r}function mO(r){return Nn(r)?r:[r]}Xe.toPath=mO;function wa(r){return Xe.toPath(r)}function rc(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 vO(r,a,e){var t=rc(r,wa(a));return JD(t)?e:t}function Dq(r,a){a=wa(a);for(var e=a.length,t=0;t<e;t++){var i=a[t];if(!Gr(r,i))return!1;r=r[i]}return!!e}function nc(r){return r}function Ca(r){return r=Ml({},r),function(a){return sO(a,r)}}function sc(r){return r=wa(r),function(a){return rc(a,r)}}function Va(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 TO(r,a,e){return r==null?nc:ti(r)?Va(r,a,e):$r(r)&&!Nn(r)?Ca(r):sc(r)}function ac(r,a){return TO(r,a,1/0)}Xe.iteratee=ac;function ui(r,a,e){return Xe.iteratee!==ac?Xe.iteratee(r,a):TO(r,a,e)}function Oq(r,a,e){a=ui(a,e);for(var t=Nt(r),i=t.length,s={},l=0;l<i;l++){var o=t[l];s[o]=a(r[o],o,r)}return s}function EO(){}function Pq(r){return r==null?EO:function(a){return vO(r,a)}}function wq(r,a,e){var t=Array(Math.max(0,r));a=Va(a,e,1);for(var i=0;i<r;i++)t[i]=a(i);return t}function oc(r,a){return a==null&&(a=r,r=0),r+Math.floor(Math.random()*(a-r+1))}const Ba=Date.now||function(){return new Date().getTime()};function IO(r){var a=function(s){return r[s]},e="(?:"+Nt(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 AO={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},Cq=IO(AO),Vq=cO(AO),Bq=IO(Vq),_q=Xe.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var lc=/(.)^/,Mq={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Nq=/\\|'|\r|\n|\u2028|\u2029/g;function Lq(r){return"\\"+Mq[r]}var jq=/^\s*(\w|\$)+\s*$/;function Uq(r,a,e){!a&&e&&(a=e),a=hO({},a,Xe.templateSettings);var t=RegExp([(a.escape||lc).source,(a.interpolate||lc).source,(a.evaluate||lc).source].join("|")+"|$","g"),i=0,s="__p+='";r.replace(t,function(u,f,c,E,I){return s+=r.slice(i,I).replace(Nq,Lq),i=I+u.length,f?s+=`'+
24
+ LIMIT 10 OFFSET 0;`,k6={id:"find-companies-with-multiple-employees-and-bank-account-search-parent-ref-id",type:n.GenericReference,entityId:fe,version:"1",entityType:n.Project},Z6={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},XR={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:L.FixedReturns,index:0,parent:Z6},q6={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},J6={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:XR,writesValues:[],index:0,parent:q6},W6={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:[XR],inputs:[],outputs:[J6],query:x6,successCalls:[],errorCalls:[],error:null,calledByError:[],calledByEntry:[],calledBySuccess:[],x:0,y:0,parent:k6},S6={type:n.GenericReference,id:"employee-mapped-dto-manager-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:GR},z6={type:n.GenericReference,id:"employee-mapped-dto-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},QR={id:Z8,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:S6,parent:z6},Y6={type:n.GenericReference,id:"employee-mapped-dto-department-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:UR},H6={type:n.GenericReference,id:"employee-mapped-dto-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},eD={id:k8,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:Y6,parent:H6},K6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:jR},X6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},tD={id:x8,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:K6,parent:X6},Q6={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:LR},e3={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},iD={id:F8,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:Q6,parent:e3},t3={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:gR},i3={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},rD={id:g8,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:t3,parent:i3},r3={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:np},n3={id:GR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:mi.properties[0],defaultValue:null,index:0,writesValues:[QR],parent:r3},s3={type:n.GenericReference,id:"manager-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:np},a3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,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:Di,asType:!1,isList:!1,parent:s3},o3={type:n.GenericReference,id:"manager-variable-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:$R},l3={type:n.GenericReference,id:"manager-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},nD={constant:!0,required:!0,id:np,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Manager",dataType:a3,description:"A variable holding an inherited manager for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:o3,writesValues:[],inputs:[],outputs:[n3],internalCalls:[],parent:l3,x:0,y:0},d3={type:n.GenericReference,id:"random-company-employee-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},u3={id:$R,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Di.properties[2],index:3,writesValues:[nD],parent:d3},p3={type:n.GenericReference,id:"random-company-employee-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},c3={id:UR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Di.properties[0],index:2,writesValues:[eD],parent:p3},f3={type:n.GenericReference,id:"random-company-employee-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},h3={id:jR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Kt.properties[1],index:1,writesValues:[tD],parent:f3},y3={type:n.GenericReference,id:"random-company-employee-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},m3={id:LR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:mi.properties[0],index:0,writesValues:[iD],parent:y3},v3={type:n.GenericReference,id:"random-company-employee-test-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:hs},T3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,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:Di,asType:!1,isList:!1,parent:v3},E3={type:n.GenericReference,id:"random-company-employee-test-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},I3={constant:!0,required:!0,id:hs,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Company employee",dataType:T3,description:"A variable holding a random company employee for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[m3,h3,c3,u3],internalCalls:[],parent:E3,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:FR},b3={type:n.LiteralValue,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-default-value-id",name:N.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},R3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:On},D3={id:FR,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:b3,index:5,readsValue:null,parent:R3},O3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-decl-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},P3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-called-by-success-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Yi},w3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},C3={id:On,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:O3,calledByError:[],calledByEntry:[],calledBySuccess:[P3],successCalls:[ap,zR,xR],errorCalls:[],readsValue:null,writesValues:[SR],inputs:[D3],outputs:[],internalCalls:[],parent:w3,x:0,y:0},V3={type:n.GenericReference,id:"employee-mapped-dto-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},B3={constant:!0,required:!0,id:Yi,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:[ap,C3],errorCalls:[],readsValue:null,writesValues:[qR],inputs:[rD,iD,tD,eD,QR],outputs:[],internalCalls:[],parent:V3,x:0,y:0},_3={type:n.GenericReference,id:"0e63e617-f9d3-42e8-bde0-1bb0b1df7034",version:"1",entityType:n.VariableDeclaration,entityId:iA},M3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,inferred:!1,id:"e75645ce-d3df-4f07-a897-ae9ef4d917fd",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:Du,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:_3},N3={type:n.GenericReference,id:"e92a8ff5-3fef-4e0c-8d8f-92c930b2890b",version:"1",entityType:n.Project,entityId:fe},sD={constant:!0,required:!0,id:iA,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:M3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:N3},L3={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:NR},j3={id:gR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:mi.properties[0],index:0,writesValues:[rD],parent:L3},U3={type:n.GenericReference,id:"global-user-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},$3={id:NR,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:sD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[j3],internalCalls:[],parent:U3,x:0,y:0},G3={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"},g3={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"},F3={like:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,inferred:!1,id:"is-test-environment-variable-dcl-datatype-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:nr,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:G3},x3={type:n.GenericReference,id:"is-test-environment-variable-dcl-main-project-ref-id",version:"1",entityType:n.Project,entityId:fe},aD={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:N.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:g3},dataType:F3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:x3},k3={type:n.GenericReference,id:"is-test-environment-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:fe},Z3={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:aD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[],internalCalls:[],parent:k3,x:0,y:0},pp={type:n.Project,id:fe,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:[M8],entities:[Ru,mi,Du,Kt,D$,Di,zo,EA,IA,os,rU,Oi,KU,bu,TB,l$,tU],functions:[Kx,kA,xu,ak,yk,eb,ku,Cu,C8,VA,n9],events:[r2],variableDeclarations:[aD,sD,Su,I3,nD,B3],variableInstances:[Z3,$3],conditions:[],operations:[ps],functionCalls:[r4,hG],loops:[F6,ap,zR,B6,xR],searches:[W6]};var oD={exports:{}};(function(r,a){(function(e,t){r.exports=t()})(FC,function(){var e=1e3,t=6e4,i=36e5,s="millisecond",l="second",o="minute",d="hour",u="day",f="week",c="month",E="quarter",I="year",D="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(ve){var ie=["th","st","nd","rd"],Y=ve%100;return"["+ve+(ie[(Y-20)%10]||ie[Y]||ie[0])+"]"}},B=function(ve,ie,Y){var de=String(ve);return!de||de.length>=ie?ve:""+Array(ie+1-de.length).join(Y)+ve},g={s:B,z:function(ve){var ie=-ve.utcOffset(),Y=Math.abs(ie),de=Math.floor(Y/60),te=Y%60;return(ie<=0?"+":"-")+B(de,2,"0")+":"+B(te,2,"0")},m:function ve(ie,Y){if(ie.date()<Y.date())return-ve(Y,ie);var de=12*(Y.year()-ie.year())+(Y.month()-ie.month()),te=ie.clone().add(de,c),Ge=Y-te<0,ge=ie.clone().add(de+(Ge?-1:1),c);return+(-(de+(Y-te)/(Ge?te-ge:ge-te))||0)},a:function(ve){return ve<0?Math.ceil(ve)||0:Math.floor(ve)},p:function(ve){return{M:c,y:I,w:f,d:u,D,h:d,m:o,s:l,ms:s,Q:E}[ve]||String(ve||"").toLowerCase().replace(/s$/,"")},u:function(ve){return ve===void 0}},q="en",S={};S[q]=G;var Q="$isDayjsObject",pe=function(ve){return ve instanceof gt||!(!ve||!ve[Q])},me=function ve(ie,Y,de){var te;if(!ie)return q;if(typeof ie=="string"){var Ge=ie.toLowerCase();S[Ge]&&(te=Ge),Y&&(S[Ge]=Y,te=Ge);var ge=ie.split("-");if(!te&&ge.length>1)return ve(ge[0])}else{var ct=ie.name;S[ct]=ie,te=ct}return!de&&te&&(q=te),te||!de&&q},X=function(ve,ie){if(pe(ve))return ve.clone();var Y=typeof ie=="object"?ie:{};return Y.date=ve,Y.args=arguments,new gt(Y)},oe=g;oe.l=me,oe.i=pe,oe.w=function(ve,ie){return X(ve,{locale:ie.$L,utc:ie.$u,x:ie.$x,$offset:ie.$offset})};var gt=function(){function ve(Y){this.$L=me(Y.locale,null,!0),this.parse(Y),this.$x=this.$x||Y.x||{},this[Q]=!0}var ie=ve.prototype;return ie.parse=function(Y){this.$d=function(de){var te=de.date,Ge=de.utc;if(te===null)return new Date(NaN);if(oe.u(te))return new Date;if(te instanceof Date)return new Date(te);if(typeof te=="string"&&!/Z$/i.test(te)){var ge=te.match(V);if(ge){var ct=ge[2]-1||0,Rt=(ge[7]||"0").substring(0,3);return Ge?new Date(Date.UTC(ge[1],ct,ge[3]||1,ge[4]||0,ge[5]||0,ge[6]||0,Rt)):new Date(ge[1],ct,ge[3]||1,ge[4]||0,ge[5]||0,ge[6]||0,Rt)}}return new Date(te)}(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 oe},ie.isValid=function(){return this.$d.toString()!==P},ie.isSame=function(Y,de){var te=X(Y);return this.startOf(de)<=te&&te<=this.endOf(de)},ie.isAfter=function(Y,de){return X(Y)<this.startOf(de)},ie.isBefore=function(Y,de){return this.endOf(de)<X(Y)},ie.$g=function(Y,de,te){return oe.u(Y)?this[de]:this.set(te,Y)},ie.unix=function(){return Math.floor(this.valueOf()/1e3)},ie.valueOf=function(){return this.$d.getTime()},ie.startOf=function(Y,de){var te=this,Ge=!!oe.u(de)||de,ge=oe.p(Y),ct=function(Fn,ci){var ln=oe.w(te.$u?Date.UTC(te.$y,ci,Fn):new Date(te.$y,ci,Fn),te);return Ge?ln:ln.endOf(u)},Rt=function(Fn,ci){return oe.w(te.toDate()[Fn].apply(te.toDate("s"),(Ge?[0,0,0,0]:[23,59,59,999]).slice(ci)),te)},Lt=this.$W,zt=this.$M,Vi=this.$D,Bs="set"+(this.$u?"UTC":"");switch(ge){case I:return Ge?ct(1,0):ct(31,11);case c:return Ge?ct(1,zt):ct(0,zt+1);case f:var gn=this.$locale().weekStart||0,Wa=(Lt<gn?Lt+7:Lt)-gn;return ct(Ge?Vi-Wa:Vi+(6-Wa),zt);case u:case D:return Rt(Bs+"Hours",0);case d:return Rt(Bs+"Minutes",1);case o:return Rt(Bs+"Seconds",2);case l:return Rt(Bs+"Milliseconds",3);default:return this.clone()}},ie.endOf=function(Y){return this.startOf(Y,!1)},ie.$set=function(Y,de){var te,Ge=oe.p(Y),ge="set"+(this.$u?"UTC":""),ct=(te={},te[u]=ge+"Date",te[D]=ge+"Date",te[c]=ge+"Month",te[I]=ge+"FullYear",te[d]=ge+"Hours",te[o]=ge+"Minutes",te[l]=ge+"Seconds",te[s]=ge+"Milliseconds",te)[Ge],Rt=Ge===u?this.$D+(de-this.$W):de;if(Ge===c||Ge===I){var Lt=this.clone().set(D,1);Lt.$d[ct](Rt),Lt.init(),this.$d=Lt.set(D,Math.min(this.$D,Lt.daysInMonth())).$d}else ct&&this.$d[ct](Rt);return this.init(),this},ie.set=function(Y,de){return this.clone().$set(Y,de)},ie.get=function(Y){return this[oe.p(Y)]()},ie.add=function(Y,de){var te,Ge=this;Y=Number(Y);var ge=oe.p(de),ct=function(zt){var Vi=X(Ge);return oe.w(Vi.date(Vi.date()+Math.round(zt*Y)),Ge)};if(ge===c)return this.set(c,this.$M+Y);if(ge===I)return this.set(I,this.$y+Y);if(ge===u)return ct(1);if(ge===f)return ct(7);var Rt=(te={},te[o]=t,te[d]=i,te[l]=e,te)[ge]||1,Lt=this.$d.getTime()+Y*Rt;return oe.w(Lt,this)},ie.subtract=function(Y,de){return this.add(-1*Y,de)},ie.format=function(Y){var de=this,te=this.$locale();if(!this.isValid())return te.invalidDate||P;var Ge=Y||"YYYY-MM-DDTHH:mm:ssZ",ge=oe.z(this),ct=this.$H,Rt=this.$m,Lt=this.$M,zt=te.weekdays,Vi=te.months,Bs=te.meridiem,gn=function(ci,ln,Sa,dd){return ci&&(ci[ln]||ci(de,Ge))||Sa[ln].slice(0,dd)},Wa=function(ci){return oe.s(ct%12||12,ci,"0")},Fn=Bs||function(ci,ln,Sa){var dd=ci<12?"AM":"PM";return Sa?dd.toLowerCase():dd};return Ge.replace(M,function(ci,ln){return ln||function(Sa){switch(Sa){case"YY":return String(de.$y).slice(-2);case"YYYY":return oe.s(de.$y,4,"0");case"M":return Lt+1;case"MM":return oe.s(Lt+1,2,"0");case"MMM":return gn(te.monthsShort,Lt,Vi,3);case"MMMM":return gn(Vi,Lt);case"D":return de.$D;case"DD":return oe.s(de.$D,2,"0");case"d":return String(de.$W);case"dd":return gn(te.weekdaysMin,de.$W,zt,2);case"ddd":return gn(te.weekdaysShort,de.$W,zt,3);case"dddd":return zt[de.$W];case"H":return String(ct);case"HH":return oe.s(ct,2,"0");case"h":return Wa(1);case"hh":return Wa(2);case"a":return Fn(ct,Rt,!0);case"A":return Fn(ct,Rt,!1);case"m":return String(Rt);case"mm":return oe.s(Rt,2,"0");case"s":return String(de.$s);case"ss":return oe.s(de.$s,2,"0");case"SSS":return oe.s(de.$ms,3,"0");case"Z":return ge}return null}(ci)||ge.replace(":","")})},ie.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},ie.diff=function(Y,de,te){var Ge,ge=this,ct=oe.p(de),Rt=X(Y),Lt=(Rt.utcOffset()-this.utcOffset())*t,zt=this-Rt,Vi=function(){return oe.m(ge,Rt)};switch(ct){case I:Ge=Vi()/12;break;case c:Ge=Vi();break;case E:Ge=Vi()/3;break;case f:Ge=(zt-Lt)/6048e5;break;case u:Ge=(zt-Lt)/864e5;break;case d:Ge=zt/i;break;case o:Ge=zt/t;break;case l:Ge=zt/e;break;default:Ge=zt}return te?Ge:oe.a(Ge)},ie.daysInMonth=function(){return this.endOf(c).$D},ie.$locale=function(){return S[this.$L]},ie.locale=function(Y,de){if(!Y)return this.$L;var te=this.clone(),Ge=me(Y,de,!0);return Ge&&(te.$L=Ge),te},ie.clone=function(){return oe.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()},ve}(),ir=gt.prototype;return X.prototype=ir,[["$ms",s],["$s",l],["$m",o],["$H",d],["$W",u],["$M",c],["$y",I],["$D",D]].forEach(function(ve){ir[ve[1]]=function(ie){return this.$g(ie,ve[0],ve[1])}}),X.extend=function(ve,ie){return ve.$i||(ve(ie,gt,X),ve.$i=!0),X},X.locale=me,X.isDayjs=pe,X.unix=function(ve){return X(1e3*ve)},X.en=S[q],X.Ls=S,X.p={},X})})(oD);var q3=oD.exports;const T=NI(q3);var O=(r=>(r.Error="error",r.Warning="warning",r))(O||{}),$=(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))($||{}),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){h(this,"id");h(this,"message");h(this,"issue");h(this,"severity");h(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 $?new Ye({id:this.id,message:this.message,issue:this.issue,severity:this.severity,code:this.code,entity:a}):null}}class Ye{constructor(a){h(this,"id");h(this,"message");h(this,"issue");h(this,"severity");h(this,"code");h(this,"entity");h(this,"firstRelationship");h(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 Ye({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 J3(r){const a=new Set;return r.filter(e=>a.has(e.id)?!1:(a.add(e.id),!0))}function ue(r){const a=r.entity.errors.find(t=>t.id===r.id);return a?{new:!1,error:a}:{new:!0,error:new Ye(r)}}function W3(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 Ke(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 fa=v.union([v.string(),v.number(),v.boolean(),v.date()]),lD=v.enum([vt.CurrentDateAndTime,vt.Random,vt.Unique]),ll=v.object({type:lD,rangeStart:fa.nullable(),rangeEnd:fa.nullable()}),ha=ll.extend({type:v.literal(vt.Random),rangeStart:fa,rangeEnd:fa}),cp=ll.extend({type:v.literal(vt.Unique),rangeStart:v.null(),rangeEnd:v.null()}),dD=ll.extend({type:v.literal(vt.CurrentDateAndTime),rangeStart:v.null(),rangeEnd:v.null()}),dl=ha.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),uD=dl.extend({rangeStart:v.number(),rangeEnd:v.null()}),pD=dl.extend({rangeStart:v.null(),rangeEnd:v.number()}),cD=dl.extend({rangeStart:v.number(),rangeEnd:v.number()}),ul=ha.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),fD=ul.extend({rangeStart:v.number(),rangeEnd:v.null()}),hD=ul.extend({rangeStart:v.null(),rangeEnd:v.number()}),yD=ul.extend({rangeStart:v.number(),rangeEnd:v.number()}),pl=ha.extend({rangeStart:v.date().nullable(),rangeEnd:v.date().nullable()}),mD=pl.extend({rangeStart:v.date(),rangeEnd:v.null()}),vD=pl.extend({rangeStart:v.null(),rangeEnd:v.date()}),TD=pl.extend({rangeStart:v.date(),rangeEnd:v.date()}),fp=ha.extend({rangeStart:v.null(),rangeEnd:v.null()}),hp=v.union([fD,hD,yD]),yp=v.union([uD,pD,cD]),mp=v.union([mD,vD,TD,dD]),vp=v.union([hp,yp,mp,cp,fp]);function ya(){return v.union([v.object({type:v.literal(n.ValueDescriptor)}),v.record(v.string(),v.any())])}function ED(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ValueDescriptor)})}function Tp(){return v.object({id:v.string(),type:v.literal(n.ValueDescriptor),name:v.string(),required:v.boolean()})}function S3(){return Tp().merge(v.object({version:v.number(),index:v.number()}))}function z3(){return Tp().merge(v.object({}))}function Y3(){return v.object({dataType:Vn(),parent:wn()})}function H3(){return S3().merge(Y3())}function cl(){return v.union([v.object({type:v.literal(n.PrimitiveEntity)}),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.PrimitiveEntity)})}function hl(){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 K3(){return hl().merge(v.object({version:v.number()}))}function X3(){return hl().merge(v.object({}))}function Q3(){return v.object({properties:v.array(Pn()),methods:v.array(Ti()),abstractMethods:v.array(Hi()),extends:v.array(v.union([cl(),ys()]))})}function e5(){return K3().merge(Q3())}function Pn(){return v.union([v.object({type:v.literal(n.Property)}),v.record(v.string(),v.any())])}function ID(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Property)})}function Ep(){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 t5(){return Ep().merge(v.object({version:v.number(),index:v.number()}))}function i5(){return Ep().merge(v.object({}))}function r5(){return v.object({dataType:Vn(),implements:Pn().nullable(),parent:v.union([Mn(),fl(),yl()])})}function n5(){return t5().merge(r5())}function s5(){return v.enum([W.CRON_JOB,W.EXECUTION,W.HTTP_ENDPOINT,W.PERSISTED_ENTITY,W.RELATIONAL_DATABASE])}function ys(){return v.union([v.object({type:v.literal(n.BuiltInBaseEntity)}),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.BuiltInBaseEntity)})}function Ip(){return v.object({id:v.string(),version:v.number(),type:v.literal(n.BuiltInBaseEntity),name:s5(),description:v.string().nullable(),abstract:v.boolean(),static:v.boolean()})}function a5(){return Ip()}function o5(){return Ip().merge(v.object({}))}function l5(){return v.object({properties:v.array(Pn()),methods:v.array(Ti()),abstractMethods:v.array(Hi()),extends:v.array(v.union([ys(),cl()]))})}function d5(){return a5().merge(l5())}function Hi(){return v.union([v.object({type:v.literal(n.ActionDescriptor)}),v.record(v.string(),v.any())])}function wn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ActionDescriptor)})}function ml(){return v.object({id:v.string(),type:v.literal(n.ActionDescriptor),name:v.string(),description:v.string().nullable()})}function u5(){return ml().merge(v.object({version:v.number()}))}function p5(){return ml().merge(v.object({}))}function c5(){return v.object({inputs:v.array(ya()),outputs:v.array(ya()),parent:v.union([oi(),Mn(),yl(),fl()]).nullable()})}function AD(){return u5().merge(c5())}function ms(){return v.union([v.object({type:v.literal(n.Loop)}),v.record(v.string(),v.any())])}function Ki(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Loop)})}function bD(){return v.object({id:v.string(),type:v.literal(n.Loop)})}function f5(){return bD().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function h5(){return bD().merge(v.object({declaration:v.union([v.string(),Ti()])}))}function y5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),declaration:Hi(),inputs:v.array(Li()),outputs:v.array(ei()),outputsDeclarations:v.array(ya()),successCalls:v.array(Ct()),errorCalls:v.array(Ct()),error:ei(),body:Ti(),parent:v.union([vr(),oi()]),breakStatements:v.array(Is()),continueStatements:v.array(vs())})}function m5(){return f5().merge(y5())}function vs(){return v.union([v.object({type:v.literal(n.ContinueStatement)}),v.record(v.string(),v.any())])}function Ts(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ContinueStatement)})}function Ap(){return v.object({id:v.string(),type:v.literal(n.ContinueStatement)})}function v5(){return Ap().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function T5(){return Ap().merge(v.object({}))}function E5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),outputs:v.array(hr()),throws:v.optional(hr()),parent:Ki()})}function I5(){return v5().merge(E5())}function Cn(){return v.union([v.object({type:v.literal(n.ReturnStatement)}),v.record(v.string(),v.any())])}function Es(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnStatement)})}function bp(){return v.object({id:v.string(),type:v.literal(n.ReturnStatement)})}function A5(){return bp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function b5(){return bp().merge(v.object({}))}function R5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),outputs:v.array(hr()),throws:v.optional(hr()),parent:vr()})}function D5(){return A5().merge(R5())}function hr(){return v.union([v.object({type:v.literal(n.ReturnDeclaration)}),v.record(v.string(),v.any())])}function RD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnDeclaration)})}function Rp(){return v.object({id:v.string(),type:v.literal(n.ReturnDeclaration),name:v.string(),description:v.string().nullable(),isError:v.boolean()})}function O5(){return Rp().merge(v.object({version:v.number(),index:v.number()}))}function P5(){return Rp().merge(v.object({}))}function w5(){return v.object({dataType:Vn().nullable(),readsValue:Aa().nullable(),parent:v.union([Es(),wn(),yr(),Ts()])})}function C5(){return O5().merge(w5())}function Is(){return v.union([v.object({type:v.literal(n.BreakStatement)}),v.record(v.string(),v.any())])}function yr(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.BreakStatement)})}function Dp(){return v.object({id:v.string(),type:v.literal(n.BreakStatement)})}function V5(){return Dp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function B5(){return Dp().merge(v.object({}))}function _5(){return v.object({calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),outputs:v.array(hr()),throws:v.optional(hr()),parent:Ki()})}function M5(){return V5().merge(_5())}function ei(){return v.union([v.object({type:v.literal(n.OutputMap)}),v.record(v.string(),v.any())])}function Op(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.OutputMap)})}function Pp(){return v.object({id:v.string(),type:v.literal(n.OutputMap)})}function N5(){return Pp().merge(v.object({version:v.number(),index:v.number()}))}function L5(){return Pp().merge(v.object({}))}function j5(){return v.object({writesValues:v.array(mr()),declaration:v.union([hr(),Pn()]),parent:v.union([nt(),Ki(),yr()])})}function U5(){return N5().merge(j5())}function As(){return v.union([v.object({type:v.literal(n.FunctionCall)}),v.record(v.string(),v.any())])}function ma(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionCall)})}function wp(){return v.object({id:v.string(),type:v.literal(n.FunctionCall)})}function $5(){return wp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function G5(){return wp().merge(v.object({}))}function g5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),writesValues:v.array(mr()),declaration:Ti(),inputs:v.array(Li()),outputs:v.array(ei()),error:v.optional(ei()),parent:v.union([vr(),oi()])})}function F5(){return $5().merge(g5())}function x5(){return v.enum([ft.Equal,ft.NotEqual,ft.MoreThan,ft.MoreThanOrEqual,ft.LessThan,ft.LessThanOrEqual,ft.And,ft.Or,bi.Empty,bi.NotEmpty])}function va(){return v.union([v.object({type:v.literal(n.Condition)}),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.Condition)})}function Cp(){return v.object({id:v.string(),type:v.literal(n.Condition)})}function k5(){return Cp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function Z5(){return Cp().merge(v.object({}))}function q5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),leftValue:Li(),rightValue:Li().nullable(),operator:x5(),parent:v.union([vr(),oi()])})}function J5(){return k5().merge(q5())}function Ta(){return v.union([v.object({type:v.literal(n.Search)}),v.record(v.string(),v.any())])}function Ea(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Search)})}function Vp(){return v.object({id:v.string(),type:v.literal(n.Search),name:v.string(),query:v.any(),description:v.string().nullable()})}function W5(){return Vp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function S5(){return Vp().merge(v.object({}))}function z5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),inputsDeclarations:v.array(_n()),inputs:v.array(Li()),outputsDeclarations:v.array(ya()),outputs:v.array(ei()),parent:v.union([vr(),oi()]),error:ei().nullable()})}function Y5(){return W5().merge(z5())}function Ia(){return v.union([v.object({type:v.literal(n.InternalCall)}),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.InternalCall)})}function _p(){return v.object({id:v.string(),type:v.literal(n.InternalCall),index:v.number()})}function H5(){return _p().merge(v.object({version:v.number(),index:v.number()}))}function K5(){return _p().merge(v.object({declaration:v.union([v.string(),Ti()])}))}function X5(){return v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),writesValues:v.array(mr()),declaration:Ti(),inputs:v.array(Li()),outputs:v.array(ei()),parent:jr(),error:v.optional(ei())})}function Q5(){return H5().merge(X5())}function Li(){return v.union([v.object({type:v.literal(n.InputMap)}),v.record(v.string(),v.any())])}function Tl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InputMap)})}function Mp(){return v.object({id:v.string(),type:v.literal(n.InputMap),name:v.string().nullable().optional(),description:v.string().nullable().optional()})}function eZ(){return Mp().merge(v.object({version:v.number(),index:v.number()}))}function tZ(){return Mp().merge(v.object({}))}function iZ(){return v.object({defaultValue:Np().nullable(),declaration:v.union([_n(),Pn()]).nullable(),readsValue:Aa().nullable(),parent:v.union([nt(),Tl(),Ki(),yr()])})}function rZ(){return eZ().merge(iZ())}function bs(){return v.union([v.object({type:v.literal(n.Operation)}),v.record(v.string(),v.any())])}function Rs(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Operation)})}function El(){return v.object({id:v.string(),type:v.literal(n.Operation)})}function nZ(){return El().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function sZ(){return El().merge(v.object({}))}function aZ(){return El().merge(v.object({successCalls:v.array(Ct()),errorCalls:v.array(Ct()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),writesValues:v.array(mr()),declaration:Hi(),inputs:v.array(Li()),outputs:v.array(ei()),error:v.array(ei()),parent:v.union([vr(),oi()])}))}function oZ(){return nZ().merge(aZ())}function Il(){return v.union([v.string(),v.number(),v.boolean(),v.null(),v.date()])}function DD(){return v.record(v.string(),Il())}function lZ(){return v.array(v.union([Il(),DD()]))}function OD(){return v.union([Il(),DD(),lZ()])}function PD(){return v.union([Il(),OD()])}function wD(){return v.enum([N.String,N.Number,N.Boolean,N.Null,N.Date,N.KeyValue,N.Enum,N.File,N.UUID,N.EntityTemplate,N.ActionDescriptor])}function CD(){return v.union([Mn(),Rs(),ba()])}function dZ(){return v.object({id:v.string(),name:wD(),type:v.literal(n.LiteralValue),value:PD(),autogeneration:vp.nullable()})}function uZ(){return dZ().merge(v.object({}))}function ji(){return v.object({id:v.string(),version:v.number(),name:wD(),type:v.literal(n.LiteralValue),value:PD(),valueAsTypeList:v.array(CD()).nullable(),valueAsTypeSingle:CD().nullable(),autogeneration:vp.nullable(),parent:v.union([Lp(),Tl()])})}function pZ(){return ji().extend({name:v.literal(N.String),value:v.string(),autogeneration:hp.nullable()})}function cZ(){return ji().extend({name:v.literal(N.Number),value:v.number(),autogeneration:yp.nullable()})}function fZ(){return ji().extend({name:v.literal(N.Boolean),value:v.boolean(),autogeneration:fp.nullable()})}function hZ(){return ji().extend({name:v.literal(N.Null),value:v.null(),autogeneration:v.null()})}function yZ(){return ji().extend({name:v.literal(N.Date),value:v.date(),autogeneration:mp.nullable()})}function mZ(){return ji().extend({name:v.literal(N.KeyValue),value:OD(),autogeneration:v.null()})}function vZ(){return ji().extend({name:v.literal(N.Enum),value:v.string(),autogeneration:v.null()})}function TZ(){return ji().extend({name:v.literal(N.File),value:v.string(),autogeneration:v.null()})}function EZ(){return ji().extend({name:v.literal(N.UUID),value:v.string(),autogeneration:cp.nullable()})}function IZ(){return ji().extend({name:v.literal(N.EntityTemplate),value:Mn(),autogeneration:v.null()})}function AZ(){return ji().extend({name:v.literal(N.ActionDescriptor),value:ba(),autogeneration:v.null()})}function Np(){return v.union([pZ(),cZ(),fZ(),hZ(),yZ(),mZ(),vZ(),TZ(),EZ(),IZ(),AZ()])}function Vn(){return v.union([v.object({type:v.literal(n.DataType)}),v.record(v.string(),v.any())])}function Lp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DataType)})}function jp(){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 bZ(){return jp().merge(v.object({version:v.number()}))}function RZ(){return jp().merge(v.object({}))}function DZ(){return v.object({defaultValue:Np().nullable(),entity:v.union([Ds(),ys(),cl(),Hi()]).nullable(),parent:v.union([ID(),_D(),ED()])})}function OZ(){return bZ().merge(DZ())}function Up(){return v.union([v.object({type:v.literal(n.VariableDeclaration)}),v.record(v.string(),v.any())])}function PZ(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableDeclaration)})}function $p(){return v.object({id:v.string(),type:v.literal(n.VariableDeclaration),name:v.string(),description:v.string().nullable()})}function wZ(){return $p().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function CZ(){return $p().merge(v.object({}))}function VZ(){return v.object({dataType:Vn().nullable(),readsValue:Aa().nullable(),writesValues:v.array(mr()),inputs:v.array(Li()),outputs:v.array(ei()),successCalls:v.array(Ct()),errorCalls:v.array(Ct()),internalCalls:v.array(Ia()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),parent:v.union([vr(),oi()])})}function BZ(){return wZ().merge(VZ())}function VD(){return v.union([v.object({type:v.literal(n.VariableInstance)}),v.record(v.string(),v.any())])}function _Z(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableInstance)})}function Gp(){return v.object({id:v.string(),type:v.literal(n.VariableInstance)})}function MZ(){return Gp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function NZ(){return Gp().merge(v.object({}))}function LZ(){return v.object({declaration:Up(),dataType:Vn().nullable(),readsValue:Aa().nullable(),writesValues:v.array(mr()),inputs:v.array(Li()),outputs:v.array(ei()),successCalls:v.array(Ct()),errorCalls:v.array(Ct()),internalCalls:v.array(Ia()),calledBySuccess:v.array(nt()),calledByError:v.array(nt()),calledByEntry:v.array(Ot()),parent:v.union([vr(),oi()])})}function jZ(){return MZ().merge(LZ())}function gp(){return v.union([v.object({type:v.literal(n.InstalledProject)}),v.record(v.string(),v.any())])}function Al(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InstalledProject)})}function UZ(){return v.object({id:v.string(),type:v.literal(n.InstalledProject)})}function $Z(){return v.object({version:v.number(),x:v.number(),y:v.number()})}function GZ(){return v.object({})}function gZ(){return v.object({implements:oi(),description:v.string().nullable(),functions:v.array(Ti()),events:v.array(Fp()),parent:oi()})}function FZ(){return $Z().merge(gZ())}function Fp(){return v.union([v.object({type:v.literal(n.GlobalEvent)}),v.record(v.string(),v.any())])}function xZ(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.GlobalEvent)})}function bl(){return v.object({id:v.string(),type:v.literal(n.GlobalEvent),name:v.string(),collapsed:v.boolean()})}function kZ(){return bl().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function ZZ(){return bl().merge(v.object({}))}function qZ(){return bl().merge(v.object({returnStatements:v.array(Cn()),implements:v.array(AD()),inputs:v.array(_n()),calls:v.array(Ct()),parent:v.union([oi(),Al()])}))}function JZ(){return kZ().merge(qZ())}function Bn(){return v.union([Up(),VD()])}function jr(){return v.union([PZ(),_Z()])}function mr(){return v.union([Bn(),Li(),hr()])}function BD(){return v.union([jr(),Tl(),RD()])}function Aa(){return v.union([Bn(),_n(),ei(),bs(),Ia(),As()])}function WZ(){return v.union([jr(),xp(),Op(),Rs(),Bp(),ma()])}function SZ(){return v.union([_n(),ei(),mr()])}function _D(){return v.union([xp(),Op(),BD()])}function Rl(){return Fp()}function Dl(){return xZ()}function Ol(){return v.union([bs(),As(),va(),Ta(),Bn(),Ia(),ms()])}function nt(){return v.union([Rs(),ma(),vl(),Ea(),jr(),Bp(),Ki()])}function Pl(){return v.union([bs(),As(),va(),Ta(),Bn(),ms()])}function wl(){return v.union([Rs(),ma(),vl(),Ea(),jr(),Ki()])}function MD(){return v.union([Ol(),Cn(),Is(),vs()])}function Ct(){return v.union([nt(),Es(),yr(),Ts()])}function ND(){return v.union([Pl(),Cn(),Is(),vs()])}function LD(){return v.union([wl(),Es(),yr(),Ts()])}function Ur(){return v.union([Ti(),Rl()])}function Ot(){return v.union([ba(),Dl()])}function zZ(){return v.union([Ol(),Ur()])}function YZ(){return v.union([nt(),Ot()])}function HZ(){return v.union([Pl(),Ur()])}function KZ(){return v.union([wl(),Ot()])}function XZ(){return v.union([MD(),Ur()])}function QZ(){return v.union([Ct(),Ot()])}function e7(){return v.union([ND(),Ur()])}function t7(){return v.union([LD(),Ot()])}function i7(){return v.union([Ur(),ms()])}function vr(){return v.union([Ot(),Ki()])}function r7(){return v.union([Ol(),Ur()])}function n7(){return v.union([nt(),Ot()])}function s7(){return v.union([Pl(),Ur()])}function a7(){return v.union([wl(),Ot()])}function o7(){return v.union([Cn(),Is(),vs()])}function l7(){return v.union([Es(),yr(),Ts()])}function d7(){return v.union([ys(),A7(),gp(),Ds(),Ti(),Rl(),Bn(),Li(),ei(),va(),bs(),As(),hr(),_n(),cl(),Vn(),Pn(),Hi(),Cn(),vs(),Is(),ms(),Ta(),Hi(),Hi(),ya(),Ia()])}function u7(){return v.union([yl(),oi(),Al(),Mn(),ba(),Dl(),jr(),Tl(),Op(),vl(),Rs(),ma(),RD(),xp(),fl(),Lp(),ID(),wn(),Es(),Ts(),yr(),Ki(),Ea(),wn(),wn(),ED(),Bp()])}function p7(){return v.union([gp(),Ds(),Ti(),Rl(),Bn(),va(),bs(),As(),Cn(),vs(),Is(),ms(),Ta()])}function c7(){return v.union([Al(),Mn(),ba(),Dl(),jr(),vl(),Rs(),ma(),Es(),Ts(),yr(),Ki(),Ea()])}function _n(){return v.union([v.object({type:v.literal(n.ArgumentDeclaration)}),v.record(v.string(),v.any())])}function xp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ArgumentDeclaration)})}function kp(){return v.object({id:v.string(),type:v.literal(n.ArgumentDeclaration)})}function f7(){return kp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function h7(){return kp().merge(v.object({}))}function y7(){return v.object({dataType:Vn().nullable(),writesValues:v.array(mr()),parent:v.union([Ot(),wn(),wn(),Ea(),yr()])})}function m7(){return f7().merge(y7())}function Ti(){return v.union([v.object({type:v.literal(n.FunctionDeclaration)}),v.record(v.string(),v.any())])}function ba(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionDeclaration)})}function Zp(){return v.object({id:v.string(),type:v.literal(n.FunctionDeclaration),name:v.string(),description:v.string().nullable()})}function v7(){return Zp().merge(v.object({version:v.number(),x:v.number(),y:v.number(),index:v.number().nullable()}))}function T7(){return Zp()}function E7(){return v.object({inputs:v.array(_n()),implements:Hi().nullable(),returnStatements:v.array(Cn()),parent:v.union([oi(),Al(),Mn(),Ki(),yl(),fl()])})}function I7(){return v7().merge(E7())}function A7(){return v.union([v.object({type:v.literal(n.Project)}),v.record(v.string(),v.any())])}function oi(){return v.object({entityType:v.literal(n.Project),entityId:v.string(),id:v.string(),type:v.literal(n.GenericReference)})}function qp(){return v.object({id:v.string(),type:v.literal(n.Project),name:v.string(),description:v.string().nullable()})}function b7(){return qp().merge(v.object({version:v.number()}))}function R7(){return qp()}function D7(){return v.object({entities:v.array(Ds()),functions:v.array(Ti()),events:v.array(Fp()),projects:v.array(gp()),variableDeclarations:v.array(Up()),variableInstances:v.array(VD()),conditions:v.array(va()),operations:v.array(bs()),functionCalls:v.array(As()),loops:v.array(ms()),searches:v.array(Ta())})}function O7(){return b7().merge(D7())}function Ds(){return v.union([v.object({type:v.literal(n.DefinitionEntity)}),v.record(v.string(),v.any())])}function Mn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DefinitionEntity)})}function Jp(){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 P7(){return Jp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function w7(){return Jp().merge(v.object({}))}function C7(){return v.union([oi(),Lp()])}function V7(){return v.object({properties:v.array(Pn()),methods:v.array(Ti()),abstractMethods:v.array(Hi()),extends:v.array(v.union([Ds(),ys()])),implements:v.array(v.union([Ds(),ys()])),parent:C7()})}function B7(){return P7().merge(V7())}function _7(r){return r instanceof Error&&r.name==="ZodError"&&"issues"in r&&Array.isArray(r.issues)}var M7=class extends Error{constructor(a,e){super(a,e);h(this,"name");h(this,"details");this.name="ZodValidationError",this.details=N7(e)}toString(){return this.message}};function N7(r){if(r){const a=r.cause;if(_7(a))return a.issues}return[]}function L7(r){return r.length!==0}var j7=/[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;function U7(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+'["'+$7(e)+'"]';if(!j7.test(e))return a+'["'+e+'"]';const t=a.length===0?"":".";return a+t+e},"")}function $7(r){return r.replace(/"/g,'\\"')}var G7="; ",g7=99,jD="Validation error",F7=": ",x7=", or ";function k7(r={}){const{issueSeparator:a=G7,unionSeparator:e=x7,prefixSeparator:t=F7,prefix:i=jD,includePath:s=!0,maxIssuesInMessage:l=g7}=r;return o=>{const d=o.slice(0,l).map(u=>Cl({issue:u,issueSeparator:a,unionSeparator:e,includePath:s})).join(a);return Z7(d,i,t)}}function Cl(r){const{issue:a,issueSeparator:e,unionSeparator:t,includePath:i}=r;if(a.code===Z.invalid_union)return a.unionErrors.reduce((s,l)=>{const o=l.issues.map(d=>Cl({issue:d,issueSeparator:e,unionSeparator:t,includePath:i})).join(e);return s.includes(o)||s.push(o),s},[]).join(t);if(a.code===Z.invalid_arguments)return[a.message,...a.argumentsError.issues.map(s=>Cl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(a.code===Z.invalid_return_type)return[a.message,...a.returnTypeError.issues.map(s=>Cl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(i&&L7(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 "${U7(a.path)}"`}return a.message}function Z7(r,a,e){return a!==null?r.length>0?[a,r].join(e):a:r.length>0?r:jD}function q7(r,a={}){const t=J7(a)([r]);return new M7(t,{cause:new ai([r])})}function J7(r){return"messageBuilder"in r?r.messageBuilder:k7(r)}var UD="1.13.7",$D=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global||Function("return this")()||{},Vl=Array.prototype,Wp=Object.prototype,GD=typeof Symbol<"u"?Symbol.prototype:null,W7=Vl.push,Ra=Vl.slice,Da=Wp.toString,S7=Wp.hasOwnProperty,gD=typeof ArrayBuffer<"u",z7=typeof DataView<"u",Y7=Array.isArray,FD=Object.keys,xD=Object.create,kD=gD&&ArrayBuffer.isView,H7=isNaN,K7=isFinite,ZD=!{toString:null}.propertyIsEnumerable("toString"),qD=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],X7=Math.pow(2,53)-1;function li(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 $r(r){var a=typeof r;return a==="function"||a==="object"&&!!r}function Q7(r){return r===null}function JD(r){return r===void 0}function WD(r){return r===!0||r===!1||Da.call(r)==="[object Boolean]"}function eq(r){return!!(r&&r.nodeType===1)}function Jt(r){var a="[object "+r+"]";return function(e){return Da.call(e)===a}}const Sp=Jt("String"),SD=Jt("Number"),tq=Jt("Date"),iq=Jt("RegExp"),rq=Jt("Error"),zD=Jt("Symbol"),YD=Jt("ArrayBuffer");var HD=Jt("Function"),nq=$D.document&&$D.document.childNodes;typeof/./!="function"&&typeof Int8Array!="object"&&typeof nq!="function"&&(HD=function(r){return typeof r=="function"||!1});const ti=HD,KD=Jt("Object");var XD=z7&&(!/\[native code\]/.test(String(DataView))||KD(new DataView(new ArrayBuffer(8)))),zp=typeof Map<"u"&&KD(new Map),sq=Jt("DataView");function aq(r){return r!=null&&ti(r.getInt8)&&YD(r.buffer)}const Bl=XD?aq:sq,Nn=Y7||Jt("Array");function Gr(r,a){return r!=null&&S7.call(r,a)}var Yp=Jt("Arguments");(function(){Yp(arguments)||(Yp=function(r){return Gr(r,"callee")})})();const Hp=Yp;function oq(r){return!zD(r)&&K7(r)&&!isNaN(parseFloat(r))}function QD(r){return SD(r)&&H7(r)}function eO(r){return function(){return r}}function tO(r){return function(a){var e=r(a);return typeof e=="number"&&e>=0&&e<=X7}}function iO(r){return function(a){return a==null?void 0:a[r]}}const _l=iO("byteLength"),lq=tO(_l);var dq=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;function uq(r){return kD?kD(r)&&!Bl(r):lq(r)&&dq.test(Da.call(r))}const rO=gD?uq:eO(!1),di=iO("length");function pq(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 nO(r,a){a=pq(a);var e=qD.length,t=r.constructor,i=ti(t)&&t.prototype||Wp,s="constructor";for(Gr(r,s)&&!a.contains(s)&&a.push(s);e--;)s=qD[e],s in r&&r[s]!==i[s]&&!a.contains(s)&&a.push(s)}function Nt(r){if(!$r(r))return[];if(FD)return FD(r);var a=[];for(var e in r)Gr(r,e)&&a.push(e);return ZD&&nO(r,a),a}function Oa(r){if(r==null)return!0;var a=di(r);return typeof a=="number"&&(Nn(r)||Sp(r)||Hp(r))?a===0:di(Nt(r))===0}function sO(r,a){var e=Nt(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 Xe(r){if(r instanceof Xe)return r;if(!(this instanceof Xe))return new Xe(r);this._wrapped=r}Xe.VERSION=UD,Xe.prototype.value=function(){return this._wrapped},Xe.prototype.valueOf=Xe.prototype.toJSON=Xe.prototype.value,Xe.prototype.toString=function(){return String(this._wrapped)};function aO(r){return new Uint8Array(r.buffer||r,r.byteOffset||0,_l(r))}var oO="[object DataView]";function Kp(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:lO(r,a,e,t)}function lO(r,a,e,t){r instanceof Xe&&(r=r._wrapped),a instanceof Xe&&(a=a._wrapped);var i=Da.call(r);if(i!==Da.call(a))return!1;if(XD&&i=="[object Object]"&&Bl(r)){if(!Bl(a))return!1;i=oO}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 GD.valueOf.call(r)===GD.valueOf.call(a);case"[object ArrayBuffer]":case oO:return lO(aO(r),aO(a),e,t)}var s=i==="[object Array]";if(!s&&rO(r)){var l=_l(r);if(l!==_l(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&&!(ti(o)&&o instanceof o&&ti(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(!Kp(r[u],a[u],e,t))return!1}else{var f=Nt(r),c;if(u=f.length,Nt(a).length!==u)return!1;for(;u--;)if(c=f[u],!(Gr(a,c)&&Kp(r[c],a[c],e,t)))return!1}return e.pop(),t.pop(),!0}function cq(r,a){return Kp(r,a)}function Pa(r){if(!$r(r))return[];var a=[];for(var e in r)a.push(e);return ZD&&nO(r,a),a}function Xp(r){var a=di(r);return function(e){if(e==null)return!1;var t=Pa(e);if(di(t))return!1;for(var i=0;i<a;i++)if(!ti(e[r[i]]))return!1;return r!==pO||!ti(e[Qp])}}var Qp="forEach",dO="has",ec=["clear","delete"],uO=["get",dO,"set"],fq=ec.concat(Qp,uO),pO=ec.concat(uO),hq=["add"].concat(ec,Qp,dO);const yq=zp?Xp(fq):Jt("Map"),mq=zp?Xp(pO):Jt("WeakMap"),vq=zp?Xp(hq):Jt("Set"),Tq=Jt("WeakSet");function Os(r){for(var a=Nt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=r[a[i]];return t}function Eq(r){for(var a=Nt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=[a[i],r[a[i]]];return t}function cO(r){for(var a={},e=Nt(r),t=0,i=e.length;t<i;t++)a[r[e[t]]]=e[t];return a}function tc(r){var a=[];for(var e in r)ti(r[e])&&a.push(e);return a.sort()}function ic(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 fO=ic(Pa),Ml=ic(Nt),hO=ic(Pa,!0);function Iq(){return function(){}}function yO(r){if(!$r(r))return{};if(xD)return xD(r);var a=Iq();a.prototype=r;var e=new a;return a.prototype=null,e}function Aq(r,a){var e=yO(r);return a&&Ml(e,a),e}function bq(r){return $r(r)?Nn(r)?r.slice():fO({},r):r}function Rq(r,a){return a(r),r}function mO(r){return Nn(r)?r:[r]}Xe.toPath=mO;function wa(r){return Xe.toPath(r)}function rc(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 vO(r,a,e){var t=rc(r,wa(a));return JD(t)?e:t}function Dq(r,a){a=wa(a);for(var e=a.length,t=0;t<e;t++){var i=a[t];if(!Gr(r,i))return!1;r=r[i]}return!!e}function nc(r){return r}function Ca(r){return r=Ml({},r),function(a){return sO(a,r)}}function sc(r){return r=wa(r),function(a){return rc(a,r)}}function Va(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 TO(r,a,e){return r==null?nc:ti(r)?Va(r,a,e):$r(r)&&!Nn(r)?Ca(r):sc(r)}function ac(r,a){return TO(r,a,1/0)}Xe.iteratee=ac;function ui(r,a,e){return Xe.iteratee!==ac?Xe.iteratee(r,a):TO(r,a,e)}function Oq(r,a,e){a=ui(a,e);for(var t=Nt(r),i=t.length,s={},l=0;l<i;l++){var o=t[l];s[o]=a(r[o],o,r)}return s}function EO(){}function Pq(r){return r==null?EO:function(a){return vO(r,a)}}function wq(r,a,e){var t=Array(Math.max(0,r));a=Va(a,e,1);for(var i=0;i<r;i++)t[i]=a(i);return t}function oc(r,a){return a==null&&(a=r,r=0),r+Math.floor(Math.random()*(a-r+1))}const Ba=Date.now||function(){return new Date().getTime()};function IO(r){var a=function(s){return r[s]},e="(?:"+Nt(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 AO={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},Cq=IO(AO),Vq=cO(AO),Bq=IO(Vq),_q=Xe.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var lc=/(.)^/,Mq={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Nq=/\\|'|\r|\n|\u2028|\u2029/g;function Lq(r){return"\\"+Mq[r]}var jq=/^\s*(\w|\$)+\s*$/;function Uq(r,a,e){!a&&e&&(a=e),a=hO({},a,Xe.templateSettings);var t=RegExp([(a.escape||lc).source,(a.interpolate||lc).source,(a.evaluate||lc).source].join("|")+"|$","g"),i=0,s="__p+='";r.replace(t,function(u,f,c,E,I){return s+=r.slice(i,I).replace(Nq,Lq),i=I+u.length,f?s+=`'+
25
25
  ((__t=(`+f+`))==null?'':_.escape(__t))+
26
26
  '`:c?s+=`'+
27
27
  ((__t=(`+c+`))==null?'':__t)+
@@ -39,10 +39,10 @@ Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInS
39
39
  Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}return e}function Oc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.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:O.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:O.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}--${$.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:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function Pc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.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:O.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:O.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=Kc(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${$.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:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function wc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.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:O.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:O.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=QP(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${$.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:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function CJ(r,a){switch(r.type){case n.DefinitionEntity:return bc(r,a);case n.FunctionDeclaration:return Rc(r,a);case n.VariableDeclaration:return Dc(r,a);case n.Property:return Oc(r,a);case n.ArgumentDeclaration:return Pc(r,a);case n.ReturnDeclaration:return wc(r,a);default:return[]}}function r1(r,a,e){const i=`${Ul(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Cc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${Ul(x(t,a))}-`),e=`${i}${Ul(x(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function yt(r,a,e="uuid"){return e==="semantic"?r1(x(r,a),r.type,a):m.UUID.uuid()}function n1(r){var l;const a=n5(),e=r.toJSON();a.safeParse(e).success;const i=s1(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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function s1(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:O.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:O.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:O.Error,code:F.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!wi(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:O.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return Ke(r.errors,a)}const VJ=Object.freeze(Object.defineProperty({__proto__:null,validate:n1,validateImplementation:s1},Symbol.toStringTag,{value:"Module"}));function BJ(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:O.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=an(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:O.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:O.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=Wt(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 ("${se(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+=`
42
+ Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function CJ(r,a){switch(r.type){case n.DefinitionEntity:return bc(r,a);case n.FunctionDeclaration:return Rc(r,a);case n.VariableDeclaration:return Dc(r,a);case n.Property:return Oc(r,a);case n.ArgumentDeclaration:return Pc(r,a);case n.ReturnDeclaration:return wc(r,a);default:return[]}}function r1(r,a,e){const i=`${Ul(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Cc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${Ul(x(t,a))}-`),e=`${i}${Ul(x(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function yt(r,a,e="uuid"){return e==="semantic"?r1(x(r,a),r.type,a):m.UUID.uuid()}function n1(r){var l;const a=n5(),e=r.toJSON();a.safeParse(e).success;const i=s1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function s1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=ue({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:O.Error,code:F.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=ue({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:O.Error,code:F.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!wi(r.dataType,e.dataType)){const i=ue({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:O.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return Ke(r.errors,a)}const VJ=Object.freeze(Object.defineProperty({__proto__:null,validate:n1,validateImplementation:s1},Symbol.toStringTag,{value:"Module"}));function BJ(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:O.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=an(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:O.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:O.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=Wt(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 ("${se(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
43
  ${rn}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.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:O.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:O.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(f=>{var c;return((c=f.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:O.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:O.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:O.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=bt(r,{},a);return e.push(...t.errors),e}class lt{constructor(a){h(this,"version");h(this,"previousVersion",null);h(this,"createdAt");h(this,"deleted",!1);h(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 Vc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(Vc||{}),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=""){h(this,"id",m.UUID.uuid());h(this,"seenEntities",[]);h(this,"added",{});h(this,"updated",{});h(this,"removed",{});h(this,"affected",{});h(this,"self",null);h(this,"author");h(this,"timestamp");h(this,"open",!0);h(this,"dirty",!0);h(this,"type","manual");h(this,"autoclose",!1);h(this,"autoCloseActionName","");h(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.sanitize(),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.project.closePendingChangeSets(),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")})}sanitize(){this.listAdded.forEach(a=>{a.previousVersion=null})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),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.project.closePendingChangeSets(),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}addDependentsToAffected(a){Object.values(a.detachedDependents).forEach(e=>{const{entity:t,field:i}=e;this.has(t.id)||this.add(t,"affected")})}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(!rd(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==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(f=>f!==a.id),delete this.project.deletedInstances[a.id],this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasRemoved(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of E)this.add(D,"removed");for(const D of I)this.add(D,"affected")}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`);return this.removed[a.id]=u,this}if(e==="added"){if(this.removed[a.id])return this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasAdded(a.id)){const{added:f,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of E)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.previousVersion=null,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`);return this.added[a.id]=u,delete this.affected[a.id],this.addDependentsToAffected(a),this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return a.captureVersion(),this.addDependentsToAffected(a),this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of E)this.add(D,"removed");for(const D of I)this.add(D,"affected")}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`);return this.updated[a.id]=u,this.addDependentsToAffected(a),this}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 _J(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var a1=(r=>(r.PropertyImplements="property-implements",r.PropertyExtends="property-extends",r.DataTypeEntity="data-type-entity",r))(a1||{});const be=class be extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"private");h(this,"abstract");h(this,"index");h(this,"static");h(this,"required");h(this,"constant",!1);h(this,"type",n.Property);h(this,"hidden",!1);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"implements",null);h(this,"extends",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,extends: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 f=_(e.implements);l=t.get(f)}let o=null;if(e.extends){const f=_(e.extends);o=t.get(f)}const d={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,extends:o,dataType: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=BJ(i,t),o=Oc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&!e.abstract}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.implements)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${kl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(null,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}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==="property-implements"&&(this.setImplements(e,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.subscribeDependents)==null||d.call(o,[{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.implements=this.implements,e.extends=this.extends,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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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(`${Vt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(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(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' 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.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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",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)}if(this.initialData.extends){const t=C(this.initialData.extends,this.project);this.setExtends(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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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,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,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,extends:((l=this.extends)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:((f=this.dataType)==null?void 0:f.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})(),extends:(()=>{var c;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((c=this.extends)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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,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,extends:((d=this.extends)==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.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e,t;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,extends:(t=this.extends)==null?void 0:t.id,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=n1(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 I,D;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,extends:this.extends,parent:d},f=st(u,l);s&&f.subscribe(),f.setParent(d,null),f.initChildren(e),e==null||e.add(f,A.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const E=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=E||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),f}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 e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};h(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}),h(be,"type",n.Property),h(be,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),h(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(be,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),h(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),h(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),h(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),h(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),h(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),h(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),h(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let gr=be;function o1(r){const a=I7(),e=r.toJSON();a.safeParse(e).success;const i=MJ(r),s=NJ(r),l=pi(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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return Ke(r.errors,o)}function MJ(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:O.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function NJ(r){const a=[];return r.implements,Ke(r.errors,a)}const LJ=Object.freeze(Object.defineProperty({__proto__:null,validate:o1},Symbol.toStringTag,{value:"Module"}));var l1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(l1||{});const Re=class Re extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"private");h(this,"index",null);h(this,"type",n.FunctionDeclaration);h(this,"implements",null);h(this,"extends",null);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=_(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=_(e.extends);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.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,extends:l,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(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=Rc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const E=d,D=Wt(E).filter(P=>!P.interactive);if(D.length){let P=D.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.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 '${E.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(D[0],D[0].project)}").`;P+=`
45
+ ${kl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(null,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}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==="property-implements"&&(this.setImplements(e,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.subscribeDependents)==null||d.call(o,[{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.implements=this.implements,e.extends=this.extends,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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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(`${Vt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(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(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' 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.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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",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)}if(this.initialData.extends){const t=C(this.initialData.extends,this.project);this.setExtends(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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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,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,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,extends:((l=this.extends)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:((f=this.dataType)==null?void 0:f.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})(),extends:(()=>{var c;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((c=this.extends)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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,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,extends:((d=this.extends)==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.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e,t;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,extends:(t=this.extends)==null?void 0:t.id,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=n1(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 I,D;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,extends:this.extends,parent:d},f=st(u,l);s&&f.subscribe(),f.setParent(d,null),f.initChildren(e),e==null||e.add(f,A.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const E=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=E||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),f}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 e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};h(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}),h(be,"type",n.Property),h(be,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),h(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(be,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),h(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),h(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),h(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),h(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),h(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),h(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),h(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let gr=be;function o1(r){const a=I7(),e=r.toJSON();a.safeParse(e).success;const i=MJ(r),s=NJ(r),l=pi(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];return Ke(r.errors,o)}function MJ(r){const a=[];if(!r.calls.length&&!r.extends){const e=ue({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:O.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function NJ(r){const a=[];return r.implements,Ke(r.errors,a)}const LJ=Object.freeze(Object.defineProperty({__proto__:null,validate:o1},Symbol.toStringTag,{value:"Module"}));var l1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(l1||{});const Re=class Re extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"private");h(this,"index",null);h(this,"type",n.FunctionDeclaration);h(this,"implements",null);h(this,"extends",null);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=_(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=_(e.extends);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.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,extends:l,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(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=Rc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const E=d,D=Wt(E).filter(P=>!P.interactive);if(D.length){let P=D.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.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 '${E.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(D[0],D[0].project)}").`;P+=`
46
46
  ${rn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:P,issue:null}))}else{const P=E.methods.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===i.implements});P&&s.push(new w({id:`${i.id}--${$.MethodOverwritesOtherSiblingWithSameImplementation}`,code:$.MethodOverwritesOtherSiblingWithSameImplementation,severity:O.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.
47
47
  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.
48
48
  ${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
@@ -52,19 +52,19 @@ If you want to implement a new method, you can create a new 'function-declaratio
52
52
  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 E=d.body;E&&((c=E.implements)==null?void 0:c.id)===i.implements&&s.push(new w({id:`${i.id}--${$.LoopBodyFunctionOverwrite}`,code:$.LoopBodyFunctionOverwrite,severity:O.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),f=u?an(u):null;return f&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${x(f,t)}" with id '${f.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 isExtendedMethod(){if(this.parent.type!==n.DefinitionEntity)return!1;const e=this.parent.allBaseMethodsFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&e.type!==n.ActionDescriptor}get returnStatements(){return Ee(this).filter(i=>i.type===n.ReturnStatement&&i.parent.id===this.id)}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:O.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.
53
53
  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:O.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
54
  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.
55
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&this.setImplements(null,i),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}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==="function-declaration-implements"&&(this.setImplements(e,i),s.push(e)),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(e=this.implements)==null||e.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var e,t;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.subscribeDependents([{entity:this,field:"function-declaration-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 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.extends=this.extends,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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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(`${Vt(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(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(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' 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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",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.initialData.extends&&(this.extends=C(this.initialData.extends,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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),pi(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.parent.type===n.DefinitionEntity&&!e&&(this.parent.removeMethod(this),t==null||t.add(this.parent,A.Affected),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=[];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),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),pi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),this.parent.type===n.DefinitionEntity&&(this.parent.addMethod(this),e==null||e.add(this.parent,A.Affected),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){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=pi(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,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,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,extends:((i=this.extends)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){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||yt(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})})(),extends:(()=>{var u;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(u=this.extends)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(o=>o.toReference(e)),calls:this.calls.map(o=>o.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,extends:((l=this.extends)==null?void 0:l.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,i;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||void 0,extends:((i=this.extends)==null?void 0:i.id)||void 0,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=o1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=pi(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 I;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[],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 f=st(d,o);t?f.setParent(t,null):f.setParent(this.parent,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.inputs)==null?void 0:I.map(D=>D.clone(e,f,m.UUID.uuid(),s));return f.inputs=c,l?(pi(this).map(D=>D.clone(e,f,m.UUID.uuid(),s)),e==null||e.attemptAutoclose("clone-entity",this.id),f):(e==null||e.attemptAutoclose("clone-entity",this.id),f)}getVariableInstances(){return He(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||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"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.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.add(l,A.Added),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(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.InternalCall,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.toShallowJSON(),index:t.internalCalls.length},l=C(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),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)&&wi(o.dataType,s.dataType))||e.push(s)}),p(e)}};h(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}),h(Re,"type",n.FunctionDeclaration),h(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),h(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),h(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),h(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),h(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),h(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),h(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),h(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),h(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),h(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let Fr=Re;function d1(r){const a=OZ(),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:O.Error,code:F.InvalidPropertiesCombination,entity:r});i.push(s.error)}return Ke(r.errors,i)}const jJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));function UJ(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${se(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:O.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:O.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:O.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}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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:O.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:O.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:O.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 Bc=(r=>(r.Entity="entity",r))(Bc||{});const De=class De extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"isList",null);h(this,"asType",null);h(this,"type",n.DataType);h(this,"options",null);h(this,"parentRelationType",null);h(this,"like");h(this,"implementationChooseOne",!1);h(this,"inferred",!1);h(this,"staticEntities",null);h(this,"interactiveEntities",null);h(this,"actionEntities",null);h(this,"entity",null);h(this,"andChildrenGroup",null);h(this,"orChildrenGroup",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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,this.staticEntities=e.staticEntities,this.interactiveEntities=e.interactiveEntities,this.actionEntities=e.actionEntities}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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,staticEntities:null,interactiveEntities:null,actionEntities: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,staticEntities:e.staticEntities??null,interactiveEntities:e.interactiveEntities??null,actionEntities:e.actionEntities??null,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=UJ(i,t);if(s.push(...l,...ut(i)),i.entity){const f=t.get(i.entity);if(f.type===n.DefinitionEntity){const E=Wt(f).filter(I=>!I.interactive);if(E.length){const I=E.length>1?`entities with ids '${se(E.map(D=>D.id),"', '","' and '")}'`:`entity with id '${E[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.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 ${I}.
55
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&this.setImplements(null,i),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}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==="function-declaration-implements"&&(this.setImplements(e,i),s.push(e)),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(e=this.implements)==null||e.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var e,t;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.subscribeDependents([{entity:this,field:"function-declaration-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 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.extends=this.extends,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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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(`${Vt(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(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(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' 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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",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.initialData.extends&&(this.extends=C(this.initialData.extends,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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),pi(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.parent.type===n.DefinitionEntity&&!e&&(this.parent.removeMethod(this),t==null||t.add(this.parent,A.Affected),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=[];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),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),pi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),this.parent.type===n.DefinitionEntity&&(this.parent.addMethod(this),e==null||e.add(this.parent,A.Affected),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){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=pi(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,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,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,extends:((i=this.extends)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){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||yt(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})})(),extends:(()=>{var u;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(u=this.extends)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(o=>o.toReference(e)),calls:this.calls.map(o=>o.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,extends:((l=this.extends)==null?void 0:l.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,i;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||void 0,extends:((i=this.extends)==null?void 0:i.id)||void 0,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=o1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=pi(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 I;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[],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 f=st(d,o);t?f.setParent(t,null):f.setParent(this.parent,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.inputs)==null?void 0:I.map(D=>D.clone(e,f,m.UUID.uuid(),s));return f.inputs=c,l?(pi(this).map(D=>D.clone(e,f,m.UUID.uuid(),s)),e==null||e.attemptAutoclose("clone-entity",this.id),f):(e==null||e.attemptAutoclose("clone-entity",this.id),f)}getVariableInstances(){return He(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||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"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.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.add(l,A.Added),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(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.InternalCall,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.toShallowJSON(),index:t.internalCalls.length},l=C(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),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)&&wi(o.dataType,s.dataType))||e.push(s)}),p(e)}};h(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}),h(Re,"type",n.FunctionDeclaration),h(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),h(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),h(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),h(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),h(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),h(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),h(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),h(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),h(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),h(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let Fr=Re;function d1(r){const a=OZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=ue({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:O.Error,code:F.InvalidPropertiesCombination,entity:r});i.push(s.error)}return Ke(r.errors,i)}const jJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));function UJ(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${se(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:O.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:O.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:O.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}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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:O.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:O.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:O.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 Bc=(r=>(r.Entity="entity",r))(Bc||{});const De=class De extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"isList",null);h(this,"asType",null);h(this,"type",n.DataType);h(this,"options",null);h(this,"parentRelationType",null);h(this,"like");h(this,"implementationChooseOne",!1);h(this,"inferred",!1);h(this,"staticEntities",null);h(this,"interactiveEntities",null);h(this,"actionEntities",null);h(this,"entity",null);h(this,"andChildrenGroup",null);h(this,"orChildrenGroup",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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,this.staticEntities=e.staticEntities,this.interactiveEntities=e.interactiveEntities,this.actionEntities=e.actionEntities}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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,staticEntities:null,interactiveEntities:null,actionEntities: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,staticEntities:e.staticEntities??null,interactiveEntities:e.interactiveEntities??null,actionEntities:e.actionEntities??null,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=UJ(i,t);if(s.push(...l,...ut(i)),i.entity){const f=t.get(i.entity);if(f.type===n.DefinitionEntity){const E=Wt(f).filter(I=>!I.interactive);if(E.length){const I=E.length>1?`entities with ids '${se(E.map(D=>D.id),"', '","' and '")}'`:`entity with id '${E[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.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 ${I}.
56
56
  ${rn}`,issue:null}))}}}const o=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),d=o?an(o):null;if(d)s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.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 f=o.type,c=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(c.includes(f)&&(i.parentRelationType&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${f}'.
57
57
  The entitities of type '${se(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const E=(u=o.dataType)==null?void 0:u.id;s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.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 '${f}', because it already has a 'data-type' child with id '${E}'.
58
58
  The entitities of type '${se(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:
59
59
  ${tr({describe_entity:E})}
60
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}f===n.DataType&&(!i.parentRelationType||!(i.parentRelationType===Pt.AndDataTypeGroup||i.parentRelationType===Pt.OrDataTypeGroup))&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.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)||an(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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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===Pt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Pt.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,this.staticEntities=e.staticEntities!==void 0?e.staticEntities:s.staticEntities,this.interactiveEntities=e.interactiveEntities!==void 0?e.interactiveEntities:s.interactiveEntities,this.actionEntities=e.actionEntities!==void 0?e.actionEntities:s.actionEntities,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=U,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:u,removed:f}=this.entity.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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===Pt.AndDataTypeGroup){if(Array.isArray(u.andChildrenGroup)){const f=u.andChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.andChildrenGroup.splice(f,1)}}else if(this.parentRelationType===Pt.OrDataTypeGroup&&Array.isArray(u.orChildrenGroup)){const f=u.orChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.orChildrenGroup.splice(f,1)}}else{const f=this.parent;f==null||f.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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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===Pt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Pt.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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,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=J){var i,s,l,o,d,u,f,c,E;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((u=this.andChildrenGroup)==null?void 0:u.map(I=>I.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(I=>I.toJSONClone({...e,newId:null})))||null,entity:((c=this.entity)==null?void 0:c.parent)===this?this.entity.toJSONClone({...e,newId:null}):((E=this.entity)==null?void 0:E.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,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=d1(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 I,D,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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},f=st(u,l);t&&f.setParent(t,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.andChildrenGroup)==null?void 0:I.map(V=>V.clone(e,f,m.UUID.uuid(),s)),E=(D=this.orChildrenGroup)==null?void 0:D.map(V=>V.clone(e,f,m.UUID.uuid(),s));if(f.andChildrenGroup=c||null,f.orChildrenGroup=E||null,this.entity&&this.entity.type===n.DefinitionEntity&&((P=this.entity)==null?void 0:P.parent)===this){const V=this.entity.clone(e,f,m.UUID.uuid(),s);f.setEntity(V)}else this.entity&&f.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),f}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===N.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",f={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(f,this.project);c.setParent(this,t),c.initChildren(t),t==null||t.add(c,A.Added),c.metaSync(f,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:f,removed:c,affected:E}=this.entity.inferFromInputs(e,t);s.push(...u),i.push(...f),l.push(...c),o.push(...E)}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}}};h(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}),h(De,"type",n.DataType),h(De,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),h(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),h(De,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),h(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),h(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"inferred"]),h(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),h(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),h(De,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),h(De,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),h(De,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),h(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),h(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let xr=De;function u1(r){var o;const a=oZ(),e=r.toJSON();a.safeParse(e).success;const i=$J(r),s=Ar(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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate(),Ke(r.errors,l)}function $J(r){const a=[];return r.inputs.forEach(e=>{e.validate()}),Ke(r.errors,a)}const GJ=Object.freeze(Object.defineProperty({__proto__:null,validate:u1},Symbol.toStringTag,{value:"Module"}));var p1=(r=>(r.Parent="parent",r))(p1||{});const Oe=class Oe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Operation);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 E=_(e.parent);i=t.get(E)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(E=>{const I=_(E);return t.get(I)}),d=e.calledBySuccess.map(E=>{const I=_(E);return t.get(I)}),u=e.calledByError.map(E=>{const I=_(E);return t.get(I)}),f={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(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=_(i.declaration);if(o){const d=eP(o,t);s.push(...d)}else{const d=`
60
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}f===n.DataType&&(!i.parentRelationType||!(i.parentRelationType===Pt.AndDataTypeGroup||i.parentRelationType===Pt.OrDataTypeGroup))&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.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)||an(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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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===Pt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Pt.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,this.staticEntities=e.staticEntities!==void 0?e.staticEntities:s.staticEntities,this.interactiveEntities=e.interactiveEntities!==void 0?e.interactiveEntities:s.interactiveEntities,this.actionEntities=e.actionEntities!==void 0?e.actionEntities:s.actionEntities,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=U,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:u,removed:f}=this.entity.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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===Pt.AndDataTypeGroup){if(Array.isArray(u.andChildrenGroup)){const f=u.andChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.andChildrenGroup.splice(f,1)}}else if(this.parentRelationType===Pt.OrDataTypeGroup&&Array.isArray(u.orChildrenGroup)){const f=u.orChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.orChildrenGroup.splice(f,1)}}else{const f=this.parent;f==null||f.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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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===Pt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Pt.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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,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=J){var i,s,l,o,d,u,f,c,E;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((u=this.andChildrenGroup)==null?void 0:u.map(I=>I.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(I=>I.toJSONClone({...e,newId:null})))||null,entity:((c=this.entity)==null?void 0:c.parent)===this?this.entity.toJSONClone({...e,newId:null}):((E=this.entity)==null?void 0:E.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,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=d1(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 I,D,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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},f=st(u,l);t&&f.setParent(t,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.andChildrenGroup)==null?void 0:I.map(V=>V.clone(e,f,m.UUID.uuid(),s)),E=(D=this.orChildrenGroup)==null?void 0:D.map(V=>V.clone(e,f,m.UUID.uuid(),s));if(f.andChildrenGroup=c||null,f.orChildrenGroup=E||null,this.entity&&this.entity.type===n.DefinitionEntity&&((P=this.entity)==null?void 0:P.parent)===this){const V=this.entity.clone(e,f,m.UUID.uuid(),s);f.setEntity(V)}else this.entity&&f.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),f}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===N.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",f={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(f,this.project);c.setParent(this,t),c.initChildren(t),t==null||t.add(c,A.Added),c.metaSync(f,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:f,removed:c,affected:E}=this.entity.inferFromInputs(e,t);s.push(...u),i.push(...f),l.push(...c),o.push(...E)}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}}};h(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}),h(De,"type",n.DataType),h(De,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),h(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),h(De,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),h(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),h(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"inferred"]),h(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),h(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),h(De,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),h(De,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),h(De,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),h(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),h(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let xr=De;function u1(r){var o;const a=oZ(),e=r.toJSON();a.safeParse(e).success;const i=$J(r),s=Ar(r),l=[...i,...s];if(r.id==="exec-sequentially-operation-call-id"){const d=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate(),Ke(r.errors,l)}function $J(r){const a=[];return r.inputs.forEach(e=>{e.validate()}),Ke(r.errors,a)}const GJ=Object.freeze(Object.defineProperty({__proto__:null,validate:u1},Symbol.toStringTag,{value:"Module"}));var p1=(r=>(r.Parent="parent",r))(p1||{});const Oe=class Oe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Operation);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 E=_(e.parent);i=t.get(E)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(E=>{const I=_(E);return t.get(I)}),d=e.calledBySuccess.map(E=>{const I=_(E);return t.get(I)}),u=e.calledByError.map(E=>{const I=_(E);return t.get(I)}),f={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(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=_(i.declaration);if(o){const d=eP(o,t);s.push(...d)}else{const d=`
61
61
  All built-in 'action-descriptor' entity ids are:
62
62
  - ${t.operationDeclarations.map(u=>`${u.id} (${x(u,t)})`).join(`
63
63
  - `)}.
64
64
  `;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:O.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.
65
65
  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:O.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.
66
66
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
67
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:E}=this.syncMissingFixedOutputs(e),{updated:I,added:D,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...f,...I),i.push(...d,...c,...I),s.push(...u,...E,...I),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&i.setParent(this.parent,null);return i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null})})}toReference(e=J){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=J){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=u1(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=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=st(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 E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-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 f;return u.id===((f=o.declaration)==null?void 0:f.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 f;return u.id===((f=o.declaration)==null?void 0:f.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===L.FixedArguments&&!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),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===L.FixedReturns&&!this.outputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.outputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.outputs.forEach(D=>{D.index>=c.index&&D.index++});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.outputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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}),h(Oe,"type",n.Operation),h(Oe,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),h(Oe,"MUTABLE_BASE_PROPERTIES",[]),h(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),h(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),h(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let kr=Oe;function c1(r){var s;const a=C5(),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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const gJ=Object.freeze(Object.defineProperty({__proto__:null,validate:c1},Symbol.toStringTag,{value:"Module"}));var f1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(f1||{});const Pe=class Pe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"isError");h(this,"type",n.ReturnDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"readsValue",null);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=bt(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=wc(i,t);if(i=l.modifiedData,i.parent){const f=t.get(_(i.parent));if(f&&[n.BreakStatement,n.ContinueStatement].includes(f.type)){const c=f,E=c.parent,I=[...E.breakStatements.filter(P=>P.id!==f.id),...E.continueStatements.filter(P=>P.id!==f.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
67
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:E}=this.syncMissingFixedOutputs(e),{updated:I,added:D,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...f,...I),i.push(...d,...c,...I),s.push(...u,...E,...I),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&i.setParent(this.parent,null);return i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null})})}toReference(e=J){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=J){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=u1(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=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=st(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 E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-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 f;return u.id===((f=o.declaration)==null?void 0:f.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 f;return u.id===((f=o.declaration)==null?void 0:f.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===L.FixedArguments&&!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),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===L.FixedReturns&&!this.outputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.outputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.outputs.forEach(D=>{D.index>=c.index&&D.index++});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.outputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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}),h(Oe,"type",n.Operation),h(Oe,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),h(Oe,"MUTABLE_BASE_PROPERTIES",[]),h(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),h(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),h(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let kr=Oe;function c1(r){var s;const a=C5(),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=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const gJ=Object.freeze(Object.defineProperty({__proto__:null,validate:c1},Symbol.toStringTag,{value:"Module"}));var f1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(f1||{});const Pe=class Pe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"isError");h(this,"type",n.ReturnDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"readsValue",null);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=bt(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=wc(i,t);if(i=l.modifiedData,i.parent){const f=t.get(_(i.parent));if(f&&[n.BreakStatement,n.ContinueStatement].includes(f.type)){const c=f,E=c.parent,I=[...E.breakStatements.filter(P=>P.id!==f.id),...E.continueStatements.filter(P=>P.id!==f.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
68
68
  ${$c}`,issue:null}));else{const P=(u=(d=I[0])==null?void 0:d.outputs[0])==null?void 0:u.name;P!==i.name&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
69
69
  ${$c}`,issue:null}))}}else if(f&&f.type===n.ReturnStatement){const c=f.parent;if(c&&rt.includes(c.type)){const E=c.implements;if(E){const I=E.outputs.find(B=>B.name===i.name),D=E.outputs.filter(B=>!f.outputs.find(q=>q.type===n.ReturnDeclaration&&q.name===B.name)),P=f.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: ${se(P.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",G=D.length?`The parent entity is still missing the following returns in the implementation: ${se(D.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";I?V&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${f.type}' with id '${f.id}' that implements a ${n.ActionDescriptor} with fixed outputs.
70
70
  Adding a new return would make the implementation invalid. An return with the same name already exists in the parent entity.
@@ -97,15 +97,15 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
97
97
  ${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.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.
98
98
  ${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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.
99
99
  ${Wl(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:O.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.
100
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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(`${Vt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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)}),this.parent.type===n.Project&&this.project.addCondition(this),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=J){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||yt(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=J){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=J){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=A1(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 I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=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=st(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 E=(I=this.inputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-input-map-"+P+"-id",s));return c.inputs=E,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 f;return u.id===((f=o.declaration)==null?void 0:f.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}}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===L.FixedArguments&&!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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}),h(ke,"type",n.Condition),h(ke,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),h(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),h(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"MUTABLE_META_PROPERTIES",["x","y"]),h(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),h(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),h(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),h(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let Wr=ke;function R1(r){var o;const a=BZ(),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=[...Ar(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:O.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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"}));function D1(r){const a=jZ(),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=[...Ar(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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const zJ=Object.freeze(Object.defineProperty({__proto__:null,validate:D1},Symbol.toStringTag,{value:"Module"}));var Nc=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(Nc||{});const Ve=class Ve extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.VariableInstance);h(this,"defaultValue",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 I=_(e.parent);i=t.get(I)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const D=_(I);return t.get(D)}),d=e.calledBySuccess.map(I=>{const D=_(I);return t.get(D)}),u=e.calledByError.map(I=>{const D=_(I);return t.get(D)});let f=null;if(e.readsValue){const I=_(e.readsValue);f=t.get(I)}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:f,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},E=C(c,t);return E.setParent(i,null),E.initChildren(null),E}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,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}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=Na(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:O.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.
100
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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(`${Vt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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)}),this.parent.type===n.Project&&this.project.addCondition(this),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=J){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||yt(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=J){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=J){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=A1(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 I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=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=st(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 E=(I=this.inputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-input-map-"+P+"-id",s));return c.inputs=E,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 f;return u.id===((f=o.declaration)==null?void 0:f.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}}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===L.FixedArguments&&!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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}),h(ke,"type",n.Condition),h(ke,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),h(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),h(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"MUTABLE_META_PROPERTIES",["x","y"]),h(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),h(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),h(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),h(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let Wr=ke;function R1(r){var o;const a=BZ(),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=[...Ar(r)];if(r.id==="random-company-employee-test-variable-id"){const d=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"}));function D1(r){const a=jZ(),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=[...Ar(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const zJ=Object.freeze(Object.defineProperty({__proto__:null,validate:D1},Symbol.toStringTag,{value:"Module"}));var Nc=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(Nc||{});const Ve=class Ve extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.VariableInstance);h(this,"defaultValue",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 I=_(e.parent);i=t.get(I)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const D=_(I);return t.get(D)}),d=e.calledBySuccess.map(I=>{const D=_(I);return t.get(D)}),u=e.calledByError.map(I=>{const D=_(I);return t.get(D)});let f=null;if(e.readsValue){const I=_(e.readsValue);f=t.get(I)}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:f,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},E=C(c,t);return E.setParent(i,null),E.initChildren(null),E}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,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}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=Na(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:O.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.
101
101
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
102
102
  Specifically for variables, their scope is also calculated from their value readers and value writters.
103
103
  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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.parent)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"parent"}]),(l=(s=(i=this.declaration.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),(d=(o=this.declaration)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"var-declaration"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.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;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:E,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...D);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:g,updated:q,removed:S,affected:Q}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...g),t.push(...q),s.push(...S),l.push(...Q)}return 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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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 Za.initWritesValues(this,this.parent),Rr.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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:((f=this.readsValue)==null?void 0:f.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=J){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=J){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=D1(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 D,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=st(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 f=(D=this.defaultValue)==null?void 0:D.clone(e,u,m.UUID.uuid(),s);u.defaultValue=f||null;const c=(P=this.inputs)==null?void 0:P.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const E=(V=this.outputs)==null?void 0:V.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=E;const I=(M=this.internalCalls)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=I,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 E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.declaration.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const D=Ui(I);c.setDataType(D),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={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},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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(f=>f.declaration===u)).map(u=>{const f={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(f,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 I,D,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.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 f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});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)}};h(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}),h(Ve,"type",n.VariableInstance),h(Ve,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),h(Ve,"MUTABLE_BASE_PROPERTIES",[]),h(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),h(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),h(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),h(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Sr=Ve;var O1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(O1||{});const Be=class Be extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"required",!1);h(this,"constant",!1);h(this,"x");h(this,"y");h(this,"type",n.VariableDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});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},f=C(u,t);return f.setParent(i,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData;const o=Dc(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===Nc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=Na(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:O.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
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.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;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:E,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...D);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:g,removed:q,affected:S}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...g),s.push(...q),l.push(...S)}return 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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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)),Za.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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,g;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=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,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,A.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const S=(G=this.dataType)==null?void 0:G.merge(q,e);this.dataType&&(S==null?void 0:S.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((B=S==null?void 0:S.self)==null?void 0:B.id)&&q.remove({ignoreUpstream:!1},e),S!=null&&S.self&&(S.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(S.self,A.Added),this.setDataType(S.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(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(Q=>x(Q,this.project)===x(q,this.project))||d.push(q)}),!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((g=this.dataType)==null||g.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:f,removed:c,affected:E}=this.generateUnusedInputs(e);t.push(...f),i.push(...u),s.push(...c),l.push(...E);const{updated:I,added:D,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...D),i.push(...I),s.push(...P),l.push(...V),this.variableInstances.forEach(q=>{const{updated:S,added:Q,removed:pe,affected:me}=q.generateUnusedInputs(e);t.push(...Q),i.push(...S),s.push(...pe),l.push(...me);const{updated:X,added:oe,removed:gt,affected:ir}=q.generateUnusedOutputs(e);t.push(...oe),i.push(...X),s.push(...gt),l.push(...ir)}),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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(E=>E.toJSONClone({...e,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...e,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(E=>E.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(E=>this.calledBy.length||this.readsValue?E.toJSONClone({...e,newId:null}):E.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){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=J){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=R1(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=st(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 f=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const E=(M=this.inputs)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=E;const I=(G=this.outputs)==null?void 0:G.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const D=(B=this.internalCalls)==null?void 0:B.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=D,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.toReference(),x:0,y:0},l=C(s,this.project);return l.hydrateAncestors(),l.setParent(e,t),t==null||t.add(l,A.Added),l.addSelfToProject(t),l.initChildren(t),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 E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const D=Ui(I);c.setDataType(D),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={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},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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(f=>f.declaration===u)).map(u=>{const f={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(f,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 I,D,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.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 f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});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)}};h(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}),h(Be,"type",n.VariableDeclaration),h(Be,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),h(Be,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),h(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),h(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),h(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),h(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let zr=Be;function P1(r){var l;const a=Y5(),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=[...Ar(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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return Ke(r.errors,s)}const YJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"}));var w1=(r=>(r.Parent="parent",r))(w1||{});const Se=class Se extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"query","");h(this,"type",n.Search);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"inputsDeclarations",[]);h(this,"inputs",[]);h(this,"outputsDeclarations",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"error",null);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 f=_(e.parent);i=t.get(f)}const s=e.calledByEntry.map(f=>{const c=_(f);return t.get(c)}),l=e.calledBySuccess.map(f=>{const c=_(f);return t.get(c)}),o=e.calledByError.map(f=>{const c=_(f);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=bt(i,{parent:{list:!1,types:[...ht,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:O.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.
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.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;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:E,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...D);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:g,removed:q,affected:S}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...g),s.push(...q),l.push(...S)}return 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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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)),Za.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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,g;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=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,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,A.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const S=(G=this.dataType)==null?void 0:G.merge(q,e);this.dataType&&(S==null?void 0:S.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((B=S==null?void 0:S.self)==null?void 0:B.id)&&q.remove({ignoreUpstream:!1},e),S!=null&&S.self&&(S.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(S.self,A.Added),this.setDataType(S.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(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(Q=>x(Q,this.project)===x(q,this.project))||d.push(q)}),!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((g=this.dataType)==null||g.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:f,removed:c,affected:E}=this.generateUnusedInputs(e);t.push(...f),i.push(...u),s.push(...c),l.push(...E);const{updated:I,added:D,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...D),i.push(...I),s.push(...P),l.push(...V),this.variableInstances.forEach(q=>{const{updated:S,added:Q,removed:pe,affected:me}=q.generateUnusedInputs(e);t.push(...Q),i.push(...S),s.push(...pe),l.push(...me);const{updated:X,added:oe,removed:gt,affected:ir}=q.generateUnusedOutputs(e);t.push(...oe),i.push(...X),s.push(...gt),l.push(...ir)}),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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(E=>E.toJSONClone({...e,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...e,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(E=>E.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(E=>this.calledBy.length||this.readsValue?E.toJSONClone({...e,newId:null}):E.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){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=J){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=R1(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=st(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 f=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const E=(M=this.inputs)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=E;const I=(G=this.outputs)==null?void 0:G.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const D=(B=this.internalCalls)==null?void 0:B.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=D,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.toReference(),x:0,y:0},l=C(s,this.project);return l.hydrateAncestors(),l.setParent(e,t),t==null||t.add(l,A.Added),l.addSelfToProject(t),l.initChildren(t),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 E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const D=Ui(I);c.setDataType(D),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={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},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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(f=>f.declaration===u)).map(u=>{const f={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(f,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 I,D,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.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 f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});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)}};h(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}),h(Be,"type",n.VariableDeclaration),h(Be,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),h(Be,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),h(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),h(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),h(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),h(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let zr=Be;function P1(r){var l;const a=Y5(),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=[...Ar(r)];if(r.id==="search-person-by-id-id"){const o=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return Ke(r.errors,s)}const YJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"}));var w1=(r=>(r.Parent="parent",r))(w1||{});const Se=class Se extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"query","");h(this,"type",n.Search);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"inputsDeclarations",[]);h(this,"inputs",[]);h(this,"outputsDeclarations",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"error",null);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 f=_(e.parent);i=t.get(f)}const s=e.calledByEntry.map(f=>{const c=_(f);return t.get(c)}),l=e.calledBySuccess.map(f=>{const c=_(f);return t.get(c)}),o=e.calledByError.map(f=>{const c=_(f);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=bt(i,{parent:{list:!1,types:[...ht,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:O.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
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),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.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),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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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=[];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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){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||yt(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(f=>f.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(f=>f.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),inputs:this.inputs.map(f=>f.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),outputs:this.outputs.map(f=>f.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=J){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=J){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=P1(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"),f=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=st(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 E=(V=this.inputsDeclarations)==null?void 0:V.map((g,q)=>g.clone(e,this,f+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=E;const I=(M=this.outputsDeclarations)==null?void 0:M.map((g,q)=>g.clone(e,this,f+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const D=(G=this.inputs)==null?void 0:G.map((g,q)=>g.clone(e,c,f+"-input-map-"+q+"-id",s));c.inputs=D;const P=(B=this.outputs)==null?void 0:B.map((g,q)=>g.clone(e,c,f+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,f+"-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 f;return((f=u.declaration)==null?void 0:f.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()},f=C(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),t.push(this),i.push(f)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const{updated:u,removed:f}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...f)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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}),h(Se,"type",n.Search),h(Se,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),h(Se,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),h(Se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"MUTABLE_META_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),h(Se,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),h(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),h(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Se,"PROPERTIES",[...ii.META_PROPERTIES,...ii.UPSTREAM_PROPERTIES,...ii.DOWNSTREAM_PROPERTIES]);let Yr=Se;function C1(r){const a=FZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const HJ=Object.freeze(Object.defineProperty({__proto__:null,validate:C1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"type",n.InstalledProject);h(this,"implements");h(this,"functions",[]);h(this,"events",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){return 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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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"))){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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),this.events.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),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"))){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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),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=J){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||yt(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=J){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=J){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=C1(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),f=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=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const E=(D=this.functions)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-exported-function-declaration-"+M+"-id",s));c.functions=E;const I=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(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}),h(Ze,"type",n.InstalledProject),h(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),h(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),h(Ze,"MUTABLE_BASE_PROPERTIES",[]),h(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),h(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),h(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),h(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),h(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),h(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Hr=Ze;function V1(r){var o;const a=Q5(),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=Ar(r),s=B1(r),l=[...i,...s];return Ke(r.errors,l)}function B1(r){const a=[],e=jl(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(de({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:O.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}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:O.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.
108
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),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.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),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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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=[];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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){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||yt(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(f=>f.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(f=>f.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),inputs:this.inputs.map(f=>f.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),outputs:this.outputs.map(f=>f.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=J){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=J){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=P1(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"),f=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=st(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 E=(V=this.inputsDeclarations)==null?void 0:V.map((g,q)=>g.clone(e,this,f+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=E;const I=(M=this.outputsDeclarations)==null?void 0:M.map((g,q)=>g.clone(e,this,f+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const D=(G=this.inputs)==null?void 0:G.map((g,q)=>g.clone(e,c,f+"-input-map-"+q+"-id",s));c.inputs=D;const P=(B=this.outputs)==null?void 0:B.map((g,q)=>g.clone(e,c,f+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,f+"-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 f;return((f=u.declaration)==null?void 0:f.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()},f=C(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),t.push(this),i.push(f)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const{updated:u,removed:f}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...f)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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}),h(Se,"type",n.Search),h(Se,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),h(Se,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),h(Se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"MUTABLE_META_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),h(Se,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),h(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),h(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Se,"PROPERTIES",[...ii.META_PROPERTIES,...ii.UPSTREAM_PROPERTIES,...ii.DOWNSTREAM_PROPERTIES]);let Yr=Se;function C1(r){const a=FZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const HJ=Object.freeze(Object.defineProperty({__proto__:null,validate:C1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"type",n.InstalledProject);h(this,"implements");h(this,"functions",[]);h(this,"events",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){return 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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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"))){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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),this.events.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),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"))){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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),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=J){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||yt(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=J){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=J){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=C1(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),f=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=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const E=(D=this.functions)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-exported-function-declaration-"+M+"-id",s));c.functions=E;const I=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(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}),h(Ze,"type",n.InstalledProject),h(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),h(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),h(Ze,"MUTABLE_BASE_PROPERTIES",[]),h(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),h(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),h(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),h(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),h(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),h(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Hr=Ze;function V1(r){var o;const a=Q5(),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=Ar(r),s=B1(r),l=[...i,...s];return Ke(r.errors,l)}function B1(r){const a=[],e=jl(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(ue({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:O.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(ue({id:`${r.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:O.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.
109
109
  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=Ga(t),s=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&s.push(...t.getAllInteractiveMethods());let l="";i?t.methods.length?l=`
110
110
  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:
111
111
  - ${t.methods.map(u=>u.id).join(`
@@ -116,8 +116,8 @@ You can attach methods to it by creating 'function-declaration' entities which h
116
116
  This variable's data-type 'entity' is a ${t.type} which doesn't have any methods attached to it yet.
117
117
  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=`
118
118
  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=`
119
- 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}--${$.InternalCallDeclarationIsNotFunctionDeclaration}`,code:$.InternalCallDeclarationIsNotFunctionDeclaration,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", points to a 'declaration' that isn't a 'function-declaration' entity.
120
- 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}--${$.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:$.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:O.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 KJ=Object.freeze(Object.defineProperty({__proto__:null,validate:V1,validateParentRelation:B1},Symbol.toStringTag,{value:"Module"}));var _1=(r=>(r.Declaration="declaration",r))(_1||{});const _e=class _e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"type",n.InternalCall);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"project");h(this,"errors",[]);h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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(I=>{const D=_(I);return t.get(D)}),u=e.calledBySuccess.map(I=>{const D=_(I);return t.get(D)}),f=e.calledByError.map(I=>{const D=_(I);return t.get(D)}),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:f,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,parent:s},E=C(c,t);return E.setParent(s,null),E.initChildren(null),E}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:it}},t);i=l.modifiedData;const o=_(i.parent),d=t.get(o);if(d){const u=jl(d,null),f=u==null?void 0:u.entity;if(!f)s.push(new w({id:`${i.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:O.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(f.type))s.push(new w({id:`${i.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:O.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.
119
+ 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(ue({id:`${r.id}--${$.InternalCallDeclarationIsNotFunctionDeclaration}`,code:$.InternalCallDeclarationIsNotFunctionDeclaration,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", points to a 'declaration' that isn't a 'function-declaration' entity.
120
+ 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(ue({id:`${r.id}--${$.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:$.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:O.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 KJ=Object.freeze(Object.defineProperty({__proto__:null,validate:V1,validateParentRelation:B1},Symbol.toStringTag,{value:"Module"}));var _1=(r=>(r.Declaration="declaration",r))(_1||{});const _e=class _e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"type",n.InternalCall);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"project");h(this,"errors",[]);h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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(I=>{const D=_(I);return t.get(D)}),u=e.calledBySuccess.map(I=>{const D=_(I);return t.get(D)}),f=e.calledByError.map(I=>{const D=_(I);return t.get(D)}),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:f,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,parent:s},E=C(c,t);return E.setParent(s,null),E.initChildren(null),E}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:it}},t);i=l.modifiedData;const o=_(i.parent),d=t.get(o);if(d){const u=jl(d,null),f=u==null?void 0:u.entity;if(!f)s.push(new w({id:`${i.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:O.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(f.type))s.push(new w({id:`${i.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:O.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.
121
121
  This variable's data-type has an 'entity' field that references an entity with id '${f.id}' and of type '${f.type}'.`,issue:null}));else{const c=Ga(f);let E="";c?f.methods.length?E=`
122
122
  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:
123
123
  - ${f.methods.map(V=>V.id).join(`
@@ -134,7 +134,7 @@ ${rn}`);const I=i.declaration;if(!t.get(I))s.push(new w({id:`${i.id}--${R.Refere
134
134
  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.${E}`,issue:null})):s.push(new w({id:`${i.id}--${$.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:$.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:O.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}".${E}`,issue:null}))}}(d.inputs.length||d.outputs.length||d.internalCalls.length)&&s.push(new w({id:`${i.id}--${R.InvalidInternalCallParentRelation}`,code:R.InvalidInternalCallParentRelation,severity:O.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.
135
135
  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.
136
136
  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:O.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.
137
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),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 _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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...E),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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&&ht.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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return 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=U,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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"))){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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.error)==null?void 0:f.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=J){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=J){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=V1(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=st(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 E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-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 f;return u.id===((f=o.declaration)==null?void 0:f.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 f;return u.id===((f=o.declaration)==null?void 0:f.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(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),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(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const D=o.includes(E.index)?this.outputs.length-1+I:E.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:E.toJSON(),defaultValue:null,writesValues:[],index:D,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((E,I)=>E.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),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}}};h(_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}),h(_e,"type",n.InternalCall),h(_e,"USER_MANAGED_PARENT_TYPES",[...it]),h(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),h(_e,"MUTABLE_BASE_PROPERTIES",[]),h(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),h(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),h(_e,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),h(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Kr=_e;function M1(r){const a=rZ(),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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const XJ=Object.freeze(Object.defineProperty({__proto__:null,validate:M1},Symbol.toStringTag,{value:"Module"}));var N1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(N1||{});const Me=class Me extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"name",null);h(this,"description",null);h(this,"type",n.InputMap);h(this,"defaultValue",null);h(this,"readsValue",null);h(this,"dataType",null);h(this,"declaration",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 f=_(e.declaration);l=t.get(f)}let o=null;if(e.readsValue){const f=_(e.readsValue);o=t.get(f)}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 f;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...dt,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 E;return i.declaration&&((E=c.declaration)==null?void 0:E.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:O.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}'.
137
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),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 _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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...E),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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&&ht.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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return 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=U,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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"))){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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.error)==null?void 0:f.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=J){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=J){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=V1(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=st(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 E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-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 f;return u.id===((f=o.declaration)==null?void 0:f.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 f;return u.id===((f=o.declaration)==null?void 0:f.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(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),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(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const D=o.includes(E.index)?this.outputs.length-1+I:E.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:E.toJSON(),defaultValue:null,writesValues:[],index:D,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((E,I)=>E.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),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}}};h(_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}),h(_e,"type",n.InternalCall),h(_e,"USER_MANAGED_PARENT_TYPES",[...it]),h(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),h(_e,"MUTABLE_BASE_PROPERTIES",[]),h(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),h(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),h(_e,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),h(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Kr=_e;function M1(r){const a=rZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const XJ=Object.freeze(Object.defineProperty({__proto__:null,validate:M1},Symbol.toStringTag,{value:"Module"}));var N1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(N1||{});const Me=class Me extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"name",null);h(this,"description",null);h(this,"type",n.InputMap);h(this,"defaultValue",null);h(this,"readsValue",null);h(this,"dataType",null);h(this,"declaration",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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 f=_(e.declaration);l=t.get(f)}let o=null;if(e.readsValue){const f=_(e.readsValue);o=t.get(f)}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 f;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...dt,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 E;return i.declaration&&((E=c.declaration)==null?void 0:E.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:O.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}'.
138
138
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
139
139
  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&&!it.includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:O.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}'.
140
140
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
@@ -152,7 +152,7 @@ Input maps can only be added to variables which hold an entity with properties.`
152
152
  The entity of the data-type has the following properties that can be reads as input maps, ids: '${se(D.properties.map(V=>V.id),"', '","' and '")}'`,issue:null})))}else if(dt.filter(c=>it.includes(c)).includes(o.type)){const E=Kc(o),I=E.find(P=>P.id===i.declaration),D=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${se(E.map(P=>P.id),"', '","' and '")}'`;I||s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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}'.
153
153
  You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
154
154
  ${D}`,issue:null}))}}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=Na(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:O.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.
155
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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 Rr.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),it.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:f,added:c,removed:E,affected:I}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...f),i.push(...c),s.push(...E),l.push(...I),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)),Rr.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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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"))){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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.defaultValue){const{updated:u,removed:f}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),this.declaration){if(this.declaration.type===n.Property&&this.declaration.parent.type===n.DefinitionEntity&&this.declaration.parent.parent.type===n.DataType&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}else if(this.declaration.type===n.ValueDescriptor&&((d=this.declaration.parent)==null?void 0:d.type)===n.Search&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}}return 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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f,c,E,I,D;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(E=this.declaration)==null?void 0:E.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,readsValue:((D=this.readsValue)==null?void 0:D.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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=M1(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=st(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 f=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=f||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(it.includes(this.parent.type)){const s=Un(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=Ui(this,e);if(s)return s}return t||null}};h(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}),h(Me,"type",n.InputMap),h(Me,"USER_MANAGED_PARENT_TYPES",[...dt]),h(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),h(Me,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),h(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),h(Me,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),h(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),h(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),h(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let Xi=Me;class QJ extends Xi{constructor(e,t){super(e,t);h(this,"declaration",null);h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class eW extends Xi{constructor(e,t){super(e,t);h(this,"name",null);h(this,"description",null);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function L1(r){const a=U5(),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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const tW=Object.freeze(Object.defineProperty({__proto__:null,validate:L1},Symbol.toStringTag,{value:"Module"}));var j1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(j1||{});const Ne=class Ne extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"type",n.OutputMap);h(this,"parentRelationType");h(this,"defaultValue",null);h(this,"declaration");h(this,"writesValues",[]);h(this,"dataType",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=bt(i,{parent:{list:!1,types:dt.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&&dt.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(f=>f.declaration.id===(i.declaration?_(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:O.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'.
155
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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 Rr.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),it.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:f,added:c,removed:E,affected:I}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...f),i.push(...c),s.push(...E),l.push(...I),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)),Rr.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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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"))){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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.defaultValue){const{updated:u,removed:f}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),this.declaration){if(this.declaration.type===n.Property&&this.declaration.parent.type===n.DefinitionEntity&&this.declaration.parent.parent.type===n.DataType&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}else if(this.declaration.type===n.ValueDescriptor&&((d=this.declaration.parent)==null?void 0:d.type)===n.Search&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}}return 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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f,c,E,I,D;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(E=this.declaration)==null?void 0:E.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,readsValue:((D=this.readsValue)==null?void 0:D.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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=M1(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=st(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 f=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=f||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(it.includes(this.parent.type)){const s=Un(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=Ui(this,e);if(s)return s}return t||null}};h(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}),h(Me,"type",n.InputMap),h(Me,"USER_MANAGED_PARENT_TYPES",[...dt]),h(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),h(Me,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),h(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),h(Me,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),h(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),h(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),h(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let Xi=Me;class QJ extends Xi{constructor(e,t){super(e,t);h(this,"declaration",null);h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class eW extends Xi{constructor(e,t){super(e,t);h(this,"name",null);h(this,"description",null);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function L1(r){const a=U5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const tW=Object.freeze(Object.defineProperty({__proto__:null,validate:L1},Symbol.toStringTag,{value:"Module"}));var j1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(j1||{});const Ne=class Ne extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"type",n.OutputMap);h(this,"parentRelationType");h(this,"defaultValue",null);h(this,"declaration");h(this,"writesValues",[]);h(this,"dataType",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=bt(i,{parent:{list:!1,types:dt.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&&dt.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(f=>f.declaration.id===(i.declaration?_(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:O.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'.
156
156
  Any value reads can be done with that output-map instead.
157
157
  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 f=i.declaration?t.get(i.declaration):null;if(f&&it.includes(o.type)){const c=Un(o),E=c.dataType,I=(d=c.dataType)==null?void 0:d.entity;E?I?I.type===n.ActionDescriptor?s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
158
158
  This means it can hold a function-call or operation as its value, to be executed programatically.
@@ -162,7 +162,7 @@ ${Gc}`,issue:null})):s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSign
162
162
  ${Gc}`,issue:null}))}else if(f){const c=o.outputs.find(E=>E.declaration.id===i.declaration);c&&s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:O.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.
163
163
  Any value reads can be done with that output-map instead.
164
164
  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}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
165
- 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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===xn.Error?it.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===k["value-descriptor"][Zn.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)),Za.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=U,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ne.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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===xn.Error?it.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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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===xn.Error?it.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=J){var i,s,l,o,d,u,f,c,E,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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(D=>D.toJSONClone({...e,newId:null})),declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(E=this.declaration)==null?void 0:E.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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=L1(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 E,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d;const u=st(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 f=(E=this.dataType)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.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}};h(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}),h(Ne,"type",n.OutputMap),h(Ne,"USER_MANAGED_PARENT_TYPES",[...lf]),h(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),h(Ne,"MUTABLE_BASE_PROPERTIES",[]),h(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),h(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),h(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),h(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Qi=Ne;class iW extends Qi{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class rW extends Qi{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function U1(r){var s;const a=m7(),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:O.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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const nW=Object.freeze(Object.defineProperty({__proto__:null,validate:U1},Symbol.toStringTag,{value:"Module"}));var $1=(r=>(r.DataTypeEntity="data-type-entity",r.Implements="implements",r))($1||{});const Le=class Le extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"type",n.ArgumentDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=bt(i,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);i=l.modifiedData;const o=Pc(i,t);if(i.parent){const d=t.get(_(i.parent));if(d&&rt.includes(d.type)){const u=d.implements;if(u){const f=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)),E=d.inputs.filter(V=>V.type===n.ArgumentDeclaration),I=E.find(V=>V.name===i.name),D=E.length?`The parent entity already implements the following arguments: ${se(E.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: ${se(c.map(V=>`'${V.id}' (${V.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";f?I&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
165
+ 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),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 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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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===xn.Error?it.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===k["value-descriptor"][Zn.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)),Za.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=U,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ne.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),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===xn.Error?it.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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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===xn.Error?it.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=J){var i,s,l,o,d,u,f,c,E,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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(D=>D.toJSONClone({...e,newId:null})),declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(E=this.declaration)==null?void 0:E.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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=L1(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 E,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d;const u=st(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 f=(E=this.dataType)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.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}};h(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}),h(Ne,"type",n.OutputMap),h(Ne,"USER_MANAGED_PARENT_TYPES",[...lf]),h(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),h(Ne,"MUTABLE_BASE_PROPERTIES",[]),h(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),h(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),h(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),h(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Qi=Ne;class iW extends Qi{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class rW extends Qi{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function U1(r){var s;const a=m7(),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=ue({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:O.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=ue({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:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const nW=Object.freeze(Object.defineProperty({__proto__:null,validate:U1},Symbol.toStringTag,{value:"Module"}));var $1=(r=>(r.DataTypeEntity="data-type-entity",r.Implements="implements",r))($1||{});const Le=class Le extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"type",n.ArgumentDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=bt(i,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);i=l.modifiedData;const o=Pc(i,t);if(i.parent){const d=t.get(_(i.parent));if(d&&rt.includes(d.type)){const u=d.implements;if(u){const f=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)),E=d.inputs.filter(V=>V.type===n.ArgumentDeclaration),I=E.find(V=>V.name===i.name),D=E.length?`The parent entity already implements the following arguments: ${se(E.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: ${se(c.map(V=>`'${V.id}' (${V.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";f?I&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
166
166
  Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
167
167
  ${D}
168
168
  ${P}`,issue:null})):s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.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.
@@ -395,14 +395,14 @@ The only use for declaring global callable entities is for a 'variable-declarati
395
395
  Or for a logic that the user is going to manually test themselves by clicking on the user-interface.`,issue:null,entity:r}));else{const e=xa(r);if(!e.reachable){let t=`This '${r.type}' entity "${x(r,r.project)}" with id "${r.id}" is not reachable from the project's closest entry point '${e.entryPoint.type}' "${x(e.entryPoint,r.project)}".`;t+=`
396
396
  This is because there are termination statements in the call chain before reaching this '${r.type}'.
397
397
  If a caller entity calls a termination statement, it will always prevent all other calls from executing.`;let i=`
398
- This '${r.type}' is blocked `;e.blocks.forEach((s,l)=>{const o=s.blockedByCaller,d=s.blockedByCalling;l===0?i+="by ":l===e.blocks.length-1&&(i+="and by "),i+=`its ancestor "${x(o,r.project)}" with id "${o.id}" that calls a '${d.type}' entity with id "${d.id}"`,l<e.blocks.length-1?i+=", ":i+="."}),a.push(new Ye({id:`${r.id}--${$.UnreachableEntity}`,code:$.UnreachableEntity,severity:O.Warning,message:`${t}${i}`,issue:null,entity:r}))}}return Ke(r.errors,a)}function Zc(r){const a=[];if(!r.internalCalls.length)return a;if(r.readsValue){const e=de({id:`${r.id}--${F.VariableReadsValueAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" reads a value. A variable with internal calls can't read a value.`,issue:null,severity:O.Error,code:F.VariableReadsValueAndInternalCall,entity:r});a.push(e.error)}if(r.writesValues.length){const e=de({id:`${r.id}--${F.VariableWritesValuesAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" writes values. A variable with internal calls can't write a value.`,issue:null,severity:O.Error,code:F.VariableWritesValuesAndInternalCall,entity:r});a.push(e.error)}if(r.getUsedInputs().length){const e=de({id:`${r.id}--${F.VariableHasInputsAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" has inputs. A variable with internal calls can't have inputs.`,issue:null,severity:O.Error,code:F.VariableHasInputsAndInternalCall,entity:r});a.push(e.error)}if(r.getUsedOutputs().length){const e=de({id:`${r.id}--${F.VariableHasOutputsAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" has outputs. A variable with internal calls can't have outputs.`,issue:null,severity:O.Error,code:F.VariableHasOutputsAndInternalCall,entity:r});a.push(e.error)}if(r.calledBy.length){const e=de({id:`${r.id}--${F.VariableIsCalledAndHasInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" is called by other entities. A variable with internal calls can't be called by other entities.`,issue:null,severity:O.Error,code:F.VariableIsCalledAndHasInternalCall,entity:r});a.push(e.error)}if([...r.successCalls,...r.errorCalls].length){const e=de({id:`${r.id}--${F.VariableCallsOthersAndHasInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" calls other entities. A variable with internal calls can't call other entities.`,issue:null,severity:O.Error,code:F.VariableCallsOthersAndHasInternalCall,entity:r});a.push(e.error)}return a}function iP(r){var l;const a=F5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Ar(r)];return Ke(r.errors,s)}const AW=Object.freeze(Object.defineProperty({__proto__:null,validate:iP},Symbol.toStringTag,{value:"Module"}));var rP=(r=>(r.Parent="parent",r.Declaration="declaration",r))(rP||{});const Je=class Je extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.FunctionCall);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"process",null);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"error",null);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionCall,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 E=_(e.parent);i=t.get(E)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(E=>{const I=_(E);return t.get(I)}),d=e.calledBySuccess.map(E=>{const I=_(E);return t.get(I)}),u=e.calledByError.map(E=>{const I=_(E);return t.get(I)}),f={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionCall,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},c=C(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=_(i.declaration);if(o){const d=Q1(o,t);s.push(...d)}else{const d=t.functions.length?`
398
+ This '${r.type}' is blocked `;e.blocks.forEach((s,l)=>{const o=s.blockedByCaller,d=s.blockedByCalling;l===0?i+="by ":l===e.blocks.length-1&&(i+="and by "),i+=`its ancestor "${x(o,r.project)}" with id "${o.id}" that calls a '${d.type}' entity with id "${d.id}"`,l<e.blocks.length-1?i+=", ":i+="."}),a.push(new Ye({id:`${r.id}--${$.UnreachableEntity}`,code:$.UnreachableEntity,severity:O.Warning,message:`${t}${i}`,issue:null,entity:r}))}}return Ke(r.errors,a)}function Zc(r){const a=[];if(!r.internalCalls.length)return a;if(r.readsValue){const e=ue({id:`${r.id}--${F.VariableReadsValueAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" reads a value. A variable with internal calls can't read a value.`,issue:null,severity:O.Error,code:F.VariableReadsValueAndInternalCall,entity:r});a.push(e.error)}if(r.writesValues.length){const e=ue({id:`${r.id}--${F.VariableWritesValuesAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" writes values. A variable with internal calls can't write a value.`,issue:null,severity:O.Error,code:F.VariableWritesValuesAndInternalCall,entity:r});a.push(e.error)}if(r.getUsedInputs().length){const e=ue({id:`${r.id}--${F.VariableHasInputsAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" has inputs. A variable with internal calls can't have inputs.`,issue:null,severity:O.Error,code:F.VariableHasInputsAndInternalCall,entity:r});a.push(e.error)}if(r.getUsedOutputs().length){const e=ue({id:`${r.id}--${F.VariableHasOutputsAndInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" has outputs. A variable with internal calls can't have outputs.`,issue:null,severity:O.Error,code:F.VariableHasOutputsAndInternalCall,entity:r});a.push(e.error)}if(r.calledBy.length){const e=ue({id:`${r.id}--${F.VariableIsCalledAndHasInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" is called by other entities. A variable with internal calls can't be called by other entities.`,issue:null,severity:O.Error,code:F.VariableIsCalledAndHasInternalCall,entity:r});a.push(e.error)}if([...r.successCalls,...r.errorCalls].length){const e=ue({id:`${r.id}--${F.VariableCallsOthersAndHasInternalCall}`,message:`Variable "${x(r,r.project)}" with id "${r.id}" calls other entities. A variable with internal calls can't call other entities.`,issue:null,severity:O.Error,code:F.VariableCallsOthersAndHasInternalCall,entity:r});a.push(e.error)}return a}function iP(r){var l;const a=F5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Ar(r)];return Ke(r.errors,s)}const AW=Object.freeze(Object.defineProperty({__proto__:null,validate:iP},Symbol.toStringTag,{value:"Module"}));var rP=(r=>(r.Parent="parent",r.Declaration="declaration",r))(rP||{});const Je=class Je extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.FunctionCall);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"process",null);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"error",null);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionCall,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 E=_(e.parent);i=t.get(E)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(E=>{const I=_(E);return t.get(I)}),d=e.calledBySuccess.map(E=>{const I=_(E);return t.get(I)}),u=e.calledByError.map(E=>{const I=_(E);return t.get(I)}),f={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionCall,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},c=C(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=_(i.declaration);if(o){const d=Q1(o,t);s.push(...d)}else{const d=t.functions.length?`
399
399
  All global 'function-declaration' entity ids are:
400
400
  - ${t.functions.map(u=>`${u.id} (${x(u,t)})`).join(`
401
401
  - `)}.`:`
402
402
  The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:O.Error,message:`Entity of type "${n.FunctionCall}" with id "${i.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
403
403
  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:O.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.
404
404
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),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 Je(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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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 Je(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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...E),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await Je.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Je.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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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=iP(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=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=st(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 E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-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 f;return u.id===((f=o.declaration)==null?void 0:f.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 f;return u.id===((f=o.declaration)==null?void 0:f.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(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),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(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const D=o.includes(E.index)?this.outputs.length-1+I:E.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:E.toJSON(),defaultValue:null,writesValues:[],index:D,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((E,I)=>E.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),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}}};h(Je,"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}),h(Je,"type",n.FunctionCall),h(Je,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Je,"PARENT_TYPES",[...Je.USER_MANAGED_PARENT_TYPES]),h(Je,"MUTABLE_BASE_PROPERTIES",[]),h(Je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Je,"BASE_PROPERTIES",[...Je.MUTABLE_BASE_PROPERTIES,...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"MUTABLE_META_PROPERTIES",["x","y"]),h(Je,"INMUTABLE_META_PROPERTIES",[...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"META_PROPERTIES",[...Je.MUTABLE_META_PROPERTIES,...Je.INMUTABLE_META_PROPERTIES]),h(Je,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Je,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Je,"UPSTREAM_PROPERTIES",[...Je.MUTABLE_UPSTREAM_PROPERTIES,...Je.INMUTABLE_UPSTREAM_PROPERTIES]),h(Je,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),h(Je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Je,"DOWNSTREAM_PROPERTIES",[...Je.MUTABLE_DOWNSTREAM_PROPERTIES,...Je.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Je,"PROPERTIES",[...Je.META_PROPERTIES,...Je.UPSTREAM_PROPERTIES,...Je.DOWNSTREAM_PROPERTIES]);let nn=Je;function qc(r){return r&&typeof r.then=="function"}class Sl{constructor(a){h(this,"order",[]);h(this,"flatRecord",{});h(this,"allBuiltInEntityIds",$i());h(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set($i()),t=p(j(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}=Xl(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}=Xl(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(Xl(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);qc(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);qc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function nP(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 f;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=u.getDefaultValue())==null?void 0:f.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),f=u==null?void 0:u.defaultValue;if(f)f.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:N.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},E=C(c,r.project);return E.setParent(u==null?void 0:u.dataType,a),E.initChildren(a),a==null||a.add(E,A.Added),E.addSelfToProject(a),{newEntities:[E]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=zl(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:N.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 sP(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let f=r.project.entities.filter(I=>I.implements.find(D=>D.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(I=>!!I.properties.find(D=>{var P;return D.implements&&D.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=D.getDefaultValue())==null?void 0:P.value)===!0}));if(!f){f=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const D=f.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=D==null?void 0:D.defaultValue)==null||d.metaSync({value:!0},a),t.push(f)}const c=r.properties.find(I=>I.implements&&I.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),E=c==null?void 0:c.defaultValue;if(c&&!E){const I={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:N.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:f,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},D=C(I,r.project);D.hydrateAncestors(),D.setParent(c,a),D.addSelfToProject(a),D.initChildren(a),a==null||a.add(D,A.Added),t.push(D);return}else E&&E.setValueAsTypeSingle(f,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function zl(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.toJSON()],x:0,y:0,parent:r.project.toReference()};nP(r,e);const o=C(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,A.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),sP(o,e),o}function Jc(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 aP(r,a,e,t=Pt.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,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},f=C(u,r.project);return s.push(f),f.setParent(a,e),f.initChildren(e),e==null||e.add(f,A.Added),f.setEntity(r),f.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:f}}function Wc(r,a,e,t,i){var u,f,c,E,I,D,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][N.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(q=>q!==void 0);if(B.every(q=>typeof q==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else{const q=[];let S=!1;B.forEach(pe=>{var me,X,oe,gt;if(Array.isArray(pe)&&(S=!0),typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const ir=Yl(pe,a.project,{...e,id:m.UUID.uuid()},t,i);ir.hasCreated&&q.push((me=ir.changeSet)==null?void 0:me.self),s.push(...(X=ir.changeSet)==null?void 0:X.updated),l.push(...(oe=ir.changeSet)==null?void 0:oe.added),o.push(...(gt=ir.changeSet)==null?void 0:gt.removed)}});const Q=p(q);if(!Q.length&&!S){B.forEach(pe=>{const me={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,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},X=C(me,a.project);switch(X.setParent(a,t),X.initChildren(t),t==null||t.add(X,A.Added),X.addSelfToProject(t),typeof pe){case"string":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}});break}else Q.length===1&&!S?a.setEntity(Q[0]):B.forEach(pe=>{if(typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const me=Jc(Object.keys(pe),a.project);if(me){const X=aP(me||Q[0],a,t,Pt.OrDataTypeGroup);s.push(...X.updated),l.push(...X.added),o.push(...X.removed)}}else{const me={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(pe),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},X=C(me,a.project);X.setParent(a,t),X.initChildren(t),t==null||t.add(X,A.Added),X.addSelfToProject(t);const oe=Wc(pe,X,{...e,id:m.UUID.uuid()},t,i);s.push(...oe.updated),l.push(...oe.added),o.push(...oe.removed)}})}}else{const B=Yl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(f=B.changeSet)==null?void 0:f.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(E=B.changeSet)==null?void 0:E.removed);break}else{const B=Yl(r,a.project,{...e},t,i);a.setEntity((I=B.changeSet)==null?void 0:I.self),s.push(...(D=B.changeSet)==null?void 0:D.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 Yl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),f=Jc(u,a);if(f)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:f}};const c=i?e.name+" of "+i.name:e.name,I={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()},D=C(I,a);return D.setParent(a,t),D.initChildren(t),t==null||t.add(D,A.Added),D.addSelfToProject(t),l.push(D),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,extends:null,index:V,hidden:!1,private:!1,required:!0,parent:D.toReference()},B=C(G,a);B.setParent(D,t),B.initChildren(t),t==null||t.add(B,A.Added),B.addSelfToProject(t),l.push(B);const g=r[P],S={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,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:B.toReference()},Q=C(S,a);Q.setParent(B,t),Q.initChildren(t),t==null||t.add(Q,A.Added),Q.addSelfToProject(t),l.push(Q);const pe=Wc(g,Q,{...e,name:P,id:m.UUID.uuid()},t,i||D);s.push(...pe.updated),l.push(...pe.added),o.push(...pe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:D}}}function br(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,f;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((f=s.implements)==null?void 0:f.id)});if(l){const d=new Ye({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:O.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new Ye({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:O.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 f,c;return!!u.implements&&((f=u.implements)==null?void 0:f.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new Ye({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:O.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new Ye({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:O.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function bW(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Bc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function RW(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===nd.Implements||t.field===nd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function DW(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function OW(r,a){return r.static&&(r.properties.forEach(t=>{t.static&&t.metaSync({static:!1},a)}),r.metaSync({static:!1},a)),r}var oP=(r=>(r.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",r.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",r))(oP||{});function lP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s/g,"-")}}function dP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}if(t.includes("-")){const i=new Ye({id:r.id+"--string-value-must-not-have-dashes",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-dashes",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s|-/g,"_")}}function Cs(r,a){const e=$n(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=Cs(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function Sc(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||Cs(s,t).last?s:(Cs(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=Sc(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&&!ht.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(ot.includes(r.type))return;Ee(r).forEach(l=>{var d,u;const o=Sc(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&&!ht.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function uP(r,a,e=new Set){const t=sn(r),i=sn(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,...uP(u,a,e)])),[]);return p([...l,...o])}function La(r,a){const e=Cs(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function PW(r,a){return!!Cs(r,a).last}function wW(r){if(rt.includes(r.type))return r;if([...gi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return rt.includes(a.type)?a:null}return null}function zc(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 zc(e,t)}function Bt(r){if(Ya.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?Bt(a):null}}function Hl(r,a){const e=ja(r,a);if(!e)return null;if(Ya.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=ja(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?ja(e.parent,a):null;return t?Hl(t,a):null}}function pP(r){if(!r)return null;if(gi.includes(r.type))return r;const a=r.parent;return a?pP(a):null}function cP(r){if(!r)return null;if(dt.includes(r.type))return r;const a=r.parent;return a?cP(a):null}function fP(r){if(!r)return null;if(Fi.includes(r.type))return r;const a=r.parent;return a?fP(a):null}function CW(r){return r.type===n.VariableDeclaration?[r]:dt.includes(r.type)?[...r.inputs,...r.outputs||[]]:ot.includes(r.type)?r.outputs:kn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function VW(r){const a=sn(r),e=[],t=[];df.includes(r.type)&&e.push(...Yc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:gi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>La(l,s)?-1:0),t.sort((s,l)=>La(l,s)?-1:0),[...e,...t,...i]}function hP(r){return[...r].sort((a,e)=>La(e,a)?-1:0)}function BW(r){const a=hP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];La(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function Gt(r){const a=r.map(e=>Bt(e));return p(a)}function Yc(r){return dt.includes(r.type)?[...Gt(r.successCalls),...Gt(r.errorCalls)]:rt.includes(r.type)?Gt(r.calls):[]}function _W(r,a){return Yc(r).includes(a)}function Hc(r){return r.writesValues||[]}function MW(r,a){return Hc(r).includes(a)}function yP(r){var a;return it.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function NW(r){return r.writesValues}function mP(r=[]){return r.map(yP).filter(a=>!!a)}function Kl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>it.includes(a.type))}function vP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&it.includes(a.type))}function TP(r){return it.includes(r.type)?r:null}function EP(r){return r.writesValues.map(TP).filter(a=>!!a)}function IP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...EP(e)]:a,[])}function Ee(r){return r.type===n.Loop?p([...Ci(Gt(r.successCalls)),...Ci(Gt(r.errorCalls)),...r.body?Ee(r.body):[]]):dt.includes(r.type)?p([...Ci(Gt(r.successCalls)),...Ci(Gt(r.errorCalls))]):rt.includes(r.type)?p(Ci(Gt(r.calls))):[]}function LW(r){return dt.includes(r.type)?[...Ci(Gt(r.successCalls)),...Ci(Gt(r.errorCalls))]:rt.includes(r.type)?Ci(Gt(r.calls)):[]}function AP(r,a=new Set){return r.writesValues.filter(t=>it.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...He(i,a)],[])}function bP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>it.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...He(s,a)],[])}function He(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return vP(r.outputs).reduce((t,i)=>[...t,...He(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Ee(r).reduce((s,l)=>{const o=Bt(l);return[...s,...He(o||l,a)]},[]),...mP(r.inputs),...IP(r.outputs)].reduce((s,l)=>[...s,...He(l,a)],[]);if(kn.includes(r.type)){const e=Kl(r.inputs),i=Ee(r).reduce((s,l)=>{const o=Bt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Kl(r.inputs)],i=Ee(r).reduce((s,l)=>{const o=Bt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l)],[])}if(it.includes(r.type)){a.add(r.id);const t=Ee(r).reduce((i,s)=>{const l=Bt(s);return[...i,...He(l||s,a)]},[]);return[r,...t,...bP(r,a),...AP(r,a)]}return[]}function pi(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...sn(r).reduce((i,s)=>[...i,s,...pi(s,a)],[])])}function Ci(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Ee(e)],[])}function RP(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,...Kl(u.inputs),...Ci(Gt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Ci(Gt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Ci(Gt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function DP(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 dt.includes(r.type)?XP(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 jW(r){const a=RP(r.project);return DP(r,a)}function ja(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 Xl(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(ni.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,f=r,c=r,E=r,I=r,D=r,P=r,V=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(D.calledByEntry||[]).flatMap(g=>g),...(D.calledBySuccess||[]).flatMap(g=>g),...(D.calledByError||[]).flatMap(g=>g),...E.parent?[E.parent]:[]];Array.isArray(s.implements)?V.push(...s.implements.flatMap(g=>g)):c.implements&&V.push(c.implements),Array.isArray(s.extends)?V.push(...s.extends.flatMap(g=>g)):c.extends&&V.push(c.extends),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&V.push(...o.valueAsTypeList.flatMap(g=>g)),o.valueAsTypeSingle&&V.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(g=>g),...(I.inputsDeclarations||[]).flatMap(g=>g),...(t.outputs||[]).flatMap(g=>g),...(I.outputsDeclarations||[]).flatMap(g=>g),...(P.internalCalls||[]).flatMap(g=>g),...P.writesValues||[],...D.dataType?[D.dataType]:[],...d.body?[d.body]:[],...D.defaultValue?[D.defaultValue]:[],...(D.successCalls||[]).flatMap(g=>g),...(D.errorCalls||[]).flatMap(g=>g),...(s.properties||[]).flatMap(g=>g),...(s.methods||[]).flatMap(g=>g),...(s.abstractMethods||[]).flatMap(g=>g),...u.error?[u.error]:[],...u.process?[u.process]:[],...E.throws?[E.throws]:[],...(i.andChildrenGroup||[]).flatMap(g=>g),...(i.orChildrenGroup||[]).flatMap(g=>g),...(f.entities||[]).flatMap(g=>g),...(f.functions||[]).flatMap(g=>g),...(f.functionCalls||[]).flatMap(g=>g),...(f.events||[]).flatMap(g=>g),...(f.conditions||[]).flatMap(g=>g),...(f.operations||[]).flatMap(g=>g),...(f.loops||[]).flatMap(g=>g),...(f.variableDeclarations||[]).flatMap(g=>g),...(f.variableInstances||[]).flatMap(g=>g),...(f.searches||[]).flatMap(g=>g),...(f.projects||[]).flatMap(g=>g),...(l.calls||[]).flatMap(g=>g)];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(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(ni.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(G[q]=S)}),M.forEach(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(ni.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(B[q]=S)}),{upstream:G,downstream:B}}function UW(r,a){const e=[];if(gi.includes(r.type)){Ii(r).forEach(s=>{const l=Hl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=ja(s,a);return l?ew(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(it.includes(r.type)){const t=Ql(r);t&&e.push(t)}return p(e)}function $n(r){const a=[];if(gi.includes(r.type)){r.calledBy.forEach(i=>{const s=Bt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>Ql(i)).filter(i=>i!==null);a.push(...p(t))}if(it.includes(r.type)){const e=Ql(r);e&&a.push(e)}return p(a)}function Ii(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function OP(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=>j(t,a,e)),...r.outputs.flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.parent?j(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.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a):[],...r.writesValues.flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(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.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...(r.extends||[]).flatMap(t=>j(t,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.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>j(t,a,e)),...(r.implements||[]).flatMap(t=>j(t,a,e)),...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>j(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>j(t,a,e)),...r.entity?j(r.entity,a,e):[],...r.parent?j(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.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,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.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(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.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,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.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(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.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.parent?j(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.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?j(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>j(t,a,e)):[],...r.parent?j(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.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.body?j(r.body,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function kP(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=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function ZP(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=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e))]}function qP(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=>j(t,a,e)),...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.variableInstances||[]).flatMap(t=>j(t,a,e)),...(r.operations||[]).flatMap(t=>j(t,a,e)),...(r.conditions||[]).flatMap(t=>j(t,a,e)),...(r.functionCalls||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.loops||[]).flatMap(t=>j(t,a,e)),...(r.searches||[]).flatMap(t=>j(t,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.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(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.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function SP(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=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function zP(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=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function YP(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?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function HP(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=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function KP(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=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.parent?j(r.parent,a,e):[]]}function $i(){const r=new Set,a=cI.flatMap(e=>j(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 j(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&&(ni.includes(r.type)||$i().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return NP(r,a,e);case n.Operation:return xP(r,a,e);case n.Condition:return VP(r,a,e);case n.Loop:return FP(r,a,e);case n.Search:return zP(r,a,e);case n.GlobalEvent:return jP(r,a,e);case n.ReturnStatement:return SP(r,a,e);case n.ContinueStatement:return BP(r,a,e);case n.BreakStatement:return wP(r,a,e);case n.VariableDeclaration:return HP(r,a,e);case n.DefinitionEntity:return _P(r,a,e);case n.FunctionDeclaration:return LP(r,a,e);case n.Project:return qP(r,a,e);case n.ActionDescriptor:return OP(r,a,e);case n.ArgumentDeclaration:return PP(r,a,e);case n.ReturnDeclaration:return WP(r,a,e);case n.ValueDescriptor:return YP(r,a,e);case n.InputMap:return UP(r,a,e);case n.OutputMap:return kP(r,a,e);case n.DataType:return MP(r,a,e);case n.InstalledProject:return $P(r,a,e);case n.InternalCall:return GP(r,a,e);case n.LiteralValue:return gP(r,a,e);case n.Property:return JP(r,a,e);case n.VariableInstance:return KP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:CP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:ZP(r,a,e)}return[]}function Kc(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||kn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function $W(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 XP(r){return dt.includes(r.type)?r.inputs:[]}function QP(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:ot.includes(r.type)?r.outputs:[]}function GW(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 gW(r){return r.type===n.Condition?[]:dt.includes(r.type)?r.outputs:[]}function Ql(r){const a=r.readsValue;return a?Bt(a):null}function ew(r,a){const e=r.readsValue;return e?Hl(e,a):null}function tw(r){const a=r.internalCalls||[];return p(Gt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Vs(r){const a=Hc(r),e=[];return a.forEach(t=>{if(it.includes(t.type))e.push(t);else if(Dr.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 sn(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)||[]),ht.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?[]:sn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>Bt(s)),i=r.errorCalls.map(s=>Bt(s));e.push(...t,...i)}if(kn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Vs(s)).flat(),i=r.calls.map(s=>Bt(s));e.push(...p(t),...i)}if(dt.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Vs(l)).flat(),i=r.successCalls.map(l=>Bt(l)),s=r.errorCalls.map(l=>Bt(l));e.push(...p(t),...i,...s)}if(it.includes(r.type)){const t=Vs(r),i=tw(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Vs(l)).flat();if(r.body){const l=sn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>Bt(l)),s=r.successCalls.map(l=>Bt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Vs(s)).flat(),i=r.calls.map(s=>Bt(s));e.push(...p(t),...i)}return p(e)}function iw(r,a=!1){const e=sn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...iw(s,a)],[])];return p(t)}function rw(r){const a=$n(r),e=[...a,...a.reduce((t,i)=>[...t,...rw(i)],[])];return p(e)}function Ua(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Ua(e),...$a(e)]:[...a,e.name],[])}function $a(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...$a(e),...Ua(e)]:[...a,e.name],[])}function Xc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Xc(e),...Qc(e)]:[...a,e],[])}function Qc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Qc(e),...Xc(e)]:[...a,e],[])}function ef(r){return[...$a(r),...Ua(r)].filter((e,t,i)=>i.indexOf(e)===t)}function nw(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===W.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=nw(i);if(s)return s}return t},null)}function FW(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function xW(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function sw(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function Wt(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,...Wt(t)]:e,[]);return p(a)}function Ga(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!Wt(r).find(t=>!t.interactive)}function kW(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function tf(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 aw(r){if([...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r))return!1;const a=$n(r);return a.length===0?!0:a.some(e=>aw(e))}function rf(r){return[...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r)?!1:$n(r).length===0}function ow(r,a=0){if(rf(r)){const e=$n(r);return e.length===0?r:e.map(i=>ow(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function lw(r){const a=[];if(rf(r))a.push(r);else return[];return $n(r).forEach(t=>{a.push(...lw(t))}),a}function dw(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function ZW(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 ga(r){switch(r){case n.DefinitionEntity:return on;case n.FunctionDeclaration:return Fr;case n.VariableDeclaration:return zr;case n.VariableInstance:return Sr;case n.FunctionCall:return nn;case n.Operation:return kr;case n.Condition:return Wr;case n.ReturnStatement:return Zr;case n.Loop:return Jr;case n.Search:return Yr;case n.InputMap:return Xi;case n.OutputMap:return Qi;case n.ArgumentDeclaration:return Ir;case n.ReturnDeclaration:return ii;case n.Property:return gr;case n.InstalledProject:return Hr;case n.Project:return m;case n.DataType:return xr;case n.GlobalEvent:return qr;case n.InternalCall:return Kr;case n.ValueDescriptor:return er;case n.BuiltInBaseEntity:return Gi;case n.PrimitiveEntity:return ri;case n.ActionDescriptor:return We;case n.LiteralValue:return Xr;case n.ContinueStatement:return $t;case n.BreakStatement:return Qr;default:return null}}function St(r,a,e=null){const t=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.ReturnStatement)return It(r,a,s);if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return i;if(rt.includes(r.type))return r;if(r.type===n.Loop)return s.id===r.id?i:r;if(ni.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=_(l);if(!o)return null;const d=a.get(o);return d?St(d,a,s):null}else return l===a?a:St(l,a,s)}function It(r,a,e=null){const t=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return It(i.parent,a,s);if(rt.includes(r.type))return r;if(ni.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=_(l);if(!o)return null;const d=a.get(o);return d?It(d,a,s):null}else return l===a?a:It(l,a,s)}function nf(r,a){if(ni.includes(r.type)||a.getBuiltIn(r.id))return null;const e=Ai(r.parent,a);return e?e===a?ht.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:nf(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 Fa(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=zc(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 uw(r,a,e){const t=Fa(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 pw(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=uw(e,t,t.project);return!i||i===t?e:t},r[0])}function Ai(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 an(r){if(!r)return null;if(ni.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:an(a)}function xa(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=nf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Ee(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=xa(o);d.reachable||Ee(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Ee(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=xa(o);d.reachable||Ee(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Ee(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=Bt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=xa(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function qW(r){return Ya.includes(r.type)?r.type===n.FunctionDeclaration?!dw(r):!0:!1}function JW(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 id(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!$a(r).includes(a)}function WW(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Ua(r).includes(a)}function ka(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ef(r).includes(a)}function SW(r){const a=[];return r.entities.forEach(e=>{if(id(e,W.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function zW(r){const a=[];return r.entities.forEach(e=>{if(id(e,W.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function YW(r){return r.type!==n.DefinitionEntity||r.abstract||!id(r,W.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][W.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function HW(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!ka(r,W.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function KW(r){var e;if(!r||r.type!==n.DefinitionEntity||!ka(r,W.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][W.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(!pf.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 XW(r){switch(r){case n.Project:return m;case n.InstalledProject:return Hr;case n.DefinitionEntity:return on;case n.FunctionDeclaration:return Fr;case n.GlobalEvent:return qr;case n.VariableInstance:return Sr;case n.VariableDeclaration:return zr;case n.InputMap:return Xi;case n.OutputMap:return Qi;case n.Condition:return Wr;case n.Operation:return kr;case n.FunctionCall:return nn;case n.ReturnDeclaration:return ii;case n.ArgumentDeclaration:return Ir;case n.PrimitiveEntity:return ri;case n.DataType:return xr;case n.Property:return gr;case n.ActionDescriptor:return We;case n.ReturnStatement:return Zr;case n.ContinueStatement:return $t;case n.BreakStatement:return Qr;case n.Loop:return Jr;case n.Search:return Yr;case n.ValueDescriptor:return er;case n.InternalCall:return Kr;case n.LiteralValue:return Xr}return null}function QW(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=ga(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 rd(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,...rd(t,a)]:[]}function eS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=Bt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function tS(r){if(r.type===n.Condition)return null;if(r.type===n.Search)return r.project.getBuiltIn(k["value-descriptor"][Zn.SearchErrorOutputDescriptor].id)||null;if(r.type===n.Operation)return r.declaration.error;if(r.type===n.FunctionCall){const e=r.declaration.returnStatements.find(t=>!!t.throws);return(e==null?void 0:e.throws)||null}return null}function cw(r){const a=B7(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(f=>iS(r,f)),s=r.extends.flatMap(f=>rS(r,f)),l=sS(r),o=nS(r);r.methods.flatMap(f=>f.validate());const d=[...i,...s,...l,...o];return Ke(r.errors,d)}function fw(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 hw(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 iS(r,a){const e=[];if(!a.abstract){const f=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:O.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(f.error),e}const t=a.properties.filter(f=>f.abstract),i=[];let s=[...r.properties];t.forEach(f=>{const c=s.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===f.id});c?s=s.filter(E=>E.id!==c.id):i.push(f)}),i.length&&i.forEach(f=>{const c=de({id:r.id+"--"+F.MissingPropertyImplementation+"--"+f.id,message:`Property "${f.name}" with id "${f.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:O.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(f=>{const c=o.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===f.id});c?o=o.filter(E=>E.id!==c.id):l.push(f)}),l.length&&l.forEach(f=>{const c=de({id:r.id+"--"+F.MissingMethodImplementation+"--"+f.id,message:`Method "${f.name}" with id "${f.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:O.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(f=>{const c=s.find(E=>E.name===f.name);c&&d.push([c,f])}),d.length&&d.forEach(([f])=>{const c=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Property "${f.name}" with id "${f.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:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(f=>{const c=o.find(E=>E.name===f.name);c&&u.push([c,f])}),u.length&&u.forEach(([f])=>{const c=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Method "${f.name}" with id "${f.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:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function rS(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:O.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:O.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+"--"+$.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:O.Error,code:$.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+"--"+$.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:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function nS(r){const a=[];if(!r.properties.length){const e=de({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:O.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function sS(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:O.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:O.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:O.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:O.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:O.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:O.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:O.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:O.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function aS(r,a){const e=[],t=Wt(a);if(!a.abstract){const l=new Ye({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:O.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 Ye({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:O.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new Ye({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:O.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new Ye({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:O.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 Ye({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:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{Wt(l).forEach(f=>{const c=t.filter(E=>E.id!==f.id);c.length&&c.forEach(E=>{if(E.id!==f.id){const I=new Ye({id:r.id+"--"+E.id+"--"+f.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:f});e.push(I)}})});const d=br(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=br(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>Wt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new Ye({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:O.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function oS(r,a,e=!1){const t=[],i=Wt(a);if(!r.abstract&&a.abstract){const f=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:O.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.abstract&&!a.abstract){const f=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:O.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!r.static&&a.static){const f=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:O.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.static&&!a.static){const f=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:O.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!Ga(a)){const f=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:O.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(f.error)}const l=r.extends.filter(f=>f.id!==a.id);l.length&&l.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==f.id);c.length&&c.forEach(E=>{if(E.id!==f.id){const I=de({id:r.id+"--"+E.id+"--"+f.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${E.name}" with id "${E.id}" but also extends entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:f});t.push(I.error)}})}else{Wt(f).forEach(M=>{const G=i.filter(B=>B.id!==M.id);G.length&&G.forEach(B=>{if(B.id!==M.id){const g=new Ye({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:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push(g)}})});const E=!!Wt(f).find(M=>M.id===a.id);let I=[...f.properties];E&&(I=I.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 D=[...f.methods];E&&(D=D.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=br(a.ownDeclaredProperties,I,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const V=br(a.abstractMethods,D,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...V.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==f.id);c.length&&c.forEach(E=>{if(E.id!==f.id){const I=new Ye({id:r.id+"--"+E.id+"--"+f.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:f});t.push(I)}})}else{Wt(f).forEach(D=>{const P=i.filter(V=>V.id!==D.id);P.length&&P.forEach(V=>{if(V.id!==D.id){const M=new Ye({id:r.id+"--"+V.id+"--"+D.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 "${D.name}" with id "${D.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:V,secondRelationship:D});t.push(M)}})});const E=br(a.ownDeclaredProperties,f.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...E.errors);const I=br(a.abstractMethods,[...f.abstractMethods,...f.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...I.errors)}});const o=br(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=br(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(f=>Wt(f))).forEach(f=>{if(!i.find(c=>c.id===f.id)){const c=new Ye({id:r.id+"--"+a.id+"--"+f.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 "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:f});t.push(c)}}),t}function lS(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new Ye({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:O.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new Ye({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:O.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function dS(r){const a=[];if(r.implements.length){const e=new Ye({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:O.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new Ye({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:O.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function uS(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new Ye({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:O.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function pS(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new Ye({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:O.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const cS=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:hw,getBasePropertiesNotImplemented:fw,validate:cw,validateCanBecomeAbstract:dS,validateCanBecomeNonAbstract:pS,validateCanBecomeNonStatic:uS,validateCanBecomeStatic:lS,validateCanExtendEntity:oS,validateCanImplementEntity:aS},Symbol.toStringTag,{value:"Module"}));function fS(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:O.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:O.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:O.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:O.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:O.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:O.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:O.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}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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:O.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:O.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:O.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 nd=(r=>(r.Extends="extends",r.Implements="implements",r))(nd||{});const $e=class $e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"static");h(this,"abstract");h(this,"type",n.DefinitionEntity);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"implements",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestedProperties",[]);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=fS(i,t),o=bc(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:O.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.
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),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:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),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 Je(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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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 Je(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),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),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=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...E),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.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?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!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);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return 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=U,...t){return await Je.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Je.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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(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:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){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=J){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=iP(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 D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=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=st(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 E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-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 f;return u.id===((f=o.declaration)==null?void 0:f.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 f;return u.id===((f=o.declaration)==null?void 0:f.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(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const E={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()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),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(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const D=o.includes(E.index)?this.outputs.length-1+I:E.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:E.toJSON(),defaultValue:null,writesValues:[],index:D,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((E,I)=>E.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),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}}};h(Je,"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}),h(Je,"type",n.FunctionCall),h(Je,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Je,"PARENT_TYPES",[...Je.USER_MANAGED_PARENT_TYPES]),h(Je,"MUTABLE_BASE_PROPERTIES",[]),h(Je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Je,"BASE_PROPERTIES",[...Je.MUTABLE_BASE_PROPERTIES,...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"MUTABLE_META_PROPERTIES",["x","y"]),h(Je,"INMUTABLE_META_PROPERTIES",[...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"META_PROPERTIES",[...Je.MUTABLE_META_PROPERTIES,...Je.INMUTABLE_META_PROPERTIES]),h(Je,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Je,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Je,"UPSTREAM_PROPERTIES",[...Je.MUTABLE_UPSTREAM_PROPERTIES,...Je.INMUTABLE_UPSTREAM_PROPERTIES]),h(Je,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),h(Je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Je,"DOWNSTREAM_PROPERTIES",[...Je.MUTABLE_DOWNSTREAM_PROPERTIES,...Je.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Je,"PROPERTIES",[...Je.META_PROPERTIES,...Je.UPSTREAM_PROPERTIES,...Je.DOWNSTREAM_PROPERTIES]);let nn=Je;function qc(r){return r&&typeof r.then=="function"}class Sl{constructor(a){h(this,"order",[]);h(this,"flatRecord",{});h(this,"allBuiltInEntityIds",$i());h(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set($i()),t=p(j(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}=Xl(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}=Xl(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(Xl(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);qc(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);qc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function nP(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 f;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=u.getDefaultValue())==null?void 0:f.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),f=u==null?void 0:u.defaultValue;if(f)f.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:N.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},E=C(c,r.project);return E.setParent(u==null?void 0:u.dataType,a),E.initChildren(a),a==null||a.add(E,A.Added),E.addSelfToProject(a),{newEntities:[E]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=zl(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:N.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 sP(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let f=r.project.entities.filter(I=>I.implements.find(D=>D.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(I=>!!I.properties.find(D=>{var P;return D.implements&&D.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=D.getDefaultValue())==null?void 0:P.value)===!0}));if(!f){f=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const D=f.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=D==null?void 0:D.defaultValue)==null||d.metaSync({value:!0},a),t.push(f)}const c=r.properties.find(I=>I.implements&&I.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),E=c==null?void 0:c.defaultValue;if(c&&!E){const I={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:N.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:f,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},D=C(I,r.project);D.hydrateAncestors(),D.setParent(c,a),D.addSelfToProject(a),D.initChildren(a),a==null||a.add(D,A.Added),t.push(D);return}else E&&E.setValueAsTypeSingle(f,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function zl(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.toJSON()],x:0,y:0,parent:r.project.toReference()};nP(r,e);const o=C(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,A.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),sP(o,e),o}function Jc(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 aP(r,a,e,t=Pt.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,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},f=C(u,r.project);return s.push(f),f.setParent(a,e),f.initChildren(e),e==null||e.add(f,A.Added),f.setEntity(r),f.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:f}}function Wc(r,a,e,t,i){var u,f,c,E,I,D,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][N.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(q=>q!==void 0);if(B.every(q=>typeof q==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else{const q=[];let S=!1;B.forEach(pe=>{var me,X,oe,gt;if(Array.isArray(pe)&&(S=!0),typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const ir=Yl(pe,a.project,{...e,id:m.UUID.uuid()},t,i);ir.hasCreated&&q.push((me=ir.changeSet)==null?void 0:me.self),s.push(...(X=ir.changeSet)==null?void 0:X.updated),l.push(...(oe=ir.changeSet)==null?void 0:oe.added),o.push(...(gt=ir.changeSet)==null?void 0:gt.removed)}});const Q=p(q);if(!Q.length&&!S){B.forEach(pe=>{const me={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,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},X=C(me,a.project);switch(X.setParent(a,t),X.initChildren(t),t==null||t.add(X,A.Added),X.addSelfToProject(t),typeof pe){case"string":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}});break}else Q.length===1&&!S?a.setEntity(Q[0]):B.forEach(pe=>{if(typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const me=Jc(Object.keys(pe),a.project);if(me){const X=aP(me||Q[0],a,t,Pt.OrDataTypeGroup);s.push(...X.updated),l.push(...X.added),o.push(...X.removed)}}else{const me={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(pe),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},X=C(me,a.project);X.setParent(a,t),X.initChildren(t),t==null||t.add(X,A.Added),X.addSelfToProject(t);const oe=Wc(pe,X,{...e,id:m.UUID.uuid()},t,i);s.push(...oe.updated),l.push(...oe.added),o.push(...oe.removed)}})}}else{const B=Yl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(f=B.changeSet)==null?void 0:f.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(E=B.changeSet)==null?void 0:E.removed);break}else{const B=Yl(r,a.project,{...e},t,i);a.setEntity((I=B.changeSet)==null?void 0:I.self),s.push(...(D=B.changeSet)==null?void 0:D.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 Yl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),f=Jc(u,a);if(f)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:f}};const c=i?e.name+" of "+i.name:e.name,I={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()},D=C(I,a);return D.setParent(a,t),D.initChildren(t),t==null||t.add(D,A.Added),D.addSelfToProject(t),l.push(D),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,extends:null,index:V,hidden:!1,private:!1,required:!0,parent:D.toReference()},B=C(G,a);B.setParent(D,t),B.initChildren(t),t==null||t.add(B,A.Added),B.addSelfToProject(t),l.push(B);const g=r[P],S={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,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:B.toReference()},Q=C(S,a);Q.setParent(B,t),Q.initChildren(t),t==null||t.add(Q,A.Added),Q.addSelfToProject(t),l.push(Q);const pe=Wc(g,Q,{...e,name:P,id:m.UUID.uuid()},t,i||D);s.push(...pe.updated),l.push(...pe.added),o.push(...pe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:D}}}function br(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,f;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((f=s.implements)==null?void 0:f.id)});if(l){const d=new Ye({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:O.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new Ye({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:O.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 f,c;return!!u.implements&&((f=u.implements)==null?void 0:f.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new Ye({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:O.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new Ye({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:O.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function bW(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Bc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function RW(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===nd.Implements||t.field===nd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function DW(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function OW(r,a){return r.static&&r.metaSync({static:!1},a),r}var oP=(r=>(r.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",r.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",r))(oP||{});function lP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s/g,"-")}}function dP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}if(t.includes("-")){const i=new Ye({id:r.id+"--string-value-must-not-have-dashes",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-dashes",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s|-/g,"_")}}function Cs(r,a){const e=$n(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=Cs(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function Sc(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||Cs(s,t).last?s:(Cs(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=Sc(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&&!ht.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(ot.includes(r.type))return;Ee(r).forEach(l=>{var d,u;const o=Sc(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&&!ht.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function uP(r,a,e=new Set){const t=sn(r),i=sn(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,...uP(u,a,e)])),[]);return p([...l,...o])}function La(r,a){const e=Cs(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function PW(r,a){return!!Cs(r,a).last}function wW(r){if(rt.includes(r.type))return r;if([...gi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return rt.includes(a.type)?a:null}return null}function zc(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 zc(e,t)}function Bt(r){if(Ya.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?Bt(a):null}}function Hl(r,a){const e=ja(r,a);if(!e)return null;if(Ya.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=ja(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?ja(e.parent,a):null;return t?Hl(t,a):null}}function pP(r){if(!r)return null;if(gi.includes(r.type))return r;const a=r.parent;return a?pP(a):null}function cP(r){if(!r)return null;if(dt.includes(r.type))return r;const a=r.parent;return a?cP(a):null}function fP(r){if(!r)return null;if(Fi.includes(r.type))return r;const a=r.parent;return a?fP(a):null}function CW(r){return r.type===n.VariableDeclaration?[r]:dt.includes(r.type)?[...r.inputs,...r.outputs||[]]:ot.includes(r.type)?r.outputs:kn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function VW(r){const a=sn(r),e=[],t=[];df.includes(r.type)&&e.push(...Yc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:gi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>La(l,s)?-1:0),t.sort((s,l)=>La(l,s)?-1:0),[...e,...t,...i]}function hP(r){return[...r].sort((a,e)=>La(e,a)?-1:0)}function BW(r){const a=hP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];La(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function Gt(r){const a=r.map(e=>Bt(e));return p(a)}function Yc(r){return dt.includes(r.type)?[...Gt(r.successCalls),...Gt(r.errorCalls)]:rt.includes(r.type)?Gt(r.calls):[]}function _W(r,a){return Yc(r).includes(a)}function Hc(r){return r.writesValues||[]}function MW(r,a){return Hc(r).includes(a)}function yP(r){var a;return it.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function NW(r){return r.writesValues}function mP(r=[]){return r.map(yP).filter(a=>!!a)}function Kl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>it.includes(a.type))}function vP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&it.includes(a.type))}function TP(r){return it.includes(r.type)?r:null}function EP(r){return r.writesValues.map(TP).filter(a=>!!a)}function IP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...EP(e)]:a,[])}function Ee(r){return r.type===n.Loop?p([...Ci(Gt(r.successCalls)),...Ci(Gt(r.errorCalls)),...r.body?Ee(r.body):[]]):dt.includes(r.type)?p([...Ci(Gt(r.successCalls)),...Ci(Gt(r.errorCalls))]):rt.includes(r.type)?p(Ci(Gt(r.calls))):[]}function LW(r){return dt.includes(r.type)?[...Ci(Gt(r.successCalls)),...Ci(Gt(r.errorCalls))]:rt.includes(r.type)?Ci(Gt(r.calls)):[]}function AP(r,a=new Set){return r.writesValues.filter(t=>it.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...He(i,a)],[])}function bP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>it.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...He(s,a)],[])}function He(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return vP(r.outputs).reduce((t,i)=>[...t,...He(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Ee(r).reduce((s,l)=>{const o=Bt(l);return[...s,...He(o||l,a)]},[]),...mP(r.inputs),...IP(r.outputs)].reduce((s,l)=>[...s,...He(l,a)],[]);if(kn.includes(r.type)){const e=Kl(r.inputs),i=Ee(r).reduce((s,l)=>{const o=Bt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Kl(r.inputs)],i=Ee(r).reduce((s,l)=>{const o=Bt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l)],[])}if(it.includes(r.type)){a.add(r.id);const t=Ee(r).reduce((i,s)=>{const l=Bt(s);return[...i,...He(l||s,a)]},[]);return[r,...t,...bP(r,a),...AP(r,a)]}return[]}function pi(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...sn(r).reduce((i,s)=>[...i,s,...pi(s,a)],[])])}function Ci(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Ee(e)],[])}function RP(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,...Kl(u.inputs),...Ci(Gt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Ci(Gt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Ci(Gt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function DP(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 dt.includes(r.type)?XP(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 jW(r){const a=RP(r.project);return DP(r,a)}function ja(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 Xl(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(ni.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,f=r,c=r,E=r,I=r,D=r,P=r,V=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(D.calledByEntry||[]).flatMap(g=>g),...(D.calledBySuccess||[]).flatMap(g=>g),...(D.calledByError||[]).flatMap(g=>g),...E.parent?[E.parent]:[]];Array.isArray(s.implements)?V.push(...s.implements.flatMap(g=>g)):c.implements&&V.push(c.implements),Array.isArray(s.extends)?V.push(...s.extends.flatMap(g=>g)):c.extends&&V.push(c.extends),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&V.push(...o.valueAsTypeList.flatMap(g=>g)),o.valueAsTypeSingle&&V.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(g=>g),...(I.inputsDeclarations||[]).flatMap(g=>g),...(t.outputs||[]).flatMap(g=>g),...(I.outputsDeclarations||[]).flatMap(g=>g),...(P.internalCalls||[]).flatMap(g=>g),...P.writesValues||[],...D.dataType?[D.dataType]:[],...d.body?[d.body]:[],...D.defaultValue?[D.defaultValue]:[],...(D.successCalls||[]).flatMap(g=>g),...(D.errorCalls||[]).flatMap(g=>g),...(s.properties||[]).flatMap(g=>g),...(s.methods||[]).flatMap(g=>g),...(s.abstractMethods||[]).flatMap(g=>g),...u.error?[u.error]:[],...u.process?[u.process]:[],...E.throws?[E.throws]:[],...(i.andChildrenGroup||[]).flatMap(g=>g),...(i.orChildrenGroup||[]).flatMap(g=>g),...(f.entities||[]).flatMap(g=>g),...(f.functions||[]).flatMap(g=>g),...(f.functionCalls||[]).flatMap(g=>g),...(f.events||[]).flatMap(g=>g),...(f.conditions||[]).flatMap(g=>g),...(f.operations||[]).flatMap(g=>g),...(f.loops||[]).flatMap(g=>g),...(f.variableDeclarations||[]).flatMap(g=>g),...(f.variableInstances||[]).flatMap(g=>g),...(f.searches||[]).flatMap(g=>g),...(f.projects||[]).flatMap(g=>g),...(l.calls||[]).flatMap(g=>g)];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(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(ni.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(G[q]=S)}),M.forEach(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(ni.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(B[q]=S)}),{upstream:G,downstream:B}}function UW(r,a){const e=[];if(gi.includes(r.type)){Ii(r).forEach(s=>{const l=Hl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=ja(s,a);return l?ew(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(it.includes(r.type)){const t=Ql(r);t&&e.push(t)}return p(e)}function $n(r){const a=[];if(gi.includes(r.type)){r.calledBy.forEach(i=>{const s=Bt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>Ql(i)).filter(i=>i!==null);a.push(...p(t))}if(it.includes(r.type)){const e=Ql(r);e&&a.push(e)}return p(a)}function Ii(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function OP(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=>j(t,a,e)),...r.outputs.flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.parent?j(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.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a):[],...r.writesValues.flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(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.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...(r.extends||[]).flatMap(t=>j(t,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.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>j(t,a,e)),...(r.implements||[]).flatMap(t=>j(t,a,e)),...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>j(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>j(t,a,e)),...r.entity?j(r.entity,a,e):[],...r.parent?j(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.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,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.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(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.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,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.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(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.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.parent?j(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.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?j(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>j(t,a,e)):[],...r.parent?j(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.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.body?j(r.body,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(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.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function kP(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=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function ZP(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=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e))]}function qP(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=>j(t,a,e)),...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.variableInstances||[]).flatMap(t=>j(t,a,e)),...(r.operations||[]).flatMap(t=>j(t,a,e)),...(r.conditions||[]).flatMap(t=>j(t,a,e)),...(r.functionCalls||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.loops||[]).flatMap(t=>j(t,a,e)),...(r.searches||[]).flatMap(t=>j(t,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.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(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.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function SP(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=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function zP(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=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function YP(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?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function HP(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=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function KP(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=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.parent?j(r.parent,a,e):[]]}function $i(){const r=new Set,a=cI.flatMap(e=>j(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 j(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&&(ni.includes(r.type)||$i().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return NP(r,a,e);case n.Operation:return xP(r,a,e);case n.Condition:return VP(r,a,e);case n.Loop:return FP(r,a,e);case n.Search:return zP(r,a,e);case n.GlobalEvent:return jP(r,a,e);case n.ReturnStatement:return SP(r,a,e);case n.ContinueStatement:return BP(r,a,e);case n.BreakStatement:return wP(r,a,e);case n.VariableDeclaration:return HP(r,a,e);case n.DefinitionEntity:return _P(r,a,e);case n.FunctionDeclaration:return LP(r,a,e);case n.Project:return qP(r,a,e);case n.ActionDescriptor:return OP(r,a,e);case n.ArgumentDeclaration:return PP(r,a,e);case n.ReturnDeclaration:return WP(r,a,e);case n.ValueDescriptor:return YP(r,a,e);case n.InputMap:return UP(r,a,e);case n.OutputMap:return kP(r,a,e);case n.DataType:return MP(r,a,e);case n.InstalledProject:return $P(r,a,e);case n.InternalCall:return GP(r,a,e);case n.LiteralValue:return gP(r,a,e);case n.Property:return JP(r,a,e);case n.VariableInstance:return KP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:CP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:ZP(r,a,e)}return[]}function Kc(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||kn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function $W(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 XP(r){return dt.includes(r.type)?r.inputs:[]}function QP(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:ot.includes(r.type)?r.outputs:[]}function GW(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 gW(r){return r.type===n.Condition?[]:dt.includes(r.type)?r.outputs:[]}function Ql(r){const a=r.readsValue;return a?Bt(a):null}function ew(r,a){const e=r.readsValue;return e?Hl(e,a):null}function tw(r){const a=r.internalCalls||[];return p(Gt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Vs(r){const a=Hc(r),e=[];return a.forEach(t=>{if(it.includes(t.type))e.push(t);else if(Dr.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 sn(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)||[]),ht.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?[]:sn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>Bt(s)),i=r.errorCalls.map(s=>Bt(s));e.push(...t,...i)}if(kn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Vs(s)).flat(),i=r.calls.map(s=>Bt(s));e.push(...p(t),...i)}if(dt.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Vs(l)).flat(),i=r.successCalls.map(l=>Bt(l)),s=r.errorCalls.map(l=>Bt(l));e.push(...p(t),...i,...s)}if(it.includes(r.type)){const t=Vs(r),i=tw(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Vs(l)).flat();if(r.body){const l=sn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>Bt(l)),s=r.successCalls.map(l=>Bt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Vs(s)).flat(),i=r.calls.map(s=>Bt(s));e.push(...p(t),...i)}return p(e)}function iw(r,a=!1){const e=sn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...iw(s,a)],[])];return p(t)}function rw(r){const a=$n(r),e=[...a,...a.reduce((t,i)=>[...t,...rw(i)],[])];return p(e)}function Ua(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Ua(e),...$a(e)]:[...a,e.name],[])}function $a(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...$a(e),...Ua(e)]:[...a,e.name],[])}function Xc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Xc(e),...Qc(e)]:[...a,e],[])}function Qc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Qc(e),...Xc(e)]:[...a,e],[])}function ef(r){return[...$a(r),...Ua(r)].filter((e,t,i)=>i.indexOf(e)===t)}function nw(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===W.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=nw(i);if(s)return s}return t},null)}function FW(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function xW(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function sw(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function Wt(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,...Wt(t)]:e,[]);return p(a)}function Ga(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!Wt(r).find(t=>!t.interactive)}function kW(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function tf(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 aw(r){if([...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r))return!1;const a=$n(r);return a.length===0?!0:a.some(e=>aw(e))}function rf(r){return[...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r)?!1:$n(r).length===0}function ow(r,a=0){if(rf(r)){const e=$n(r);return e.length===0?r:e.map(i=>ow(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function lw(r){const a=[];if(rf(r))a.push(r);else return[];return $n(r).forEach(t=>{a.push(...lw(t))}),a}function dw(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function ZW(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 ga(r){switch(r){case n.DefinitionEntity:return on;case n.FunctionDeclaration:return Fr;case n.VariableDeclaration:return zr;case n.VariableInstance:return Sr;case n.FunctionCall:return nn;case n.Operation:return kr;case n.Condition:return Wr;case n.ReturnStatement:return Zr;case n.Loop:return Jr;case n.Search:return Yr;case n.InputMap:return Xi;case n.OutputMap:return Qi;case n.ArgumentDeclaration:return Ir;case n.ReturnDeclaration:return ii;case n.Property:return gr;case n.InstalledProject:return Hr;case n.Project:return m;case n.DataType:return xr;case n.GlobalEvent:return qr;case n.InternalCall:return Kr;case n.ValueDescriptor:return er;case n.BuiltInBaseEntity:return Gi;case n.PrimitiveEntity:return ri;case n.ActionDescriptor:return We;case n.LiteralValue:return Xr;case n.ContinueStatement:return $t;case n.BreakStatement:return Qr;default:return null}}function St(r,a,e=null){const t=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.ReturnStatement)return It(r,a,s);if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return i;if(rt.includes(r.type))return r;if(r.type===n.Loop)return s.id===r.id?i:r;if(ni.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=_(l);if(!o)return null;const d=a.get(o);return d?St(d,a,s):null}else return l===a?a:St(l,a,s)}function It(r,a,e=null){const t=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return It(i.parent,a,s);if(rt.includes(r.type))return r;if(ni.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=_(l);if(!o)return null;const d=a.get(o);return d?It(d,a,s):null}else return l===a?a:It(l,a,s)}function nf(r,a){if(ni.includes(r.type)||a.getBuiltIn(r.id))return null;const e=Ai(r.parent,a);return e?e===a?ht.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:nf(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 Fa(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=zc(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 uw(r,a,e){const t=Fa(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 pw(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=uw(e,t,t.project);return!i||i===t?e:t},r[0])}function Ai(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 an(r){if(!r)return null;if(ni.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:an(a)}function xa(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=nf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Ee(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=xa(o);d.reachable||Ee(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Ee(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=xa(o);d.reachable||Ee(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Ee(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=Bt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=xa(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function qW(r){return Ya.includes(r.type)?r.type===n.FunctionDeclaration?!dw(r):!0:!1}function JW(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 id(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!$a(r).includes(a)}function WW(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Ua(r).includes(a)}function ka(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ef(r).includes(a)}function SW(r){const a=[];return r.entities.forEach(e=>{if(id(e,W.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function zW(r){const a=[];return r.entities.forEach(e=>{if(id(e,W.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function YW(r){return r.type!==n.DefinitionEntity||r.abstract||!id(r,W.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][W.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function HW(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!ka(r,W.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function KW(r){var e;if(!r||r.type!==n.DefinitionEntity||!ka(r,W.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][W.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(!pf.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 XW(r){switch(r){case n.Project:return m;case n.InstalledProject:return Hr;case n.DefinitionEntity:return on;case n.FunctionDeclaration:return Fr;case n.GlobalEvent:return qr;case n.VariableInstance:return Sr;case n.VariableDeclaration:return zr;case n.InputMap:return Xi;case n.OutputMap:return Qi;case n.Condition:return Wr;case n.Operation:return kr;case n.FunctionCall:return nn;case n.ReturnDeclaration:return ii;case n.ArgumentDeclaration:return Ir;case n.PrimitiveEntity:return ri;case n.DataType:return xr;case n.Property:return gr;case n.ActionDescriptor:return We;case n.ReturnStatement:return Zr;case n.ContinueStatement:return $t;case n.BreakStatement:return Qr;case n.Loop:return Jr;case n.Search:return Yr;case n.ValueDescriptor:return er;case n.InternalCall:return Kr;case n.LiteralValue:return Xr}return null}function QW(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=ga(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 rd(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,...rd(t,a)]:[]}function eS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=Bt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function tS(r){if(r.type===n.Condition)return null;if(r.type===n.Search)return r.project.getBuiltIn(k["value-descriptor"][Zn.SearchErrorOutputDescriptor].id)||null;if(r.type===n.Operation)return r.declaration.error;if(r.type===n.FunctionCall){const e=r.declaration.returnStatements.find(t=>!!t.throws);return(e==null?void 0:e.throws)||null}return null}function cw(r){const a=B7(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(f=>iS(r,f)),s=r.extends.flatMap(f=>rS(r,f)),l=sS(r),o=nS(r);r.methods.flatMap(f=>f.validate());const d=[...i,...s,...l,...o];return Ke(r.errors,d)}function fw(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 hw(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 iS(r,a){const e=[];if(!a.abstract){const f=ue({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:O.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(f.error),e}const t=a.properties.filter(f=>f.abstract),i=[];let s=[...r.properties];t.forEach(f=>{const c=s.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===f.id});c?s=s.filter(E=>E.id!==c.id):i.push(f)}),i.length&&i.forEach(f=>{const c=ue({id:r.id+"--"+F.MissingPropertyImplementation+"--"+f.id,message:`Property "${f.name}" with id "${f.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:O.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(f=>{const c=o.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===f.id});c?o=o.filter(E=>E.id!==c.id):l.push(f)}),l.length&&l.forEach(f=>{const c=ue({id:r.id+"--"+F.MissingMethodImplementation+"--"+f.id,message:`Method "${f.name}" with id "${f.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:O.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(f=>{const c=s.find(E=>E.name===f.name);c&&d.push([c,f])}),d.length&&d.forEach(([f])=>{const c=ue({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Property "${f.name}" with id "${f.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:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(f=>{const c=o.find(E=>E.name===f.name);c&&u.push([c,f])}),u.length&&u.forEach(([f])=>{const c=ue({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Method "${f.name}" with id "${f.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:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function rS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=ue({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:O.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=ue({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:O.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=>{var u;return d.name===s.name&&((u=s.extends)==null?void 0:u.id)!==d.id});((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=ue({id:r.id+"--"+$.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:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>{var u;return d.name===s.name&&((u=s.extends)==null?void 0:u.id)!==d.id});((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=ue({id:r.id+"--"+$.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:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function nS(r){const a=[];if(!r.properties.length){const e=ue({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:O.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function sS(r){const a=[];if(r.abstract){if(r.methods.length){const e=ue({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:O.Error,code:F.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=ue({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:O.Error,code:F.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=ue({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:O.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=ue({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:O.Error,code:F.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}if(r.properties.some(e=>e.abstract)){const e=ue({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:O.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(e.error),r.properties.forEach(t=>{if(t.abstract){const i=ue({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:O.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(i.error)}})}}if(r.static&&r.properties.some(e=>!e.static)){const e=ue({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:O.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.static){const i=ue({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:O.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function aS(r,a){const e=[],t=Wt(a);if(!a.abstract){const l=new Ye({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:O.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 Ye({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:O.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new Ye({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:O.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new Ye({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:O.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 Ye({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:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{Wt(l).forEach(f=>{const c=t.filter(E=>E.id!==f.id);c.length&&c.forEach(E=>{if(E.id!==f.id){const I=new Ye({id:r.id+"--"+E.id+"--"+f.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:f});e.push(I)}})});const d=br(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=br(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>Wt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new Ye({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:O.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function oS(r,a,e=!1){const t=[],i=Wt(a);if(!r.abstract&&a.abstract){const f=ue({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:O.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.abstract&&!a.abstract){const f=ue({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:O.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!r.static&&a.static){const f=ue({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:O.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.static&&!a.static){const f=ue({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:O.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!Ga(a)){const f=ue({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:O.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(f.error)}const l=r.extends.filter(f=>f.id!==a.id);l.length&&l.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==f.id);c.length&&c.forEach(E=>{if(E.id!==f.id){const I=ue({id:r.id+"--"+E.id+"--"+f.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${E.name}" with id "${E.id}" but also extends entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:f});t.push(I.error)}})}else{Wt(f).forEach(M=>{const G=i.filter(B=>B.id!==M.id);G.length&&G.forEach(B=>{if(B.id!==M.id){const g=new Ye({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:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push(g)}})});const E=!!Wt(f).find(M=>M.id===a.id);let I=[...f.properties];E&&(I=I.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 D=[...f.methods];E&&(D=D.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=br(a.ownDeclaredProperties,I,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const V=br(a.abstractMethods,D,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...V.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==f.id);c.length&&c.forEach(E=>{if(E.id!==f.id){const I=new Ye({id:r.id+"--"+E.id+"--"+f.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:f});t.push(I)}})}else{Wt(f).forEach(D=>{const P=i.filter(V=>V.id!==D.id);P.length&&P.forEach(V=>{if(V.id!==D.id){const M=new Ye({id:r.id+"--"+V.id+"--"+D.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 "${D.name}" with id "${D.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:V,secondRelationship:D});t.push(M)}})});const E=br(a.ownDeclaredProperties,f.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...E.errors);const I=br(a.abstractMethods,[...f.abstractMethods,...f.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...I.errors)}});const o=br(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=br(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(f=>Wt(f))).forEach(f=>{if(!i.find(c=>c.id===f.id)){const c=new Ye({id:r.id+"--"+a.id+"--"+f.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 "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:f});t.push(c)}}),t}function lS(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new Ye({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:O.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new Ye({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:O.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function dS(r){const a=[];if(r.implements.length){const e=new Ye({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:O.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new Ye({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:O.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function uS(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new Ye({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:O.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function pS(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new Ye({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:O.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const cS=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:hw,getBasePropertiesNotImplemented:fw,validate:cw,validateCanBecomeAbstract:dS,validateCanBecomeNonAbstract:pS,validateCanBecomeNonStatic:uS,validateCanBecomeStatic:lS,validateCanExtendEntity:oS,validateCanImplementEntity:aS},Symbol.toStringTag,{value:"Module"}));function fS(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:O.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:O.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:O.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:O.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:O.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:O.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:O.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}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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:O.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:O.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:O.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 nd=(r=>(r.Extends="extends",r.Implements="implements",r))(nd||{});const $e=class $e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"static");h(this,"abstract");h(this,"type",n.DefinitionEntity);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"implements",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestedProperties",[]);h(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(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.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=fS(i,t),o=bc(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:O.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
  ${tr({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 allBaseMethodsFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>t.type!==n.DefinitionEntity?[]:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[]),...this.implements.reduce((e,t)=>t.type!==n.DefinitionEntity?t.abstractMethods:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...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 extendedMethodsFromOriginalParents(){return p(this.extends.reduce((e,t)=>{if(t.type!==n.DefinitionEntity)return[];const i=[...t.ownDeclaredMethods,...t.extendedMethodsFromOriginalParents].filter(s=>s.type!==n.ActionDescriptor);return[...e,...i]},[]))}get implementedMethodsFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.type===n.DefinitionEntity?t.methods:[],s=[...t.abstractMethods].filter(l=>!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>[...t.abstractMethods,...e],[])].filter(e=>e.type===n.ActionDescriptor))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}get extendedMethods(){return this.methods.filter(e=>e.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(e=>!e.isExtendedMethod)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){return this.implements.forEach(e=>{ni.includes(e.type)||e.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(e=>{ni.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{ni.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 $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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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;const{updated:o,added:d,removed:u,affected:f}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...f);const{updated:c,added:E,removed:I,affected:D}=this.addExtendedProperties(e);t.push(...c),i.push(...E),s.push(...I),l.push(...D);const{updated:P,added:V,removed:M}=this.removeUnrecognizedProperties(e);t.push(...P),i.push(...V),s.push(...M);const{updated:G,added:B,removed:g,affected:q}=this.syncImplementationMethods(e);t.push(...G),i.push(...B),s.push(...g),l.push(...q);const{updated:S,added:Q,removed:pe,affected:me}=this.addExtendedMethods(e);t.push(...S),i.push(...Q),s.push(...pe),l.push(...me);const{updated:X,added:oe,removed:gt}=this.removeUnrecognizedMethods(e);return t.push(...X),i.push(...oe),s.push(...gt),this.addSuggestions(),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=[];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)}removeUnrecognizedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-properties"))){const t=[],i=[],s=[],l=[];let o=[...this.properties];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedProperty);const d=this.implementedPropertiesFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-methods"))){const t=[],i=[],s=[],l=[];let o=[...this.methods];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedMethod);const d=this.implementedMethodsFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,d=this.implementedMethodsFromOriginalParents,u=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})).forEach(c=>{if(this.methods.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===c.id}))return;const I=this.methods.find(P=>{var g,q;if(P.name===c.name&&!P.implements)return!0;const V=ka(this,W.CRON_JOB),M=ka(this,W.HTTP_ENDPOINT),G=((g=P.implements)==null?void 0:g.id)===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,B=((q=P.implements)==null?void 0:q.id)===k["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(V&&!B&&!M&&G||M&&!G&&!V&&B)});if(I&&I.type===n.FunctionDeclaration){I.setImplements(c),I.metaSync({name:c.name},e),e==null||e.add(I,A.Updated),e==null||e.add(this,A.Updated);return}const D=c.implementAsFunctionDeclaration(e,this);i.push(D),e==null||e.add(D,A.Added),this.addMethod(D)}),e==null||e.attemptAutoclose("sync-implementation-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self: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(I=>{var D;return((D=I.implements)==null?void 0:D.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 I=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(I){I.implements=c,I.abstract=!1;return}const D=c.clone(e,this,m.UUID.uuid());D.initChildren(e),i.push(D),e==null||e.add(D,A.Added),D.setImplements(c,e),D.metaSync({abstract:!1},e),this.addProperty(D)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,u=this.extendedMethodsFromOriginalParents.filter(c=>c.type===n.FunctionDeclaration),f=new Set(o.filter(c=>{var E;return!!((E=c.extends)!=null&&E.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const E=c.clone(e,this,m.UUID.uuid());E.setExtends(c,e),E.initChildren(e),i.push(E),e==null||e.add(E,A.Added),this.addMethod(E)}),e==null||e.attemptAutoclose("add-extended-methods",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(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})?!1:!c.abstract),f=new Set(o.filter(c=>{var E;return!!((E=c.extends)!=null&&E.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const E=c.clone(e,this,m.UUID.uuid());E.setExtends(c,e),E.initChildren(e),i.push(E),e==null||e.add(E,A.Added),this.addProperty(E)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{fw(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)}),hw(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(f=>{f.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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await $e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await $e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await $e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await $e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await $e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.methods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),!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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){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||yt(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=J){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=J){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=cw(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"),f=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=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const E=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=E;const I=(V=this.methods)==null?void 0:V.map((G,B)=>G.clone(e,c,f+"-method-"+B+"-id",s));c.methods=I;const D=(M=this.abstractMethods)==null?void 0:M.map((G,B)=>G.clone(e,c,f+"-abstract-method-"+B+"-id",s));return c.abstractMethods=D,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=zl(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(I=>x(I,this.project)===x(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const E=u.find(B=>x(B,this.project)===x(c,this.project));if(!E)return;const D=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=Ui(D,t),V=P==null?void 0:P.clone(t,E,m.UUID.uuid(),!0);if(V){const B=(M=E.dataType)==null?void 0:M.merge(V,t);E.dataType&&(B==null?void 0:B.self.id)!==E.dataType.id&&E.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),E.setDataType(B.self),t==null||t.add(E,A.Updated))}c.setDeclaration(E),t==null||t.add(c,A.Updated)});const f=[];return d.forEach(c=>{if(!c.declaration){f.push(c);return}}),f.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(f.forEach(c=>{var B,g,q,S;const E=this.properties.find(Q=>x(Q,this.project)===x(c,this.project));if(E){if(c.setDeclaration(E),!E.getDataType(t)){const pe=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),me=Ui(pe),X=me==null?void 0:me.clone(t,E,m.UUID.uuid(),!0);if(X){const oe=(B=E.dataType)==null?void 0:B.merge(X,t);E.dataType&&(oe==null?void 0:oe.self.id)!==E.dataType.id&&E.dataType.remove({ignoreUpstream:!1},t),X.id!==((g=oe==null?void 0:oe.self)==null?void 0:g.id)&&X.remove({ignoreUpstream:!1},t),oe!=null&&oe.self&&(oe.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(oe.self,A.Added),E.setDataType(oe.self),t==null||t.add(E,A.Updated))}}return}const I={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,extends:null,dataType:null,parent:this.toReference()},D=C(I,this.project);D.setParent(this,t),D.initChildren(t),t==null||t.add(D,A.Added);const V=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=Ui(V),G=M==null?void 0:M.clone(t,D,m.UUID.uuid(),!0);if(G){const Q=(q=D.dataType)==null?void 0:q.merge(G,t);D.dataType&&(Q==null?void 0:Q.self.id)!==D.dataType.id&&D.dataType.remove({ignoreUpstream:!1},t),G.id!==((S=Q==null?void 0:Q.self)==null?void 0:S.id)&&G.remove({ignoreUpstream:!1},t),Q!=null&&Q.self&&(Q.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(Q.self,A.Added),D.setDataType(Q.self),t==null||t.add(D,A.Updated))}return this.addProperty(D),c.setDeclaration(D),t==null||t.add(c,A.Updated),D}),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})}};h($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}),h($e,"type",n.DefinitionEntity),h($e,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),h($e,"PARENT_TYPES",[...$e.USER_MANAGED_PARENT_TYPES]),h($e,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),h($e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h($e,"BASE_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"MUTABLE_META_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,"x","y"]),h($e,"INMUTABLE_META_PROPERTIES",[...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"META_PROPERTIES",[...$e.MUTABLE_META_PROPERTIES,...$e.INMUTABLE_META_PROPERTIES]),h($e,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),h($e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h($e,"UPSTREAM_PROPERTIES",[...$e.MUTABLE_UPSTREAM_PROPERTIES,...$e.INMUTABLE_UPSTREAM_PROPERTIES]),h($e,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),h($e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h($e,"DOWNSTREAM_PROPERTIES",[...$e.MUTABLE_DOWNSTREAM_PROPERTIES,...$e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h($e,"PROPERTIES",[...$e.META_PROPERTIES,...$e.UPSTREAM_PROPERTIES,...$e.DOWNSTREAM_PROPERTIES]);let on=$e;function hS(r){const a=d5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const Ja=class Ja extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"version");h(this,"name");h(this,"description",null);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",!1);h(this,"static");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"interactive",!1);h(this,"errors",[]);h(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=U,...t){return await Ja.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=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){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=hS(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=zl(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 Ja&&e.push(...i.getAllInteractiveMethods())})),p(e)}};h(Ja,"repository",{APILoad:async(e,...t)=>null});let Gi=Ja;function yS(r){const a=e5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const ld=class ld extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"type",n.PrimitiveEntity);h(this,"static");h(this,"abstract");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(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=U,...t){return await ld.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=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){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=yS(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 Gi&&e.push(...i.getAllInteractiveMethods())}),p(e)}};h(ld,"repository",{APILoad:async(e,...t)=>null});let ri=ld;function st(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 Xr(r,a);case n.DefinitionEntity:return e||new on(r,a);case n.PrimitiveEntity:return e||new ri(r,a);case n.FunctionDeclaration:return e||new Fr(r,a);case n.GlobalEvent:return e||new qr(r,a);case n.DataType:return e||new xr(r,a);case n.Property:return e||new gr(r,a);case n.FunctionCall:return e||new nn(r,a);case n.Condition:return e||new Wr(r,a);case n.Operation:return e||new kr(r,a);case n.VariableDeclaration:return e||new zr(r,a);case n.VariableInstance:return e||new Sr(r,a);case n.OutputMap:return e||new Qi(r,a);case n.ReturnDeclaration:return e||new ii(r,a);case n.ArgumentDeclaration:return e||new Ir(r,a);case n.InputMap:return e||new Xi(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Hr(r,a);case n.ActionDescriptor:return e||new We(r,a);case n.ReturnStatement:return e||new Zr(r,a);case n.Loop:return e||new Jr(r,a);case n.Search:return e||new Yr(r,a);case n.ValueDescriptor:return e||new er(r,a);case n.BuiltInBaseEntity:return e||new Gi(r,a);case n.InternalCall:return e||new Kr(r,a);case n.ContinueStatement:return e||new $t(r,a);case n.BreakStatement:return e||new Qr(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=st(r,a);return e.subscribe(),e}function mS(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return Xr.fromGenerationTarget(r,a);case n.DefinitionEntity:return on.fromGenerationTarget(r,a);case n.FunctionDeclaration:return Fr.fromGenerationTarget(r,a);case n.GlobalEvent:return qr.fromGenerationTarget(r,a);case n.DataType:return xr.fromGenerationTarget(r,a);case n.Property:return gr.fromGenerationTarget(r,a);case n.FunctionCall:return nn.fromGenerationTarget(r,a);case n.Condition:return Wr.fromGenerationTarget(r,a);case n.Operation:return kr.fromGenerationTarget(r,a);case n.VariableDeclaration:return zr.fromGenerationTarget(r,a);case n.VariableInstance:return Sr.fromGenerationTarget(r,a);case n.OutputMap:return Qi.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ii.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return Ir.fromGenerationTarget(r,a);case n.InputMap:return Xi.fromGenerationTarget(r,a);case n.InstalledProject:return Hr.fromGenerationTarget(r,a);case n.ReturnStatement:return Zr.fromGenerationTarget(r,a);case n.Loop:return Jr.fromGenerationTarget(r,a);case n.Search:return Yr.fromGenerationTarget(r,a);case n.ActionDescriptor:return We.fromGenerationTarget(r,a);case n.ValueDescriptor:return er.fromGenerationTarget(r,a);case n.InternalCall:return Kr.fromGenerationTarget(r,a);case n.ContinueStatement:return $t.fromGenerationTarget(r,a);case n.BreakStatement:return Qr.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const J={seenEntityMaps:new Map,seenEntities:new Set,timestamp:T().toISOString()};class yw{constructor(){h(this,"initialData")}}const U={cascade:!1},mw={APILoad:async(r,...a)=>null},vS={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,...mw};class TS{}class ES extends yw{}class IS{}class AS{}class bS{}class sf{}class RS extends sf{}class DS extends sf{}class OS{}class Rr{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=Ai(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.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=Ai(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.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 Za{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),it.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class PS{}const re=class re extends lt{constructor(e){super(e);h(this,"initialData");h(this,"id");h(this,"type",n.Project);h(this,"name",null);h(this,"description",null);h(this,"x");h(this,"y");h(this,"entities",[]);h(this,"projects",[]);h(this,"functions",[]);h(this,"events",[]);h(this,"variableDeclarations",[]);h(this,"variableInstances",[]);h(this,"conditions",[]);h(this,"operations",[]);h(this,"functionCalls",[]);h(this,"loops",[]);h(this,"searches",[]);h(this,"primitives",[]);h(this,"builtInBaseEntities",[]);h(this,"operationDeclarations",[]);h(this,"globalEventActionDescriptors",[]);h(this,"loopDeclarations",[]);h(this,"loopDeclarationsBodies",[]);h(this,"conditionDeclarations",[]);h(this,"valueDescriptors",[]);h(this,"dataTypes",[]);h(this,"project");h(this,"instances",{});h(this,"builtInInstances",{});h(this,"deletedInstances",{});h(this,"errors",[]);h(this,"references",[]);h(this,"history",[]);h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(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{(!re.UUID||re.UUID.isBackup)&&(re.UUID=Jo==null?void 0:Jo()),re.UUID||(re.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),re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){re.UUID=e}static new(e=null){return{id:re.UUID.uuid(),version:re.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||re.sessionAuthor,previousVersion:null,deleted:!1,type:n.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingChangeSets(){const e=this.history.find(t=>t.dirty&&!t.open);e&&await this.closeChangeSet(e)}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingChangeSets()}async closeChangeSet(e){const t=this.history.findIndex(l=>l.id===e.id),i=this.history.slice(0,t),s=i[i.length-1];if(!(s!=null&&s.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(e)).success&&(e.dirty=!1,this.closePendingChangeSets());return}}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.warn("Previous still open: ",i),console.warn("New change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>T(e==null?void 0:e.timestamp).isBefore(T(l==null?void 0:l.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){return 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=re.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);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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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)}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.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,re.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,re.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,re.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,re.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,re.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=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+re.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){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=O7(),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=Ee(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=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=He(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(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===W.PERSISTED_ENTITY)||null}};h(re,"sessionAuthor","1"),h(re,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),h(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}),h(re,"type",n.Project),h(re,"USER_MANAGED_PARENT_TYPES",[]),h(re,"PARENT_TYPES",[...re.USER_MANAGED_PARENT_TYPES]),h(re,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(re,"BASE_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,...re.INMUTABLE_BASE_PROPERTIES]),h(re,"MUTABLE_META_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,"x","y"]),h(re,"INMUTABLE_META_PROPERTIES",[...re.INMUTABLE_BASE_PROPERTIES]),h(re,"META_PROPERTIES",[...re.MUTABLE_META_PROPERTIES,...re.INMUTABLE_META_PROPERTIES]),h(re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(re,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),h(re,"UPSTREAM_PROPERTIES",[...re.MUTABLE_UPSTREAM_PROPERTIES,...re.INMUTABLE_UPSTREAM_PROPERTIES]),h(re,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),h(re,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(re,"DOWNSTREAM_PROPERTIES",[...re.MUTABLE_DOWNSTREAM_PROPERTIES,...re.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(re,"PROPERTIES",[...re.META_PROPERTIES,...re.UPSTREAM_PROPERTIES,...re.DOWNSTREAM_PROPERTIES]);let m=re;var vw=(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))(vw||{});class Tw extends We{constructor(e){super(Bi,e);h(this,"id",Qe.Parallel);h(this,"name",Qe.Parallel);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",Bi);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Bi.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Bi.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Bi.error?C(Bi.error,this.project):null}}class Ew extends We{constructor(e){super(Yt,e);h(this,"id",Yt.id);h(this,"name",Yt.name);h(this,"description",Yt.description);h(this,"version",Yt.version);h(this,"autoexecutable",!1);h(this,"initialData",Yt);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Yt.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Yt.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Yt.error?C(Yt.error,this.project):null}}class Iw extends We{constructor(e){super(lr,e);h(this,"id",Qe.Sequential);h(this,"name",Qe.Sequential);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",lr);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=lr.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=lr.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=lr.error?C(lr.error,this.project):null}}class wS extends We{constructor(a){super(Ns,a)}}class CS extends We{constructor(a){super(un,a)}}class VS extends We{constructor(e){super(pn,e);h(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[tt.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[tt.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[tt.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:E,removed:I,affected:D}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...E),s.push(...c),l.push(...I),o.push(...D)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:E,removed:I,affected:D}=this.syncDataToValidateInputMapDataType(u,t);i.push(...E),s.push(...c),l.push(...I),o.push(...D)}const f=this.getOutputDataOutputMap(e);if(f){const{added:c,updated:E,removed:I,affected:D}=this.syncOutputDataOutputMapDataType(f,t);i.push(...E),s.push(...c),l.push(...I),o.push(...D)}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,f,c;const i=[],s=[],l=[],o=[];if(((u=e.declaration)==null?void 0:u.id)!==k.operation[tt.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 E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},I=C(E,e.project);I.setParent(e,t),I.initChildren(t),t==null||t.add(I,A.Added),i.push(I),e.setDataType(I)}(f=e.dataType)==null||f.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,E,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[tt.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 D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(D,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(E=e.dataType)==null||E.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(f),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,E,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[tt.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 D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(D,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(E=e.dataType)==null||E.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(f),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 s,l;if(((s=e.declaration)==null?void 0:s.id)===k.operation[tt.Validate].inputs.dataToValidate.id){const{added:o,updated:d,removed:u,affected:f}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(d),added:p(o),removed:p(u),affected:p(f),self:e.dataType}}const i=(l=e.declaration)==null?void 0:l.getDataType(t);if(i&&i.isResolved)return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:i};if(e.readsValue){const o=Ui(e.readsValue,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:o}}return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{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[tt.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 BS extends We{constructor(a){super(Id,a)}}class _S extends We{constructor(a){super(bd,a)}}class MS extends We{constructor(a){super(Rd,a)}}class NS extends We{constructor(a){super(Qa,a)}}class LS extends We{constructor(a){super(Ha,a)}}class jS extends We{constructor(a){super(Ms,a)}}function US(r){const a=[new Iw(r),new Tw(r),new Ew(r),new wS(r),new CS(r),new VS(r),new NS(r),new BS(r),new MS(r),new _S(r),new LS(r),new jS(r),new We(Ed,r),new We(Td,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class Aw extends Gi{constructor(e){super(Mt,e);h(this,"initialData");h(this,"id",W.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",W.PERSISTED_ENTITY);h(this,"description",Mt.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Mt.abstract);h(this,"static",Mt.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=Mt,this.project=e,this.id=Mt.id,this.version=Mt.version,this.name=Mt.name,this.static=Mt.static,this.abstract=Mt.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))}}var bw=(r=>(r.StatusCodeMustBeNumber="status-code-must-be-number",r.StatusCodeMustBeBetween100And599="status-code-must-be-between-100-and-599",r))(bw||{});function Rw(r,a){const e=[];if(typeof a!="number"){const t=new Ye({id:r.id+"--status-code-must-be-number",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number.`,issue:null,severity:O.Error,code:"status-code-must-be-number",entity:r});return e.push(t),{errors:e,override:a}}if(a<100){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}if(a>599){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}return{errors:e,override:a}}class Dw extends Gi{constructor(e){super(si,e);h(this,"initialData");h(this,"id",W.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",W.PERSISTED_ENTITY);h(this,"description",si.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",si.abstract);h(this,"static",si.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=si,this.project=e,this.id=si.id,this.version=si.version,this.name=si.name,this.static=si.static,this.abstract=si.abstract,this.properties=this.initialData.properties.map(l=>{const o=C(l,this.project);return o.setParent(this,null),o.initChildren(null),o}),this.methods=this.initialData.methods.map(l=>{const o=C(l,this.project);return o.parent=this,o}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const o=C(l,this.project);return o.parent=this,o}),this.extends=this.initialData.extends.map(l=>C(l,this.project));const t=this.properties.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.path.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(l,o)=>lP(l,o);const i=this.abstractMethods.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id);if(!i)throw new Error("Handler method not found in endpoint entity");const s=i.outputs.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.outputs.statusCode.id);if(!s)throw new Error("Status code output not found in handler method");s.codeNativeValueValidation=(l,o)=>Rw(l,o)}}const $S="test_primitive_entities_export";class GS extends Gi{constructor(e){super(Dt,e);h(this,"initialData");h(this,"id",W.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",W.PERSISTED_ENTITY);h(this,"description",Dt.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Dt.abstract);h(this,"static",Dt.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=Dt,this.project=e,this.id=Dt.id,this.version=Dt.version,this.name=Dt.name,this.static=Dt.static,this.abstract=Dt.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}),this.extends=this.initialData.extends.map(i=>C(i,this.project));const t=this.properties.find(i=>i.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(i,s)=>dP(i,s)}}function gS(r){const a=[new Aw(r),new Dw(r),new GS(r),new Gi(Dt,r),new Gi(vo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function FS(r){const a=[new ri(ae,r),new ri(nr,r),new ri(Te,r),new ri(cd,r),new ri(wt,r),new ri(sr,r),new ri(xi,r),new ri(ar,r),new ri(qn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function xS(r){const a=[new We(Eo,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function kS(r){const a=[new We($s,r),new We(Or,r),new We(js,r),new We(Sn,r),new We(zn,r),new We(oo,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new We(co,r),new We(Us,r),new We(uo,r),new We(Ud,r),new We(Gd,r),new We(lo,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function ZS(r){const a=[new er(Io,r),new er(nu,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function qS(r){const a=[new We(mn,r),new We(Qn,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Gn={},sd={},qa={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function Ow(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new Sl(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=ad(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new b(o,m.sessionAuthor,l,o,!0,"project-init-from-fetch-result")):null;return i.visit(u=>{if(u.id===o.id)return;const f=C(u,o);f.hydrateAncestors(),f.addSelfToProject(null)}),a?(i.visit(u=>{const f=o.get(u.id);f&&f.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):od(o,l).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.attemptAutoclose("project-init-from-fetch-result",o.id),o}async function JS(r,a=qa){const e={...qa,...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={...pp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{try{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})}catch(s){console.error("Error fetching project: ",s),i({data:null})}})}function ad(r){const a=new m(r);return FS(a),gS(a),US(a),xS(a),kS(a),ZS(a),qS(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 od(r,a){return r.instancesList.filter(t=>T(t.createdAt).isAfter(T(a)||!!t.previousVersion))}function WS(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 f=r.get(u);if(!rd(f,{...r.instances,...r.builtInInstances}).every(I=>!t.includes(I))){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=ad(s),o=a?l.addChangeSet(new b(l,m.sessionAuthor,i,l,!0,"project-clone")):null,d=new Sl(r);return d.visit(u=>{const f=u.toShallowJSON({seenEntityMaps:e});u.type===n.ValueDescriptor&&u.name==="Iteration result"&&(console.log("Og entity shallow copy: ",f),console.log("Og entity full: ",u)),f.previousVersion=null,f.createdAt=i,f.version=m.UUID.uuid();const c=C(f,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,A.Added)}),a?(d.visit(u=>{const f=l.get(e.get(u.id));f&&f.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):od(l,i).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.attemptAutoclose("project-clone",l.id),l}function Pw(r,{enrich:a}={enrich:!0}){const e=ad(r),t=T().toISOString(),i=a?e.addChangeSet(new b(e,m.sessionAuthor,t,e,!0,"project-init")):null;i&&(i.type=Vc.Automatic);const s=new Sl(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)):od(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.attemptAutoclose("project-init",e.id),e}async function SS(r,a=qa){const e={...qa,...a};if(r.id&&Gn[r.id]&&!e.ignoreCache)return Gn[r.id];if(r.id&&sd[r.id]&&!e.ignoreCache)return await sd[r.id],Gn[r.id];const t=JS(r,e);r.id&&(sd[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=Pw(pp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=Ow(i.data,{enrich:!!e.enrich}),Gn[r.id]=s,r.id&&delete sd[r.id],s}return null}function zS(r){return Gn[r.id]&&delete Gn[r.id],null}y.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=xc,y.ALL_BUILT_IN_BASE_ENTITIES=qE,y.ALL_BUILT_IN_CONDITION_ENTITIES=nI,y.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=aI,y.ALL_BUILT_IN_LOOP_BODY_ENTITIES=TT,y.ALL_BUILT_IN_LOOP_ENTITIES=vT,y.ALL_BUILT_IN_OPERATION_ENTITIES=V0,y.ALL_BUILT_IN_PRIMITIVE_ENTITIES=vf,y.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=cI,y.ALL_BUILT_IN_VALUE_DESCRIPTORS=pI,y.ActionDescriptorState=We,y.ActionInputMapState=eW,y.ActionOutputMapState=rW,y.AppendToListOperationInputIds=Oy,y.AppendToListOperationOutputIds=Py,y.ArgumentDeclarationDependencyField=$1,y.ArgumentDeclarationState=Ir,y.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=$c,y.BUILT_IN_BASE_ENTITY_IDS=k,y.BUILT_IN_ENTITY_TYPES=ni,y.BaseCanvasDraggableState=IS,y.BaseEntityNames=W,y.BaseState=ES,y.BaseValueDescriptorIds=Zn,y.BreakStatementDependencyField=x1,y.BreakStatementState=Qr,y.BuiltInBaseEntityState=Gi,y.CACHED_PROJECTS_BY_ID=Gn,y.CALLABLE_ENTITIES_EXPLANATION=cW,y.CALLABLE_TYPES=gi,y.CALLER_ENTITIES_EXPLANATION=W1,y.CALLER_TYPES=Fi,y.CALLS_UPDATE_EXPLANATION=tn,y.COMPARISON_CONDITIONS=iI,y.CONDITIONS=rI,y.CUSTOM_ENTITY_OPERATIONS=Sm,y.CallableEntityClass=bS,y.CallerEntityClass=sf,y.ChangeSet=b,y.ChangeSetChangeCaptureType=Vc,y.ChangeSetEntityChangeType=A,y.ChildEntityState=AS,y.CommonStringValidationErrorCodes=oP,y.ComparisonOperatorTypes=ft,y.ConditionDependencyField=b1,y.ConditionState=Wr,y.ContinueStatementDependencyField=m1,y.ContinueStatementState=$t,y.CreateNewInputIds=Am,y.CreateNewOutputIds=bm,y.DRAGGABLE_CALLABLE_TYPES=pd,y.DRAGGABLE_CALLER_TYPES=df,y.DRAGGABLE_ELEMENT_TYPES=Ya,y.DRAGGABLE_EXECUTABLE_TYPES=_w,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=za,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=ud,y.DataTypeCompatibilityTypes=Pi,y.DataTypeDependencyField=Bc,y.DataTypeParentChildRelation=Pt,y.DataTypeState=xr,y.DefinitionEntityDependencyField=nd,y.DefinitionEntityState=on,y.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=vS,y.ENTITIES_WITH_VALLUES_EXPLANATION=kl,y.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=U,y.ENTITY_RECUSION_OPTIONS_DEFAULTS=J,y.ENTITY_TYPES=Mw,y.ENTITY_WITH_DECLARATION_TYPES=Vw,y.ENTITY_WITH_LOGIC_SCOPE_TYPES=ht,y.ENTITY_WITH_NAMES_TYPES=uf,y.ENTITY_WITH_PARENT_TYPES=ww,y.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=of,y.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=Cw,y.ENTITY_WITH_VALUE_TYPES=af,y.ENTRY_POINT_ENTITIES_EXPLANATION=Ma,y.ENTRY_POINT_TYPES=rt,y.EVENT_TYPES=kn,y.EXECUTABLE_TYPES=Bw,y.EXECUTION_OPERATIONS=Im,y.EndpointEntity=Dw,y.EntityAction=vw,y.EntityError=Ye,y.EntityErrorSeverity=O,y.EntityGenerationError=w,y.EntityGenerationErrorCode=R,y.EntityInstanceErrorCode=F,y.EntityOperations=tt,y.EntityType=n,y.EntityWithLogicScopeClass=PS,y.EntityWithValueClass=OS,y.EntryPointEntityClass=RS,y.ExecutionOperations=Qe,y.ExecutionTerminationType=E1,y.FunctionCallDependencyField=rP,y.FunctionCallState=nn,y.FunctionDeclarationDependencyField=l1,y.FunctionDeclarationState=Fr,y.GET_PROJECT_OPTIONS_DEFAULTS=qa,y.GLOBAL_EVENT_DECLARATIONS=sI,y.GetLastInListOperationInputIds=fy,y.GetLastInListOperationOutputIds=hy,y.GlobalEventNames=rr,y.GlobalEventState=qr,y.HTTPOperations=jt,y.HTTPStatucCodeValidationErrorCodes=bw,y.HTTP_OPERATIONS=w0,y.InputMapDependencyField=N1,y.InputMapState=Xi,y.InstalledProjectState=Hr,y.InternalCallDependencyField=_1,y.InternalCallState=Kr,y.JoinListOperationInputIds=Nh,y.JoinListOperationOutputIds=Lh,y.LIST_OPERATIONS=gy,y.ListOperations=ye,y.LiteralValueDependencyField=g1,y.LiteralValueState=Xr,y.LoopDependencyField=I1,y.LoopState=Jr,y.LoopTypes=ee,y.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=rn,y.NUMBER_OPERATIONS=Sf,y.NumberOperations=et,y.OPERATION_DECLARATIONS=C0,y.OperationDependencyField=p1,y.OperationState=kr,y.OutputMapDependencyField=j1,y.OutputMapParentChildRelation=xn,y.OutputMapState=Qi,y.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Zl,y.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=en,y.PASS_THROUGH_CALLABLE_TYPES=dt,y.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=lf,y.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Fc,y.ParallelExecutionOperation=Tw,y.PassThroughCallableEntityClass=DS,y.PersistedEntity=Aw,y.PersistedEntityMethods=fi,y.PrimitiveEntityState=ri,y.PrimitiveTypes=N,y.ProjectState=m,y.PropertyDependencyField=a1,y.PropertyState=gr,y.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=mw,y.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=fW,y.ReturnDeclarationDependencyField=f1,y.ReturnDeclarationState=ii,y.ReturnStatementDependencyField=_c,y.ReturnStatementState=Zr,y.STANDALONE_CONDITIONS=SE,y.STRING_OPERATIONS=Mh,y.ScopeCompatibilityType=td,y.SearchDependencyField=w1,y.SearchState=Yr,y.SequentialExecutionOperation=Iw,y.SequentialExecutionOperationInputIds=om,y.SequentialExecutionOperationOutputIds=lm,y.SharedEntityErrorCode=$,y.SharedStateFunctionality=yw,y.SplitListOperationInputIds=Yh,y.SplitListOperationOutputIds=Hh,y.StandaloneOperatorTypes=bi,y.StringOperations=Ae,y.TERMINATION_TYPES=ot,y.Traverser=Sl,y.USER_MANAGED_ENTITY_TYPES=pf,y.UserManagedEntityStateTemplate=TS,y.VALUE_READING_ENTITIES_EXPLANATION=gc,y.VALUE_READING_TYPES=Dr,y.VALUE_WRITING_ENTITIES_EXPLANATION=S1,y.VALUE_WRITING_TYPES=Tt,y.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=Gc,y.VARIABLE_TYPES=it,y.ValueAutogenerationType=vt,y.ValueDescriptorDependencyField=Z1,y.ValueDescriptorParentChildRelation=L,y.ValueDescriptorState=er,y.ValueReadingEntityClass=Rr,y.ValueWritingEntityClass=Za,y.VariableDeclarationDependencyField=O1,y.VariableDeclarationState=zr,y.VariableInputMapState=QJ,y.VariableInstanceDependencyField=Nc,y.VariableInstanceState=Sr,y.VariableOutputMapState=iW,y.WaitOperation=Ew,y.WaitOperationInputIds=em,y.WaitOperationOutputIds=tm,y.actionDescriptorValidation=JJ,y.appendToListOperation=Qa,y.appendToListOperationElementToAppendArgument=Od,y.appendToListOperationElementToAppendArgumentParentRef=Ly,y.appendToListOperationElementToAppendArgumentRef=Vy,y.appendToListOperationError=Gy,y.appendToListOperationErrorParentRef=$y,y.appendToListOperationListArgument=Dd,y.appendToListOperationListArgumentParentRef=Ny,y.appendToListOperationListArgumentRef=wy,y.appendToListOperationListDataType=Cy,y.appendToListOperationResultListDataType=My,y.appendToListOperationResultListReturn=Uy,y.appendToListOperationResultListReturnParentRef=jy,y.appendToListOperationResultListReturnRef=_y,y.appendToListOperationSecondListDataType=By,y.applyNewScope=K,y.argumentDeclarationValidation=nW,y.asGenerationActionExample=tr,y.booleanPrototype=nr,y.breakStatementValidation=oW,y.calculateNewParentBasedOnCallers=Sc,y.capitalizeFirstLetter=Vt,y.changeSetJSONRecordToUniqueIds=_J,y.checkAreDataTypesCompatible=wi,y.checkAreDefinitionEntitiesCompatibleAsDataType=JO,y.checkArePropertiesCompatibleAsDataType=qO,y.checkExtendsBaseEntity=id,y.checkHasBaseEntity=ka,y.checkHasMetadataChanged=pt,y.checkImplementationsOverlap=br,y.checkImplementsBaseEntity=WW,y.checkIsBranchDependentButNotDirectlyOnBranch=La,y.checkIsBranchDependentOnBranch=PW,y.checkIsCallableEntityReachable=xa,y.checkIsCanvasEntity=qW,y.checkIsDetachedBranch=aw,y.checkIsDetachedBranchShallow=rf,y.checkIsGlobalVariable=kW,y.checkIsGloballyDeclared=tf,y.checkIsMethod=dw,y.checkIsNestedScope=ed,y.checkScopeCompatibility=Fa,y.cloneProject=WS,y.conditionValidation=WJ,y.continueStatementValidation=xJ,y.convertToAbstract=bW,y.convertToNonAbstract=RW,y.convertToNonStatic=OW,y.convertToStatic=DW,y.countedLoopActionDescriptor=$s,y.countedLoopActionDescriptorDynamicReturnDeclaration=dT,y.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=lT,y.countedLoopActionDescriptorStringArgumentDeclaration=oT,y.countedLoopActionDescriptorStringArgumentDeclarationDataType=sT,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=rT,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=iT,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=nT,y.countedLoopActionDescriptorStringArgumentDeclarationParentRef=aT,y.countedLoopBodyActionDescriptor=co,y.countedLoopBodyActionDescriptorAnyDynamicArgument=hT,y.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=fT,y.countedLoopBodyActionDescriptorAnyDynamicReturn=mT,y.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=yT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Fd,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=pT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=uT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=cT,y.createDefinitionEntityFromJSONObject=Yl,y.createEntityError=de,y.createNestedDataTypeForEntity=aP,y.createNewInstanceOperation=un,y.createNewInstanceOperationEntityToInstanciateArgument=Bm,y.createNewInstanceOperationEntityToInstanciateArgumentRef=wm,y.createNewInstanceOperationEntityToInstanciateDataType=Cm,y.createNewInstanceOperationError=Lm,y.createNewInstanceOperationErrorParentRef=Nm,y.createNewInstanceOperationNewEntityDataArgument=Pm,y.createNewInstanceOperationNewEntityDataArgumentDataType=Om,y.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Dm,y.createNewInstanceOperationNewEntityDataArgumentParentRef=Rm,y.createNewInstanceOperationOutputEntityDeclaration=Mm,y.createNewInstanceOperationOutputEntityDeclarationParentRef=_m,y.createNewInstanceOperationRef=Vm,y.createSemanticId=r1,y.createStateFromGenerationTargetType=mS,y.createStateFromType=st,y.createStateFromTypeAndSubscribe=C,y.cronJobBuiltInBaseEntity=vo,y.cronJobBuiltInBaseEntityExpressionProperty=kE,y.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Fw,y.cronJobBuiltInBaseEntityExpressionPropertyRef=FE,y.cronJobBuiltInBaseEntityRef=xE,y.cronJobTriggeredFunctionDeclarationBlueprint=eu,y.cronJobTriggeredFunctionDeclarationBlueprintParentRef=GE,y.dataTypeCompatibilityToErrorExplanation=tP,y.dataTypeValidation=jJ,y.datePrototype=xi,y.dateValueAutogenerationSchema=mp,y.definitionEntityToZodSchema=CI,y.definitionEntityValidation=cS,y.deletePersistedEntityMethod=Qd,y.deletePersistedEntityMethodParentRef=RE,y.deleteRootProject=zS,y.endpointBuiltInBaseEntity=si,y.endpointBuiltInBaseEntityRef=bT,y.endpointBuiltInBaseEntityRefFour=nE,y.endpointBuiltInBaseEntityRefThree=_T,y.endpointBuiltInBaseEntityRefTwo=wT,y.endpointBuiltInCorsProperty=RT,y.endpointBuiltInCorsPropertyDataType=AT,y.endpointBuiltInCorsPropertyDataTypeRef=ET,y.endpointBuiltInCorsPropertyRef=IT,y.endpointBuiltInMethodProperty=kd,y.endpointBuiltInMethodPropertyDataType=BT,y.endpointBuiltInMethodPropertyDataTypeRef=CT,y.endpointBuiltInMethodPropertyRef=VT,y.endpointBuiltInPathProperty=xd,y.endpointBuiltInPathPropertyDataType=PT,y.endpointBuiltInPathPropertyDataTypeRef=DT,y.endpointBuiltInPathPropertyRef=OT,y.endpointPathParamsArgumentDeclaration=qd,y.endpointPathParamsArgumentDeclarationRef=xT,y.endpointPathParamsVariableDataType=kT,y.endpointPathParamsVariableDataTypeRef=FT,y.endpointReachedTriggerActionDescriptor=Hd,y.endpointReachedTriggerActionDescriptorRef=ZT,y.endpointReachedTriggerActionDescriptorRefFour=WT,y.endpointReachedTriggerActionDescriptorRefThree=JT,y.endpointReachedTriggerActionDescriptorRefTwo=qT,y.endpointRequestBodyArgumentDeclaration=Wd,y.endpointRequestBodyArgumentDeclarationRef=jT,y.endpointRequestBodyVariableDataType=UT,y.endpointRequestHeadersArgumentDeclaration=Zd,y.endpointRequestHeadersArgumentDeclarationRef=NT,y.endpointRequestHeadersVariableDataType=LT,y.endpointRequestHeadersVariableDataTypeRef=MT,y.endpointRequestQueryParamsArgumentDeclaration=Jd,y.endpointRequestQueryParamsArgumentDeclarationRef=GT,y.endpointRequestQueryParamsVariableDataType=gT,y.endpointRequestQueryParamsVariableDataTypeRef=$T,y.endpointResponseBodyDataType=iE,y.endpointResponseBodyReturnDeclaration=Yd,y.endpointResponseBodyReturnDeclarationRef=tE,y.endpointResponseCodeDataType=zT,y.endpointResponseCodeReturnDeclaration=Sd,y.endpointResponseCodeReturnDeclarationDefaultValueParentRef=HT,y.endpointResponseCodeReturnDeclarationRef=ST,y.endpointResponseHeadersDataType=QT,y.endpointResponseHeadersDataTypeRef=KT,y.endpointResponseHeadersReturnDeclaration=zd,y.endpointResponseHeadersReturnDeclarationRef=XT,y.endpointReturnStatementRef=YT,y.endpointReturnStatementRefThree=rE,y.endpointReturnStatementRefTwo=eE,y.enrichFromKnownEntities=ja,y.enumOptionsProperty=mf,y.enumOptionsPropertyDataType=hf,y.enumOptionsPropertyDataTypeRef=cf,y.enumOptionsPropertyRef=ff,y.enumPrototype=sr,y.enumPrototypeRef=yf,y.executionBuiltInBaseEntity=To,y.executionBuiltInEntityAbortMethod=tu,y.executionBuiltInEntityAbortMethodParentRef=ZE,y.filterOutDuplicateEntities=p,y.filterOutDuplicateErrors=J3,y.findEntityFromKeys=Jc,y.findReferenceToSelfInList=DP,y.findReferencesToSelfInProject=jW,y.flattenActionDescriptor=OP,y.flattenArgumentDeclaration=PP,y.flattenBreakStatement=wP,y.flattenBuiltInBaseEntity=CP,y.flattenCalls=Ci,y.flattenCanvasAncestorsUntil=Cs,y.flattenCondition=VP,y.flattenContinueStatement=BP,y.flattenDataType=MP,y.flattenDefinitionEntity=_P,y.flattenDefinitionEntityExtensionAndImplementationTypes=ef,y.flattenDefinitionEntityExtensionTypes=$a,y.flattenDefinitionEntityExtensions=Xc,y.flattenDefinitionEntityImplementations=Qc,y.flattenDefinitionEntityImplementionTypes=Ua,y.flattenDerivedCanvasEntities=pi,y.flattenDetachedBranch=lw,y.flattenElementCalls=Ee,y.flattenElementCallsOnTheSameScope=LW,y.flattenEntity=j,y.flattenFunctionCall=NP,y.flattenFunctionDeclaration=LP,y.flattenGlobalEvent=jP,y.flattenInputMap=UP,y.flattenInstalledProject=$P,y.flattenInternalCall=GP,y.flattenLiteralValue=gP,y.flattenLoop=FP,y.flattenOperation=xP,y.flattenOutputMap=kP,y.flattenPrimitiveEntity=ZP,y.flattenProject=qP,y.flattenProjectElements=RP,y.flattenProperty=JP,y.flattenRelatedCanvasElementsOnTheLeft=rw,y.flattenRelatedCanvasElementsOnTheRight=iw,y.flattenReturnDeclaration=WP,y.flattenReturnStatement=SP,y.flattenSearch=zP,y.flattenValueDescriptor=YP,y.flattenVariableDeclaration=HP,y.flattenVariableInstance=KP,y.flattenVariableReads=bP,y.flattenVariableWrites=AP,y.flattenVariables=He,y.fromChangeSetToRecordChangeSet=QW,y.fromZodParseToEntityGenerationErrors=Lc,y.functionCallValidation=AW,y.functionDeclarationValidation=LJ,y.generate=qV,y.generateActionExample=hW,y.generateExecutionDataType=bJ,y.generateIdFromStrategy=yt,y.generateMutablePropertiesExplanation=gl,y.generateRandomBoolean=tA,y.generateRandomDate=MI,y.generateRandomDateAfter=VI,y.generateRandomDateBefore=BI,y.generateRandomDateBetweenRange=_I,y.generateRandomNumber=HI,y.generateRandomNumberAfter=SI,y.generateRandomNumberBefore=zI,y.generateRandomNumberBetweenRange=YI,y.generateRandomText=eA,y.generateRandomTextAfter=KI,y.generateRandomTextBefore=XI,y.generateRandomTextBetweenRange=QI,y.generateUniqueUUID=WI,y.getAllActionDescriptorsForConditions=Wl,y.getAllActionDescriptorsForGlobalEvents=ql,y.getAllActionDescriptorsForLoops=Jl,y.getAllActionDescriptorsForOperations=TW,y.getAllBuiltInEntityIds=$i,y.getAllGloballyDeclaredFunctionDeclarationsExplanation=X1,y.getBaseBuiltInEntities=Wt,y.getBaseSchemaBasedOnType=q1,y.getBuiltInEntityOwner=an,y.getCallableEntityReferenceSchema=Ct,y.getCallableEntityTypeSchema=MD,y.getCalledBy=Ii,y.getCallerEntityReferenceSchema=YZ,y.getCallerEntityTypeSchema=zZ,y.getCalls=Yc,y.getCanvasEntitiesDerivedFromInternalCalls=tw,y.getCanvasEntitiesDerivedFromWrites=Vs,y.getCanvasEntityDerivedFromValueReadingEntity=Ql,y.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=ew,y.getCanvasEntityReferenceSchema=c7,y.getCanvasEntityTypeSchema=p7,y.getChildrenEntityWithValues=CW,y.getColumnProperties=HW,y.getCommonAncestor=zc,y.getCommonChildren=uP,y.getDatabaseEntities=zW,y.getDatabaseEntity=KW,y.getDeclaration=Un,y.getDeclarationOutputedError=tS,y.getDeepestScope=pw,y.getDraggableCallableEntityReferenceSchema=LD,y.getDraggableCallableEntityTypeSchema=ND,y.getDraggableCallerEntityReferenceSchema=KZ,y.getDraggableCallerEntityTypeSchema=HZ,y.getDraggableExecutableEntityReferenceSchema=t7,y.getDraggableExecutableEntityTypeSchema=e7,y.getDraggablePassThroughCallableEntityReferenceSchema=wl,y.getDraggablePassThroughCallableEntityTypeSchema=Pl,y.getDraggablePlayableEntityReferenceSchema=a7,y.getDraggablePlayableEntityTypeSchema=s7,y.getEntitiesCreatedSinceInitialization=od,y.getEntityArgumentDeclarations=Kc,y.getEntityInputMaps=XP,y.getEntityOutputMaps=gW,y.getEntityReferenceSchema=u7,y.getEntityReturnDeclarations=QP,y.getEntityTypeSchema=d7,y.getEntityWithLogicScopeReferenceSchema=vr,y.getEntityWithLogicScopeTypeSchema=i7,y.getEntityWithValueReferenceSchema=_D,y.getEntityWithValueTypeSchema=SZ,y.getEntryPointEntityReferenceSchema=Ot,y.getEntryPointEntityTypeSchema=Ur,y.getEventEntityReferenceSchema=Dl,y.getEventEntityTypeSchema=Rl,y.getExecutableEntityReferenceSchema=QZ,y.getExecutableEntityTypeSchema=XZ,y.getExtendedBuiltInEntity=FW,y.getExtendedDefinitionEntity=sw,y.getFirstNonLoopScopeOwner=It,y.getGenerationTargetSchemaBasedOnType=J1,y.getHeadIfPartOfDetachedBranch=ow,y.getHighestScope=uw,y.getImplementedBuiltInEntity=xW,y.getIsInteractive=Ga,y.getLastInListOperation=Rd,y.getLastInListOperationError=Dy,y.getLastInListOperationErrorParentRef=Ry,y.getLastInListOperationInputListArgument=Iy,y.getLastInListOperationInputListArgumentParentRef=Ey,y.getLastInListOperationInputListArgumentRef=yy,y.getLastInListOperationInputListDataType=my,y.getLastInListOperationOutputElementDataType=Ty,y.getLastInListOperationOutputElementReturn=by,y.getLastInListOperationOutputElementReturnParentRef=Ay,y.getLastInListOperationOutputElementReturnRef=vy,y.getLinkedEntitiesFromArgumentDeclaration=NW,y.getLowestPersistedEntityImplementation=nw,y.getParentCallableEntity=pP,y.getParentCallerEntity=fP,y.getParentCanvasEntities=Gt,y.getParentCanvasEntity=Bt,y.getParentCanvasEntityFromTransfer=Hl,y.getParentEntryPoint=wW,y.getParentPassthroughCallableEntity=cP,y.getPassThroughCallableEntityReferenceSchema=nt,y.getPassThroughCallableEntityTypeSchema=Ol,y.getPeristedEntities=SW,y.getPlayableEntityReferenceSchema=n7,y.getPlayableEntityTypeSchema=r7,y.getProject=SS,y.getPrototypeByType=ga,y.getRecusriveParentsIds=rd,y.getReferenceEntityId=_,y.getReferencedEntitiesStateOrErrors=xl,y.getReferencedEntityStateOrErrors=jc,y.getReferencedIds=Xl,y.getRelatedCanvasElementsOnTheLeft=$n,y.getRelatedCanvasElementsOnTheLeftFromTransfer=UW,y.getRelatedCanvasElementsOnTheRight=sn,y.getRootEntryPointScopeOwner=nf,y.getScopeOwner=St,y.getStateClassFromType=XW,y.getTerminationReferenceSchema=l7,y.getTerminationTypeSchema=o7,y.getTouchedCanvasEntitiesFromChangeSet=eS,y.getUsedArgFromDeclaration=$W,y.getUsedReturnFromDeclaration=GW,y.getValueReadingEntityReferenceSchema=BD,y.getValueReadingEntityTypeSchema=mr,y.getValueWritingEntityReferenceSchema=WZ,y.getValueWritingEntityTypeSchema=Aa,y.getVariableFromInputMapping=yP,y.getVariableFromReturnVariablePointer=TP,y.getVariableReferenceSchema=jr,y.getVariableTypeSchema=Bn,y.getVariablesFromArgumentDeclarations=Kl,y.getVariablesFromInputMaps=mP,y.getVariablesFromOutputMapping=EP,y.getVariablesFromOutputMaps=IP,y.getVariablesFromReturnDeclarations=vP,y.getVariablesInSameOrHigherScope=Ac,y.getWrites=Hc,y.globalEventValidation=kJ,y.groupCallsBasedOnParallelizableExecution=BW,y.handleAfterEntityImplementationSideEffects=sP,y.handleBeforeEntityImplementationSideEffects=nP,y.httpRequestBodyArgument=ro,y.httpRequestBodyArgumentRef=a0,y.httpRequestBodyDataType=o0,y.httpRequestHeadersArgument=io,y.httpRequestHeadersArgumentRef=n0,y.httpRequestHeadersDataType=s0,y.httpRequestMethodArgument=eo,y.httpRequestMethodArgumentRef=i0,y.httpRequestMethodDataType=r0,y.httpRequestMethodDataTypeRef=e0,y.httpRequestOperation=Ns,y.httpRequestOperationErrorValueDescriptor=_d,y.httpRequestOperationErrorValueDescriptorDatatype=P0,y.httpRequestOperationErrorValueDescriptorRef=O0,y.httpRequestOperationRef=A0,y.httpRequestOperationRefEight=R0,y.httpRequestOperationRefFive=E0,y.httpRequestOperationRefFour=T0,y.httpRequestOperationRefNine=D0,y.httpRequestOperationRefSeven=b0,y.httpRequestOperationRefSix=I0,y.httpRequestOperationRefThree=v0,y.httpRequestOperationRefTwo=m0,y.httpRequestQueryParamsArgument=Bd,y.httpRequestQueryParamsArgumentRef=Xm,y.httpRequestQueryParamsDataType=Qm,y.httpRequestVariableURLArgument=to,y.httpRequestVariableURLArgumentRef=Hm,y.httpRequestVariableURLDataType=Km,y.httpRequestVariableURLDataTypeRef=zm,y.httpResponseBodyReturnDataType=y0,y.httpResponseBodyReturnDataTypeRef=f0,y.httpResponseBodyReturnReturn=ao,y.httpResponseBodyReturnReturnRef=h0,y.httpResponseCodeDataType=d0,y.httpResponseCodeReturn=no,y.httpResponseCodeReturnRef=l0,y.httpResponseHeadersDataType=c0,y.httpResponseHeadersDataTypeRef=u0,y.httpResponseHeadersReturn=so,y.httpResponseHeadersReturnRef=p0,y.httpStatusCodeValueValidation=Rw,y.implement=zl,y.inferArgumentDeclarationDataType=WO,y.inferDataType=Ui,y.inferInputMapDataType=Tc,y.inferOutputMapDataType=Ic,y.inferPropertyDataType=YO,y.inferReturnDeclarationDataType=Ec,y.inferValueDescriptorDataType=HO,y.inferVariableDeclarationDataType=zO,y.inferVariableInstanceDataType=SO,y.initBaseProjectEntity=ad,y.initProject=Pw,y.initProjectFromFetchResult=Ow,y.inputMapValidation=XJ,y.installedProjectValidation=HJ,y.internalCallValidation=KJ,y.isPromise=qc,y.iterateOverListActionDescriptorListArgumentDeclaration=av,y.iterateOverListActionDescriptorListArgumentDeclarationDataType=nv,y.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=rv,y.iterateOverListActionDescriptorListArgumentDeclarationParentRef=sv,y.iterateOverListLoopActionDescriptor=Or,y.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=lv,y.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=ov,y.iterateOverListLoopBodyActionDescriptor=Us,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=vv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=mv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Ev,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=Tv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=po,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=uv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=dv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=pv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=yv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=fv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=cv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=hv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Dv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=bv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Av,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=Rv,y.iterateOverObjectKeysLoopActionDescriptor=Sn,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Pv,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=Ov,y.iterateOverObjectKeysLoopBodyActionDescriptor=Ud,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=jv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Lv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=$v,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Uv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=jd,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Cv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=wv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Vv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Nv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=_v,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Bv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Mv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=kv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Fv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=gv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=xv,y.iterateOverObjectValuesLoopActionDescriptor=zn,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=qv,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Zv,y.iterateOverObjectValuesLoopBodyActionDescriptor=Gd,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Qv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Xv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=tT,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=eT,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=$d,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Wv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Jv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Sv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Kv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Yv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=zv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Hv,y.iterateOverStringActionDescriptorDynamicReturnDeclaration=J0,y.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=q0,y.iterateOverStringActionDescriptorStringArgumentDeclaration=Z0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=x0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=F0,y.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=k0,y.iterateOverStringLoopActionDescriptor=js,y.iterateOverStringLoopBodyActionDescriptor=uo,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=Q0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=X0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=tv,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=ev,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Nd,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=S0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=W0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=z0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Ld,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=H0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Y0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=K0,y.joinListOperation=Id,y.joinListOperationError=zh,y.joinListOperationErrorParentRef=Sh,y.joinListOperationFirstListArgument=kh,y.joinListOperationFirstListArgumentParentRef=xh,y.joinListOperationFirstListArgumentRef=jh,y.joinListOperationFirstListDataType=Uh,y.joinListOperationResultListDataType=Fh,y.joinListOperationResultListReturn=Wh,y.joinListOperationResultListReturnParentRef=Jh,y.joinListOperationResultListReturnRef=gh,y.joinListOperationSecondListArgument=qh,y.joinListOperationSecondListArgumentParentRef=Zh,y.joinListOperationSecondListArgumentRef=$h,y.joinListOperationSecondListDataType=Gh,y.joinListWithLastSeparator=se,y.joinStringsOperation=Ms,y.joinStringsOperationDynamicStringArgument=hh,y.joinStringsOperationDynamicStringArgumentParentRef=fh,y.joinStringsOperationDynamicStringArgumentRef=ph,y.joinStringsOperationDynamicStringDataType=ch,y.joinStringsOperationError=uh,y.joinStringsOperationErrorParentRef=dh,y.joinStringsOperationFirstStringArgument=Ka,y.joinStringsOperationFirstStringArgumentParentRef=eh,y.joinStringsOperationFirstStringArgumentRef=zf,y.joinStringsOperationFirstStringDataType=Yf,y.joinStringsOperationResultStringDataType=Qf,y.joinStringsOperationResultStringReturn=_s,y.joinStringsOperationResultStringReturnParentRef=lh,y.joinStringsOperationResultStringReturnRef=Xf,y.joinStringsOperationSecondStringArgument=Xa,y.joinStringsOperationSecondStringArgumentParentRef=oh,y.joinStringsOperationSecondStringArgumentRef=Hf,y.joinStringsOperationSecondStringDataType=Kf,y.joinStringsOperationSeparatorStringArgument=ah,y.joinStringsOperationSeparatorStringArgumentParentRef=sh,y.joinStringsOperationSeparatorStringArgumentRef=th,y.joinStringsOperationSeparatorStringDataType=nh,y.joinStringsOperationSeparatorStringDataTypeDefaultValue=rh,y.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=ih,y.keyValuePrototype=qn,y.literalValudValidation=sW,y.loopValidation=qJ,y.lowercaseFirstLetter=_a,y.manualFlowActionDescriptorDeclarationArgumentDeclaration=Md,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=N0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=M0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=L0,y.manualFlowLoopActionDescriptor=oo,y.manualFlowLoopActionDescriptorDynamicReturnDeclaration=_0,y.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=B0,y.manualFlowLoopBodyActionDescriptor=lo,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=U0,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=j0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=G0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=$0,y.mapActionDescriptorToTypeItRepresents=JW,y.mergeEntityErrorsList=W3,y.mergeListOfEntities=ZW,y.methodDefaultValue=t0,y.mockClientProject=pp,y.moreThanOrEqualCondition=Qn,y.moreThanOrEqualConditionLeftHandArgument=KE,y.moreThanOrEqualConditionLeftHandArgumentDataType=YE,y.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=zE,y.moreThanOrEqualConditionLeftHandArgumentParentRef=HE,y.moreThanOrEqualConditionRightHandArgument=tI,y.moreThanOrEqualConditionRightHandArgumentDataType=QE,y.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=XE,y.moreThanOrEqualConditionRightHandArgumentParentRef=eI,y.noSpacesOrDashesValueValidation=dP,y.noSpacesValueValidation=lP,y.notEmptyCondition=mn,y.notEmptyConditionArgument=WE,y.notEmptyConditionRef=JE,y.nullPrototype=cd,y.numberAdditionOperation=Ha,y.numberAdditionOperationDynamicSummandArgument=Bf,y.numberAdditionOperationDynamicSummandArgumentType=Vf,y.numberAdditionOperationDynamicSummandArgumentTypeParentRef=Cf,y.numberAdditionOperationError=wf,y.numberAdditionOperationErrorParentRef=Pf,y.numberAdditionOperationFirstNumberArgument=fd,y.numberAdditionOperationFirstNumberArgumentRef=Tf,y.numberAdditionOperationFirstNumberDataType=Ef,y.numberAdditionOperationRef=Df,y.numberAdditionOperationRefThree=yd,y.numberAdditionOperationRefTwo=Of,y.numberAdditionOperationResultNumberDataType=Rf,y.numberAdditionOperationResultNumberReturn=md,y.numberAdditionOperationResultNumberReturnRef=bf,y.numberAdditionOperationSecondNumberArgument=hd,y.numberAdditionOperationSecondNumberArgumentRef=If,y.numberAdditionOperationSecondNumberDataType=Af,y.numberPrototype=Te,y.numberSubtractionOperation=Td,y.numberSubtractionOperationDynamicSubtrahendArgument=Wf,y.numberSubtractionOperationDynamicSubtrahendArgumentType=Jf,y.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=qf,y.numberSubtractionOperationError=Zf,y.numberSubtractionOperationErrorParentRef=kf,y.numberSubtractionOperationFirstNumberArgument=$f,y.numberSubtractionOperationFirstNumberArgumentRef=_f,y.numberSubtractionOperationFirstNumberDataType=Mf,y.numberSubtractionOperationRef=vd,y.numberSubtractionOperationRefThree=Ff,y.numberSubtractionOperationRefTwo=Gf,y.numberSubtractionOperationResultNumberDataType=Uf,y.numberSubtractionOperationResultNumberReturn=xf,y.numberSubtractionOperationResultNumberReturnRef=jf,y.numberSubtractionOperationSecondNumberArgument=gf,y.numberSubtractionOperationSecondNumberArgumentRef=Nf,y.numberSubtractionOperationSecondNumberDataType=Lf,y.numberValueAutogenerationSchema=yp,y.operationValidation=GJ,y.outputMapValidation=tW,y.parallelExecutionOperation=Bi,y.parallelExecutionOperationError=Qy,y.parallelExecutionOperationErrorParentRef=Xy,y.parallelExecutionOperationListOfExecutionResultsDataType=Yy,y.parallelExecutionOperationListOfExecutionResultsReturn=wd,y.parallelExecutionOperationListOfExecutionResultsReturnRef=zy,y.parallelExecutionOperationListOfFunctionsArgument=Pd,y.parallelExecutionOperationListOfFunctionsArgumentDatatype=Sy,y.parallelExecutionOperationListOfFunctionsArgumentRef=Wy,y.parallelExecutionOperationListOfFunctionsBlueprint=Jy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Zy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=ky,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=xy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=Fy,y.parallelExecutionOperationListOfFunctionsBlueprintParentRef=qy,y.parallelExecutionOperationRef=Hy,y.parallelExecutionOperationRefThree=Ky,y.persistedBuiltInBaseEntity=Mt,y.persistedBuiltInBaseEntityDatabaseProperty=Hn,y.persistedBuiltInBaseEntityDatabasePropertyDataType=PE,y.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=$w,y.persistedBuiltInBaseEntityDatabasePropertyParentRef=wE,y.persistedBuiltInBaseEntityDatabasePropertyRef=OE,y.persistedBuiltInBaseEntityPrimaryKeyProperty=Kn,y.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=jE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=VE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=CE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=UE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=LE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=_E,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=BE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=NE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=ME,y.processOutputGlobalValueDescriptorDataType=lI,y.processOutputGlobalValueDescriptorReturn=Io,y.processOutputGlobalValueDescriptorReturnRef=oI,y.projectPublicationCompletedGlobalEvent=Eo,y.propertyToZodSchema=wI,y.propertyValidation=VJ,y.relationalDatabaseBuiltInBaseEntity=Dt,y.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Xd,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=AE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=IE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=bE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=EE,y.relationalDatabaseBuiltInBaseEntityDefaultProperty=Kd,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=TE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=mE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=vE,y.relationalDatabaseBuiltInBaseEntityIdentifierProperty=fo,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=oE,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=sE,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=aE,y.relationalDatabaseBuiltInBaseEntityMinSizeProperty=mo,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=yE,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=fE,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=hE,y.relationalDatabaseBuiltInBaseEntityPasswordProperty=yo,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=pE,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=Uw,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDefaultValueParentRef=cE,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=uE,y.relationalDatabaseBuiltInBaseEntityRef=Yn,y.relationalDatabaseBuiltInBaseEntityUsernameProperty=ho,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=dE,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=jw,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=lE,y.resolveActionDescriptorName=i1,y.resolveBaseEntityName=XO,y.resolveBuiltInBaseEntityDataTypeLabel=QO,y.resolveClonedEntityProject=mt,y.resolveConditionOperatorLabel=Gl,y.resolveDataType=jl,y.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Wc,y.resolveDataTypeLabel=$l,y.resolveDefinitionEntityDataTypeLabel=wJ,y.resolveEntityDataTypeLabel=PJ,y.resolveEntityName=x,y.resolveFirstCallsSecond=_W,y.resolveFirstWritesSecond=MW,y.resolvePrimaryKeyProperty=YW,y.resolvePrimitiveEntityName=t1,y.resolveSearchName=e1,y.resolveVariableScope=RJ,y.returnDeclarationValidation=gJ,y.returnStatementValidation=FJ,y.searchStatementErrorGlobalValueDescriptor=nu,y.searchStatementErrorGlobalValueDescriptorDataType=uI,y.searchStatementErrorGlobalValueDescriptorRef=dI,y.searchValidation=YJ,y.sequentialExecutionOperation=lr,y.sequentialExecutionOperationError=Em,y.sequentialExecutionOperationErrorParentRef=Tm,y.sequentialExecutionOperationListOfExecutionResultsDataType=ym,y.sequentialExecutionOperationListOfExecutionResultsReturn=Vd,y.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=vm,y.sequentialExecutionOperationListOfExecutionResultsReturnRef=hm,y.sequentialExecutionOperationListOfFunctionsArgument=Cd,y.sequentialExecutionOperationListOfFunctionsArgumentDatatype=fm,y.sequentialExecutionOperationListOfFunctionsArgumentParentRef=mm,y.sequentialExecutionOperationListOfFunctionsArgumentRef=cm,y.sequentialExecutionOperationListOfFunctionsBlueprint=pm,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=um,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=dm,y.softDeletePersistedEntityMethod=Gw,y.softDeletePersistedEntityMethodParentRef=$E,y.sortCallsBasedOnExecutionDependencies=hP,y.sortChildrenEntitiesBasedOnExecutionDependencies=VW,y.splitListOperation=bd,y.splitListOperationError=cy,y.splitListOperationErrorParentRef=py,y.splitListOperationFirstOutputListDataType=ty,y.splitListOperationFirstOutputListReturn=oy,y.splitListOperationFirstOutputListReturnParentRef=ay,y.splitListOperationFirstOutputListReturnRef=Ad,y.splitListOperationInputListArgument=ry,y.splitListOperationInputListArgumentParentRef=iy,y.splitListOperationInputListArgumentRef=Kh,y.splitListOperationInputListDataType=Xh,y.splitListOperationSecondOutputListDataType=ly,y.splitListOperationSecondOutputListReturn=uy,y.splitListOperationSecondOutputListReturnParentRef=dy,y.splitListOperationSplitIndexArgument=sy,y.splitListOperationSplitIndexArgumentParentRef=ny,y.splitListOperationSplitIndexArgumentRef=Qh,y.splitListOperationSplitIndexDataType=ey,y.splitStringOperation=Ed,y.splitStringOperationError=_h,y.splitStringOperationErrorParentRef=Bh,y.splitStringOperationFirstPartResultStringDataType=Ih,y.splitStringOperationFirstPartResultStringReturn=Vh,y.splitStringOperationFirstPartResultStringReturnParentRef=Ch,y.splitStringOperationFirstPartResultStringReturnRef=Eh,y.splitStringOperationIndexArgument=Ph,y.splitStringOperationIndexArgumentParentRef=Oh,y.splitStringOperationIndexArgumentRef=vh,y.splitStringOperationIndexDataType=Th,y.splitStringOperationSecondPartResultStringDataType=bh,y.splitStringOperationSecondPartResultStringReturn=Nw,y.splitStringOperationSecondPartResultStringReturnParentRef=wh,y.splitStringOperationSecondPartResultStringReturnRef=Ah,y.splitStringOperationStringArgument=Dh,y.splitStringOperationStringArgumentParentRef=Rh,y.splitStringOperationStringArgumentRef=yh,y.splitStringOperationStringDataType=mh,y.stringPrototype=ae,y.stringValueAutogenerationSchema=hp,y.suggestNewIdForEntity=Cc,y.test_primitive_entities_export=$S,y.toCamelCase=DJ,y.toEntityState=Ai,y.toKebabCase=KO,y.toLowerCaseKebabCase=Ul,y.toPascalCase=OJ,y.untypedDataPrototype=wt,y.updateErrorsList=Ke,y.urlDefaultValue=Ym,y.uuidPrototype=ar,y.validateArgumentDeclarationName=Pc,y.validateCalledByErrorIdInAction=mW,y.validateCalledByIdInAction=yW,y.validateCallers=K1,y.validateConditionEntityDeclaration=EW,y.validateDataOperation=pn,y.validateDataOperationDataToValidateArgument=Gm,y.validateDataOperationDataToValidateArgumentParentRef=$m,y.validateDataOperationDataToValidateArgumentRef=jm,y.validateDataOperationDataToValidateDataType=Um,y.validateDataOperationEntityToMatchTypeArgument=km,y.validateDataOperationEntityToMatchTypeArgumentParentRef=xm,y.validateDataOperationEntityToMatchTypeArgumentRef=gm,y.validateDataOperationEntityToMatchTypeDataType=Fm,y.validateDataOperationError=Wm,y.validateDataOperationErrorParentRef=Jm,y.validateDataOperationOutputEntityDeclaration=qm,y.validateDataOperationOutputEntityDeclarationParentRef=Zm,y.validateDefinitionEntityName=bc,y.validateEntryCaller=H1,y.validateErrorCaller=Y1,y.validateFunctionCallDeclaration=Q1,y.validateFunctionDeclarationName=Rc,y.validateGeneratedEntityParentIsNotBuiltInEntity=pW,y.validateGeneration=dW,y.validateGenerationTarget=ut,y.validateGenerationUpdate=uW,y.validateLoopEntityDeclaration=IW,y.validateName=CJ,y.validateOperationEntityDeclaration=eP,y.validatePropertyName=Oc,y.validateReachability=Ar,y.validateReadsValueInActionPayload=vW,y.validateReferenceObject=Fl,y.validateReferenceToOne=Uc,y.validateReferences=bt,y.validateReturnDeclarationName=wc,y.validateSuccessCaller=z1,y.validateValueReaderGenerationUpdate=Na,y.validateValueWritter=kc,y.validateVariableDeclarationName=Dc,y.validateVariableInternalCallUse=Zc,y.valueAutogenerationCurrentDateAndTimeSchema=dD,y.valueAutogenerationGenericSchema=ll,y.valueAutogenerationOptions=vp,y.valueAutogenerationOptionsSchema=lD,y.valueAutogenerationRandomBooleanSchema=fp,y.valueAutogenerationRandomDateBetweenSchema=TD,y.valueAutogenerationRandomDateFromSchema=mD,y.valueAutogenerationRandomDateSchema=pl,y.valueAutogenerationRandomDateUntilSchema=vD,y.valueAutogenerationRandomNumberBetweenSchema=cD,y.valueAutogenerationRandomNumberFromSchema=uD,y.valueAutogenerationRandomNumberSchema=dl,y.valueAutogenerationRandomNumberUntilSchema=pD,y.valueAutogenerationRandomSchema=ha,y.valueAutogenerationRandomTextBetweenSchema=yD,y.valueAutogenerationRandomTextFromSchema=fD,y.valueAutogenerationRandomTextSchema=ul,y.valueAutogenerationRandomTextUntilSchema=hD,y.valueAutogenerationRangeValueTypesSchema=fa,y.valueAutogenerationUniqueSchema=cp,y.valueDescriptorValidation=lW,y.variableDeclarationValidation=SJ,y.variableInstanceValidation=zJ,y.waitOperation=Yt,y.waitOperationMillisecondsNumberArgument=dn,y.waitOperationMillisecondsNumberArgumentRef=im,y.waitOperationMillisecondsNumberDataType=rm,y.waitOperationOperationError=am,y.waitOperationOperationErrorParentRef=sm,y.waitOperationRef=nm,Object.defineProperty(y,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 allBaseMethodsFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>t.type!==n.DefinitionEntity?[]:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[]),...this.implements.reduce((e,t)=>t.type!==n.DefinitionEntity?t.abstractMethods:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...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 extendedMethodsFromOriginalParents(){return p(this.extends.reduce((e,t)=>{if(t.type!==n.DefinitionEntity)return[];const i=[...t.ownDeclaredMethods,...t.extendedMethodsFromOriginalParents].filter(s=>s.type!==n.ActionDescriptor);return[...e,...i]},[]))}get implementedMethodsFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.type===n.DefinitionEntity?t.methods:[],s=[...t.abstractMethods].filter(l=>!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>[...t.abstractMethods,...e],[])].filter(e=>e.type===n.ActionDescriptor))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}get extendedMethods(){return this.methods.filter(e=>e.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(e=>!e.isExtendedMethod)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){return this.implements.forEach(e=>{ni.includes(e.type)||e.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(e=>{ni.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{ni.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 $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.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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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.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;const{updated:o,added:d,removed:u,affected:f}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...f);const{updated:c,added:E,removed:I,affected:D}=this.addExtendedProperties(e);t.push(...c),i.push(...E),s.push(...I),l.push(...D);const{updated:P,added:V,removed:M}=this.removeUnrecognizedProperties(e);t.push(...P),i.push(...V),s.push(...M);const{updated:G,added:B,removed:g,affected:q}=this.syncImplementationMethods(e);t.push(...G),i.push(...B),s.push(...g),l.push(...q);const{updated:S,added:Q,removed:pe,affected:me}=this.addExtendedMethods(e);t.push(...S),i.push(...Q),s.push(...pe),l.push(...me);const{updated:X,added:oe,removed:gt}=this.removeUnrecognizedMethods(e);return t.push(...X),i.push(...oe),s.push(...gt),this.addSuggestions(),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=[];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)}removeUnrecognizedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-properties"))){const t=[],i=[],s=[],l=[];let o=[...this.properties];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedProperty);const d=this.implementedPropertiesFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-methods"))){const t=[],i=[],s=[],l=[];let o=[...this.methods];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedMethod);const d=this.implementedMethodsFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,d=this.implementedMethodsFromOriginalParents,u=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})).forEach(c=>{if(this.methods.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===c.id}))return;const I=this.methods.find(P=>{var g,q;if(P.name===c.name&&!P.implements)return!0;const V=ka(this,W.CRON_JOB),M=ka(this,W.HTTP_ENDPOINT),G=((g=P.implements)==null?void 0:g.id)===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,B=((q=P.implements)==null?void 0:q.id)===k["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(V&&!B&&!M&&G||M&&!G&&!V&&B)});if(I&&I.type===n.FunctionDeclaration){I.setImplements(c),I.metaSync({name:c.name},e),e==null||e.add(I,A.Updated),e==null||e.add(this,A.Updated);return}const D=c.implementAsFunctionDeclaration(e,this);i.push(D),e==null||e.add(D,A.Added),this.addMethod(D)}),e==null||e.attemptAutoclose("sync-implementation-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self: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(I=>{var D;return((D=I.implements)==null?void 0:D.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 I=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(I){I.implements=c,I.abstract=!1;return}const D=c.clone(e,this,m.UUID.uuid());D.initChildren(e),i.push(D),e==null||e.add(D,A.Added),D.setImplements(c,e),D.metaSync({abstract:!1},e),this.addProperty(D)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,u=this.extendedMethodsFromOriginalParents.filter(c=>c.type===n.FunctionDeclaration),f=new Set(o.filter(c=>{var E;return!!((E=c.extends)!=null&&E.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const E=c.clone(e,this,m.UUID.uuid());E.setExtends(c,e),E.initChildren(e),i.push(E),e==null||e.add(E,A.Added),this.addMethod(E)}),e==null||e.attemptAutoclose("add-extended-methods",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(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})?!1:!c.abstract),f=new Set(o.filter(c=>{var E;return!!((E=c.extends)!=null&&E.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const E=c.clone(e,this,m.UUID.uuid());E.setExtends(c,e),E.initChildren(e),i.push(E),e==null||e.add(E,A.Added),this.addProperty(E)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{fw(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)}),hw(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(f=>{f.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!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await $e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await $e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await $e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await $e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await $e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,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.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.methods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),!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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),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=J){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||yt(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=J){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=J){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=cw(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"),f=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=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const E=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=E;const I=(V=this.methods)==null?void 0:V.map((G,B)=>G.clone(e,c,f+"-method-"+B+"-id",s));c.methods=I;const D=(M=this.abstractMethods)==null?void 0:M.map((G,B)=>G.clone(e,c,f+"-abstract-method-"+B+"-id",s));return c.abstractMethods=D,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=zl(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(I=>x(I,this.project)===x(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const E=u.find(B=>x(B,this.project)===x(c,this.project));if(!E)return;const D=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=Ui(D,t),V=P==null?void 0:P.clone(t,E,m.UUID.uuid(),!0);if(V){const B=(M=E.dataType)==null?void 0:M.merge(V,t);E.dataType&&(B==null?void 0:B.self.id)!==E.dataType.id&&E.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),E.setDataType(B.self),t==null||t.add(E,A.Updated))}c.setDeclaration(E),t==null||t.add(c,A.Updated)});const f=[];return d.forEach(c=>{if(!c.declaration){f.push(c);return}}),f.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(f.forEach(c=>{var B,g,q,S;const E=this.properties.find(Q=>x(Q,this.project)===x(c,this.project));if(E){if(c.setDeclaration(E),!E.getDataType(t)){const pe=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),me=Ui(pe),X=me==null?void 0:me.clone(t,E,m.UUID.uuid(),!0);if(X){const oe=(B=E.dataType)==null?void 0:B.merge(X,t);E.dataType&&(oe==null?void 0:oe.self.id)!==E.dataType.id&&E.dataType.remove({ignoreUpstream:!1},t),X.id!==((g=oe==null?void 0:oe.self)==null?void 0:g.id)&&X.remove({ignoreUpstream:!1},t),oe!=null&&oe.self&&(oe.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(oe.self,A.Added),E.setDataType(oe.self),t==null||t.add(E,A.Updated))}}return}const I={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,extends:null,dataType:null,parent:this.toReference()},D=C(I,this.project);D.setParent(this,t),D.initChildren(t),t==null||t.add(D,A.Added);const V=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=Ui(V),G=M==null?void 0:M.clone(t,D,m.UUID.uuid(),!0);if(G){const Q=(q=D.dataType)==null?void 0:q.merge(G,t);D.dataType&&(Q==null?void 0:Q.self.id)!==D.dataType.id&&D.dataType.remove({ignoreUpstream:!1},t),G.id!==((S=Q==null?void 0:Q.self)==null?void 0:S.id)&&G.remove({ignoreUpstream:!1},t),Q!=null&&Q.self&&(Q.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(Q.self,A.Added),D.setDataType(Q.self),t==null||t.add(D,A.Updated))}return this.addProperty(D),c.setDeclaration(D),t==null||t.add(c,A.Updated),D}),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})}};h($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}),h($e,"type",n.DefinitionEntity),h($e,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),h($e,"PARENT_TYPES",[...$e.USER_MANAGED_PARENT_TYPES]),h($e,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),h($e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h($e,"BASE_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"MUTABLE_META_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,"x","y"]),h($e,"INMUTABLE_META_PROPERTIES",[...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"META_PROPERTIES",[...$e.MUTABLE_META_PROPERTIES,...$e.INMUTABLE_META_PROPERTIES]),h($e,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),h($e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h($e,"UPSTREAM_PROPERTIES",[...$e.MUTABLE_UPSTREAM_PROPERTIES,...$e.INMUTABLE_UPSTREAM_PROPERTIES]),h($e,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),h($e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h($e,"DOWNSTREAM_PROPERTIES",[...$e.MUTABLE_DOWNSTREAM_PROPERTIES,...$e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h($e,"PROPERTIES",[...$e.META_PROPERTIES,...$e.UPSTREAM_PROPERTIES,...$e.DOWNSTREAM_PROPERTIES]);let on=$e;function hS(r){const a=d5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const Ja=class Ja extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"version");h(this,"name");h(this,"description",null);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",!1);h(this,"static");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"interactive",!1);h(this,"errors",[]);h(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=U,...t){return await Ja.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=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){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=hS(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=zl(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 Ja&&e.push(...i.getAllInteractiveMethods())})),p(e)}};h(Ja,"repository",{APILoad:async(e,...t)=>null});let Gi=Ja;function yS(r){const a=e5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const ld=class ld extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"type",n.PrimitiveEntity);h(this,"static");h(this,"abstract");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(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=U,...t){return await ld.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=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){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=yS(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 Gi&&e.push(...i.getAllInteractiveMethods())}),p(e)}};h(ld,"repository",{APILoad:async(e,...t)=>null});let ri=ld;function st(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 Xr(r,a);case n.DefinitionEntity:return e||new on(r,a);case n.PrimitiveEntity:return e||new ri(r,a);case n.FunctionDeclaration:return e||new Fr(r,a);case n.GlobalEvent:return e||new qr(r,a);case n.DataType:return e||new xr(r,a);case n.Property:return e||new gr(r,a);case n.FunctionCall:return e||new nn(r,a);case n.Condition:return e||new Wr(r,a);case n.Operation:return e||new kr(r,a);case n.VariableDeclaration:return e||new zr(r,a);case n.VariableInstance:return e||new Sr(r,a);case n.OutputMap:return e||new Qi(r,a);case n.ReturnDeclaration:return e||new ii(r,a);case n.ArgumentDeclaration:return e||new Ir(r,a);case n.InputMap:return e||new Xi(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Hr(r,a);case n.ActionDescriptor:return e||new We(r,a);case n.ReturnStatement:return e||new Zr(r,a);case n.Loop:return e||new Jr(r,a);case n.Search:return e||new Yr(r,a);case n.ValueDescriptor:return e||new er(r,a);case n.BuiltInBaseEntity:return e||new Gi(r,a);case n.InternalCall:return e||new Kr(r,a);case n.ContinueStatement:return e||new $t(r,a);case n.BreakStatement:return e||new Qr(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=st(r,a);return e.subscribe(),e}function mS(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return Xr.fromGenerationTarget(r,a);case n.DefinitionEntity:return on.fromGenerationTarget(r,a);case n.FunctionDeclaration:return Fr.fromGenerationTarget(r,a);case n.GlobalEvent:return qr.fromGenerationTarget(r,a);case n.DataType:return xr.fromGenerationTarget(r,a);case n.Property:return gr.fromGenerationTarget(r,a);case n.FunctionCall:return nn.fromGenerationTarget(r,a);case n.Condition:return Wr.fromGenerationTarget(r,a);case n.Operation:return kr.fromGenerationTarget(r,a);case n.VariableDeclaration:return zr.fromGenerationTarget(r,a);case n.VariableInstance:return Sr.fromGenerationTarget(r,a);case n.OutputMap:return Qi.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ii.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return Ir.fromGenerationTarget(r,a);case n.InputMap:return Xi.fromGenerationTarget(r,a);case n.InstalledProject:return Hr.fromGenerationTarget(r,a);case n.ReturnStatement:return Zr.fromGenerationTarget(r,a);case n.Loop:return Jr.fromGenerationTarget(r,a);case n.Search:return Yr.fromGenerationTarget(r,a);case n.ActionDescriptor:return We.fromGenerationTarget(r,a);case n.ValueDescriptor:return er.fromGenerationTarget(r,a);case n.InternalCall:return Kr.fromGenerationTarget(r,a);case n.ContinueStatement:return $t.fromGenerationTarget(r,a);case n.BreakStatement:return Qr.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const J={seenEntityMaps:new Map,seenEntities:new Set,timestamp:T().toISOString()};class yw{constructor(){h(this,"initialData")}}const U={cascade:!1},mw={APILoad:async(r,...a)=>null},vS={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,...mw};class TS{}class ES extends yw{}class IS{}class AS{}class bS{}class sf{}class RS extends sf{}class DS extends sf{}class OS{}class Rr{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=Ai(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.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=Ai(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.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 Za{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),it.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class PS{}const re=class re extends lt{constructor(e){super(e);h(this,"initialData");h(this,"id");h(this,"type",n.Project);h(this,"name",null);h(this,"description",null);h(this,"x");h(this,"y");h(this,"entities",[]);h(this,"projects",[]);h(this,"functions",[]);h(this,"events",[]);h(this,"variableDeclarations",[]);h(this,"variableInstances",[]);h(this,"conditions",[]);h(this,"operations",[]);h(this,"functionCalls",[]);h(this,"loops",[]);h(this,"searches",[]);h(this,"primitives",[]);h(this,"builtInBaseEntities",[]);h(this,"operationDeclarations",[]);h(this,"globalEventActionDescriptors",[]);h(this,"loopDeclarations",[]);h(this,"loopDeclarationsBodies",[]);h(this,"conditionDeclarations",[]);h(this,"valueDescriptors",[]);h(this,"dataTypes",[]);h(this,"project");h(this,"instances",{});h(this,"builtInInstances",{});h(this,"deletedInstances",{});h(this,"errors",[]);h(this,"references",[]);h(this,"history",[]);h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(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{(!re.UUID||re.UUID.isBackup)&&(re.UUID=Jo==null?void 0:Jo()),re.UUID||(re.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),re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){re.UUID=e}static new(e=null){return{id:re.UUID.uuid(),version:re.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||re.sessionAuthor,previousVersion:null,deleted:!1,type:n.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingChangeSets(){const e=this.history.find(t=>t.dirty&&!t.open);e&&await this.closeChangeSet(e)}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingChangeSets()}async closeChangeSet(e){const t=this.history.findIndex(l=>l.id===e.id),i=this.history.slice(0,t),s=i[i.length-1];if(!(s!=null&&s.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(e)).success&&(e.dirty=!1,this.closePendingChangeSets());return}}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.warn("Previous still open: ",i),console.warn("New change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>T(e==null?void 0:e.timestamp).isBefore(T(l==null?void 0:l.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),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}}unsubscribeFromDependencies(){return 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=re.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);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[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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)}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.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,re.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,re.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?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=U,...t){return await re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,re.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,re.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,re.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=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+re.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){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=O7(),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=Ee(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=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=He(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=Ee(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=Ee(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===W.PERSISTED_ENTITY)||null}};h(re,"sessionAuthor","1"),h(re,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),h(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}),h(re,"type",n.Project),h(re,"USER_MANAGED_PARENT_TYPES",[]),h(re,"PARENT_TYPES",[...re.USER_MANAGED_PARENT_TYPES]),h(re,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(re,"BASE_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,...re.INMUTABLE_BASE_PROPERTIES]),h(re,"MUTABLE_META_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,"x","y"]),h(re,"INMUTABLE_META_PROPERTIES",[...re.INMUTABLE_BASE_PROPERTIES]),h(re,"META_PROPERTIES",[...re.MUTABLE_META_PROPERTIES,...re.INMUTABLE_META_PROPERTIES]),h(re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(re,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),h(re,"UPSTREAM_PROPERTIES",[...re.MUTABLE_UPSTREAM_PROPERTIES,...re.INMUTABLE_UPSTREAM_PROPERTIES]),h(re,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),h(re,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(re,"DOWNSTREAM_PROPERTIES",[...re.MUTABLE_DOWNSTREAM_PROPERTIES,...re.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(re,"PROPERTIES",[...re.META_PROPERTIES,...re.UPSTREAM_PROPERTIES,...re.DOWNSTREAM_PROPERTIES]);let m=re;var vw=(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))(vw||{});class Tw extends We{constructor(e){super(Bi,e);h(this,"id",Qe.Parallel);h(this,"name",Qe.Parallel);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",Bi);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Bi.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Bi.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Bi.error?C(Bi.error,this.project):null}}class Ew extends We{constructor(e){super(Yt,e);h(this,"id",Yt.id);h(this,"name",Yt.name);h(this,"description",Yt.description);h(this,"version",Yt.version);h(this,"autoexecutable",!1);h(this,"initialData",Yt);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Yt.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Yt.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Yt.error?C(Yt.error,this.project):null}}class Iw extends We{constructor(e){super(lr,e);h(this,"id",Qe.Sequential);h(this,"name",Qe.Sequential);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",lr);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=lr.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=lr.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=lr.error?C(lr.error,this.project):null}}class wS extends We{constructor(a){super(Ns,a)}}class CS extends We{constructor(a){super(un,a)}}class VS extends We{constructor(e){super(pn,e);h(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[tt.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[tt.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[tt.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:E,removed:I,affected:D}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...E),s.push(...c),l.push(...I),o.push(...D)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:E,removed:I,affected:D}=this.syncDataToValidateInputMapDataType(u,t);i.push(...E),s.push(...c),l.push(...I),o.push(...D)}const f=this.getOutputDataOutputMap(e);if(f){const{added:c,updated:E,removed:I,affected:D}=this.syncOutputDataOutputMapDataType(f,t);i.push(...E),s.push(...c),l.push(...I),o.push(...D)}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,f,c;const i=[],s=[],l=[],o=[];if(((u=e.declaration)==null?void 0:u.id)!==k.operation[tt.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 E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},I=C(E,e.project);I.setParent(e,t),I.initChildren(t),t==null||t.add(I,A.Added),i.push(I),e.setDataType(I)}(f=e.dataType)==null||f.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,E,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[tt.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 D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(D,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(E=e.dataType)==null||E.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(f),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,E,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[tt.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 D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(D,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(E=e.dataType)==null||E.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(f),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 s,l;if(((s=e.declaration)==null?void 0:s.id)===k.operation[tt.Validate].inputs.dataToValidate.id){const{added:o,updated:d,removed:u,affected:f}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(d),added:p(o),removed:p(u),affected:p(f),self:e.dataType}}const i=(l=e.declaration)==null?void 0:l.getDataType(t);if(i&&i.isResolved)return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:i};if(e.readsValue){const o=Ui(e.readsValue,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:o}}return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{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[tt.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 BS extends We{constructor(a){super(Id,a)}}class _S extends We{constructor(a){super(bd,a)}}class MS extends We{constructor(a){super(Rd,a)}}class NS extends We{constructor(a){super(Qa,a)}}class LS extends We{constructor(a){super(Ha,a)}}class jS extends We{constructor(a){super(Ms,a)}}function US(r){const a=[new Iw(r),new Tw(r),new Ew(r),new wS(r),new CS(r),new VS(r),new NS(r),new BS(r),new MS(r),new _S(r),new LS(r),new jS(r),new We(Ed,r),new We(Td,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class Aw extends Gi{constructor(e){super(Mt,e);h(this,"initialData");h(this,"id",W.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",W.PERSISTED_ENTITY);h(this,"description",Mt.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Mt.abstract);h(this,"static",Mt.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=Mt,this.project=e,this.id=Mt.id,this.version=Mt.version,this.name=Mt.name,this.static=Mt.static,this.abstract=Mt.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))}}var bw=(r=>(r.StatusCodeMustBeNumber="status-code-must-be-number",r.StatusCodeMustBeBetween100And599="status-code-must-be-between-100-and-599",r))(bw||{});function Rw(r,a){const e=[];if(typeof a!="number"){const t=new Ye({id:r.id+"--status-code-must-be-number",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number.`,issue:null,severity:O.Error,code:"status-code-must-be-number",entity:r});return e.push(t),{errors:e,override:a}}if(a<100){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}if(a>599){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}return{errors:e,override:a}}class Dw extends Gi{constructor(e){super(si,e);h(this,"initialData");h(this,"id",W.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",W.PERSISTED_ENTITY);h(this,"description",si.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",si.abstract);h(this,"static",si.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=si,this.project=e,this.id=si.id,this.version=si.version,this.name=si.name,this.static=si.static,this.abstract=si.abstract,this.properties=this.initialData.properties.map(l=>{const o=C(l,this.project);return o.setParent(this,null),o.initChildren(null),o}),this.methods=this.initialData.methods.map(l=>{const o=C(l,this.project);return o.parent=this,o}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const o=C(l,this.project);return o.parent=this,o}),this.extends=this.initialData.extends.map(l=>C(l,this.project));const t=this.properties.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.path.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(l,o)=>lP(l,o);const i=this.abstractMethods.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id);if(!i)throw new Error("Handler method not found in endpoint entity");const s=i.outputs.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.outputs.statusCode.id);if(!s)throw new Error("Status code output not found in handler method");s.codeNativeValueValidation=(l,o)=>Rw(l,o)}}const $S="test_primitive_entities_export";class GS extends Gi{constructor(e){super(Dt,e);h(this,"initialData");h(this,"id",W.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",W.PERSISTED_ENTITY);h(this,"description",Dt.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Dt.abstract);h(this,"static",Dt.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=Dt,this.project=e,this.id=Dt.id,this.version=Dt.version,this.name=Dt.name,this.static=Dt.static,this.abstract=Dt.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}),this.extends=this.initialData.extends.map(i=>C(i,this.project));const t=this.properties.find(i=>i.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(i,s)=>dP(i,s)}}function gS(r){const a=[new Aw(r),new Dw(r),new GS(r),new Gi(Dt,r),new Gi(vo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function FS(r){const a=[new ri(ae,r),new ri(nr,r),new ri(Te,r),new ri(cd,r),new ri(wt,r),new ri(sr,r),new ri(xi,r),new ri(ar,r),new ri(qn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function xS(r){const a=[new We(Eo,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function kS(r){const a=[new We($s,r),new We(Or,r),new We(js,r),new We(Sn,r),new We(zn,r),new We(oo,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new We(co,r),new We(Us,r),new We(uo,r),new We(Ud,r),new We(Gd,r),new We(lo,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function ZS(r){const a=[new er(Io,r),new er(nu,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function qS(r){const a=[new We(mn,r),new We(Qn,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Gn={},sd={},qa={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function Ow(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new Sl(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=ad(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new b(o,m.sessionAuthor,l,o,!0,"project-init-from-fetch-result")):null;return i.visit(u=>{if(u.id===o.id)return;const f=C(u,o);f.hydrateAncestors(),f.addSelfToProject(null)}),a?(i.visit(u=>{const f=o.get(u.id);f&&f.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):od(o,l).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.attemptAutoclose("project-init-from-fetch-result",o.id),o}async function JS(r,a=qa){const e={...qa,...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={...pp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{try{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})}catch(s){console.error("Error fetching project: ",s),i({data:null})}})}function ad(r){const a=new m(r);return FS(a),gS(a),US(a),xS(a),kS(a),ZS(a),qS(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 od(r,a){return r.instancesList.filter(t=>T(t.createdAt).isAfter(T(a)||!!t.previousVersion))}function WS(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 f=r.get(u);if(!rd(f,{...r.instances,...r.builtInInstances}).every(I=>!t.includes(I))){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=ad(s),o=a?l.addChangeSet(new b(l,m.sessionAuthor,i,l,!0,"project-clone")):null,d=new Sl(r);return d.visit(u=>{const f=u.toShallowJSON({seenEntityMaps:e});u.type===n.ValueDescriptor&&u.name==="Iteration result"&&(console.log("Og entity shallow copy: ",f),console.log("Og entity full: ",u)),f.previousVersion=null,f.createdAt=i,f.version=m.UUID.uuid();const c=C(f,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,A.Added)}),a?(d.visit(u=>{const f=l.get(e.get(u.id));f&&f.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):od(l,i).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.attemptAutoclose("project-clone",l.id),l}function Pw(r,{enrich:a}={enrich:!0}){const e=ad(r),t=T().toISOString(),i=a?e.addChangeSet(new b(e,m.sessionAuthor,t,e,!0,"project-init")):null;i&&(i.type=Vc.Automatic);const s=new Sl(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)):od(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.attemptAutoclose("project-init",e.id),e}async function SS(r,a=qa){const e={...qa,...a};if(r.id&&Gn[r.id]&&!e.ignoreCache)return Gn[r.id];if(r.id&&sd[r.id]&&!e.ignoreCache)return await sd[r.id],Gn[r.id];const t=JS(r,e);r.id&&(sd[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=Pw(pp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=Ow(i.data,{enrich:!!e.enrich}),Gn[r.id]=s,r.id&&delete sd[r.id],s}return null}function zS(r){return Gn[r.id]&&delete Gn[r.id],null}y.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=xc,y.ALL_BUILT_IN_BASE_ENTITIES=qE,y.ALL_BUILT_IN_CONDITION_ENTITIES=nI,y.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=aI,y.ALL_BUILT_IN_LOOP_BODY_ENTITIES=TT,y.ALL_BUILT_IN_LOOP_ENTITIES=vT,y.ALL_BUILT_IN_OPERATION_ENTITIES=V0,y.ALL_BUILT_IN_PRIMITIVE_ENTITIES=vf,y.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=cI,y.ALL_BUILT_IN_VALUE_DESCRIPTORS=pI,y.ActionDescriptorState=We,y.ActionInputMapState=eW,y.ActionOutputMapState=rW,y.AppendToListOperationInputIds=Oy,y.AppendToListOperationOutputIds=Py,y.ArgumentDeclarationDependencyField=$1,y.ArgumentDeclarationState=Ir,y.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=$c,y.BUILT_IN_BASE_ENTITY_IDS=k,y.BUILT_IN_ENTITY_TYPES=ni,y.BaseCanvasDraggableState=IS,y.BaseEntityNames=W,y.BaseState=ES,y.BaseValueDescriptorIds=Zn,y.BreakStatementDependencyField=x1,y.BreakStatementState=Qr,y.BuiltInBaseEntityState=Gi,y.CACHED_PROJECTS_BY_ID=Gn,y.CALLABLE_ENTITIES_EXPLANATION=cW,y.CALLABLE_TYPES=gi,y.CALLER_ENTITIES_EXPLANATION=W1,y.CALLER_TYPES=Fi,y.CALLS_UPDATE_EXPLANATION=tn,y.COMPARISON_CONDITIONS=iI,y.CONDITIONS=rI,y.CUSTOM_ENTITY_OPERATIONS=Sm,y.CallableEntityClass=bS,y.CallerEntityClass=sf,y.ChangeSet=b,y.ChangeSetChangeCaptureType=Vc,y.ChangeSetEntityChangeType=A,y.ChildEntityState=AS,y.CommonStringValidationErrorCodes=oP,y.ComparisonOperatorTypes=ft,y.ConditionDependencyField=b1,y.ConditionState=Wr,y.ContinueStatementDependencyField=m1,y.ContinueStatementState=$t,y.CreateNewInputIds=Am,y.CreateNewOutputIds=bm,y.DRAGGABLE_CALLABLE_TYPES=pd,y.DRAGGABLE_CALLER_TYPES=df,y.DRAGGABLE_ELEMENT_TYPES=Ya,y.DRAGGABLE_EXECUTABLE_TYPES=_w,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=za,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=ud,y.DataTypeCompatibilityTypes=Pi,y.DataTypeDependencyField=Bc,y.DataTypeParentChildRelation=Pt,y.DataTypeState=xr,y.DefinitionEntityDependencyField=nd,y.DefinitionEntityState=on,y.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=vS,y.ENTITIES_WITH_VALLUES_EXPLANATION=kl,y.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=U,y.ENTITY_RECUSION_OPTIONS_DEFAULTS=J,y.ENTITY_TYPES=Mw,y.ENTITY_WITH_DECLARATION_TYPES=Vw,y.ENTITY_WITH_LOGIC_SCOPE_TYPES=ht,y.ENTITY_WITH_NAMES_TYPES=uf,y.ENTITY_WITH_PARENT_TYPES=ww,y.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=of,y.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=Cw,y.ENTITY_WITH_VALUE_TYPES=af,y.ENTRY_POINT_ENTITIES_EXPLANATION=Ma,y.ENTRY_POINT_TYPES=rt,y.EVENT_TYPES=kn,y.EXECUTABLE_TYPES=Bw,y.EXECUTION_OPERATIONS=Im,y.EndpointEntity=Dw,y.EntityAction=vw,y.EntityError=Ye,y.EntityErrorSeverity=O,y.EntityGenerationError=w,y.EntityGenerationErrorCode=R,y.EntityInstanceErrorCode=F,y.EntityOperations=tt,y.EntityType=n,y.EntityWithLogicScopeClass=PS,y.EntityWithValueClass=OS,y.EntryPointEntityClass=RS,y.ExecutionOperations=Qe,y.ExecutionTerminationType=E1,y.FunctionCallDependencyField=rP,y.FunctionCallState=nn,y.FunctionDeclarationDependencyField=l1,y.FunctionDeclarationState=Fr,y.GET_PROJECT_OPTIONS_DEFAULTS=qa,y.GLOBAL_EVENT_DECLARATIONS=sI,y.GetLastInListOperationInputIds=fy,y.GetLastInListOperationOutputIds=hy,y.GlobalEventNames=rr,y.GlobalEventState=qr,y.HTTPOperations=jt,y.HTTPStatucCodeValidationErrorCodes=bw,y.HTTP_OPERATIONS=w0,y.InputMapDependencyField=N1,y.InputMapState=Xi,y.InstalledProjectState=Hr,y.InternalCallDependencyField=_1,y.InternalCallState=Kr,y.JoinListOperationInputIds=Nh,y.JoinListOperationOutputIds=Lh,y.LIST_OPERATIONS=gy,y.ListOperations=ye,y.LiteralValueDependencyField=g1,y.LiteralValueState=Xr,y.LoopDependencyField=I1,y.LoopState=Jr,y.LoopTypes=ee,y.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=rn,y.NUMBER_OPERATIONS=Sf,y.NumberOperations=et,y.OPERATION_DECLARATIONS=C0,y.OperationDependencyField=p1,y.OperationState=kr,y.OutputMapDependencyField=j1,y.OutputMapParentChildRelation=xn,y.OutputMapState=Qi,y.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Zl,y.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=en,y.PASS_THROUGH_CALLABLE_TYPES=dt,y.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=lf,y.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Fc,y.ParallelExecutionOperation=Tw,y.PassThroughCallableEntityClass=DS,y.PersistedEntity=Aw,y.PersistedEntityMethods=fi,y.PrimitiveEntityState=ri,y.PrimitiveTypes=N,y.ProjectState=m,y.PropertyDependencyField=a1,y.PropertyState=gr,y.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=mw,y.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=fW,y.ReturnDeclarationDependencyField=f1,y.ReturnDeclarationState=ii,y.ReturnStatementDependencyField=_c,y.ReturnStatementState=Zr,y.STANDALONE_CONDITIONS=SE,y.STRING_OPERATIONS=Mh,y.ScopeCompatibilityType=td,y.SearchDependencyField=w1,y.SearchState=Yr,y.SequentialExecutionOperation=Iw,y.SequentialExecutionOperationInputIds=om,y.SequentialExecutionOperationOutputIds=lm,y.SharedEntityErrorCode=$,y.SharedStateFunctionality=yw,y.SplitListOperationInputIds=Yh,y.SplitListOperationOutputIds=Hh,y.StandaloneOperatorTypes=bi,y.StringOperations=Ae,y.TERMINATION_TYPES=ot,y.Traverser=Sl,y.USER_MANAGED_ENTITY_TYPES=pf,y.UserManagedEntityStateTemplate=TS,y.VALUE_READING_ENTITIES_EXPLANATION=gc,y.VALUE_READING_TYPES=Dr,y.VALUE_WRITING_ENTITIES_EXPLANATION=S1,y.VALUE_WRITING_TYPES=Tt,y.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=Gc,y.VARIABLE_TYPES=it,y.ValueAutogenerationType=vt,y.ValueDescriptorDependencyField=Z1,y.ValueDescriptorParentChildRelation=L,y.ValueDescriptorState=er,y.ValueReadingEntityClass=Rr,y.ValueWritingEntityClass=Za,y.VariableDeclarationDependencyField=O1,y.VariableDeclarationState=zr,y.VariableInputMapState=QJ,y.VariableInstanceDependencyField=Nc,y.VariableInstanceState=Sr,y.VariableOutputMapState=iW,y.WaitOperation=Ew,y.WaitOperationInputIds=em,y.WaitOperationOutputIds=tm,y.actionDescriptorValidation=JJ,y.appendToListOperation=Qa,y.appendToListOperationElementToAppendArgument=Od,y.appendToListOperationElementToAppendArgumentParentRef=Ly,y.appendToListOperationElementToAppendArgumentRef=Vy,y.appendToListOperationError=Gy,y.appendToListOperationErrorParentRef=$y,y.appendToListOperationListArgument=Dd,y.appendToListOperationListArgumentParentRef=Ny,y.appendToListOperationListArgumentRef=wy,y.appendToListOperationListDataType=Cy,y.appendToListOperationResultListDataType=My,y.appendToListOperationResultListReturn=Uy,y.appendToListOperationResultListReturnParentRef=jy,y.appendToListOperationResultListReturnRef=_y,y.appendToListOperationSecondListDataType=By,y.applyNewScope=K,y.argumentDeclarationValidation=nW,y.asGenerationActionExample=tr,y.booleanPrototype=nr,y.breakStatementValidation=oW,y.calculateNewParentBasedOnCallers=Sc,y.capitalizeFirstLetter=Vt,y.changeSetJSONRecordToUniqueIds=_J,y.checkAreDataTypesCompatible=wi,y.checkAreDefinitionEntitiesCompatibleAsDataType=JO,y.checkArePropertiesCompatibleAsDataType=qO,y.checkExtendsBaseEntity=id,y.checkHasBaseEntity=ka,y.checkHasMetadataChanged=pt,y.checkImplementationsOverlap=br,y.checkImplementsBaseEntity=WW,y.checkIsBranchDependentButNotDirectlyOnBranch=La,y.checkIsBranchDependentOnBranch=PW,y.checkIsCallableEntityReachable=xa,y.checkIsCanvasEntity=qW,y.checkIsDetachedBranch=aw,y.checkIsDetachedBranchShallow=rf,y.checkIsGlobalVariable=kW,y.checkIsGloballyDeclared=tf,y.checkIsMethod=dw,y.checkIsNestedScope=ed,y.checkScopeCompatibility=Fa,y.cloneProject=WS,y.conditionValidation=WJ,y.continueStatementValidation=xJ,y.convertToAbstract=bW,y.convertToNonAbstract=RW,y.convertToNonStatic=OW,y.convertToStatic=DW,y.countedLoopActionDescriptor=$s,y.countedLoopActionDescriptorDynamicReturnDeclaration=dT,y.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=lT,y.countedLoopActionDescriptorStringArgumentDeclaration=oT,y.countedLoopActionDescriptorStringArgumentDeclarationDataType=sT,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=rT,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=iT,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=nT,y.countedLoopActionDescriptorStringArgumentDeclarationParentRef=aT,y.countedLoopBodyActionDescriptor=co,y.countedLoopBodyActionDescriptorAnyDynamicArgument=hT,y.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=fT,y.countedLoopBodyActionDescriptorAnyDynamicReturn=mT,y.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=yT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Fd,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=pT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=uT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=cT,y.createDefinitionEntityFromJSONObject=Yl,y.createEntityError=ue,y.createNestedDataTypeForEntity=aP,y.createNewInstanceOperation=un,y.createNewInstanceOperationEntityToInstanciateArgument=Bm,y.createNewInstanceOperationEntityToInstanciateArgumentRef=wm,y.createNewInstanceOperationEntityToInstanciateDataType=Cm,y.createNewInstanceOperationError=Lm,y.createNewInstanceOperationErrorParentRef=Nm,y.createNewInstanceOperationNewEntityDataArgument=Pm,y.createNewInstanceOperationNewEntityDataArgumentDataType=Om,y.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Dm,y.createNewInstanceOperationNewEntityDataArgumentParentRef=Rm,y.createNewInstanceOperationOutputEntityDeclaration=Mm,y.createNewInstanceOperationOutputEntityDeclarationParentRef=_m,y.createNewInstanceOperationRef=Vm,y.createSemanticId=r1,y.createStateFromGenerationTargetType=mS,y.createStateFromType=st,y.createStateFromTypeAndSubscribe=C,y.cronJobBuiltInBaseEntity=vo,y.cronJobBuiltInBaseEntityExpressionProperty=kE,y.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Fw,y.cronJobBuiltInBaseEntityExpressionPropertyRef=FE,y.cronJobBuiltInBaseEntityRef=xE,y.cronJobTriggeredFunctionDeclarationBlueprint=eu,y.cronJobTriggeredFunctionDeclarationBlueprintParentRef=GE,y.dataTypeCompatibilityToErrorExplanation=tP,y.dataTypeValidation=jJ,y.datePrototype=xi,y.dateValueAutogenerationSchema=mp,y.definitionEntityToZodSchema=CI,y.definitionEntityValidation=cS,y.deletePersistedEntityMethod=Qd,y.deletePersistedEntityMethodParentRef=RE,y.deleteRootProject=zS,y.endpointBuiltInBaseEntity=si,y.endpointBuiltInBaseEntityRef=bT,y.endpointBuiltInBaseEntityRefFour=nE,y.endpointBuiltInBaseEntityRefThree=_T,y.endpointBuiltInBaseEntityRefTwo=wT,y.endpointBuiltInCorsProperty=RT,y.endpointBuiltInCorsPropertyDataType=AT,y.endpointBuiltInCorsPropertyDataTypeRef=ET,y.endpointBuiltInCorsPropertyRef=IT,y.endpointBuiltInMethodProperty=kd,y.endpointBuiltInMethodPropertyDataType=BT,y.endpointBuiltInMethodPropertyDataTypeRef=CT,y.endpointBuiltInMethodPropertyRef=VT,y.endpointBuiltInPathProperty=xd,y.endpointBuiltInPathPropertyDataType=PT,y.endpointBuiltInPathPropertyDataTypeRef=DT,y.endpointBuiltInPathPropertyRef=OT,y.endpointPathParamsArgumentDeclaration=qd,y.endpointPathParamsArgumentDeclarationRef=xT,y.endpointPathParamsVariableDataType=kT,y.endpointPathParamsVariableDataTypeRef=FT,y.endpointReachedTriggerActionDescriptor=Hd,y.endpointReachedTriggerActionDescriptorRef=ZT,y.endpointReachedTriggerActionDescriptorRefFour=WT,y.endpointReachedTriggerActionDescriptorRefThree=JT,y.endpointReachedTriggerActionDescriptorRefTwo=qT,y.endpointRequestBodyArgumentDeclaration=Wd,y.endpointRequestBodyArgumentDeclarationRef=jT,y.endpointRequestBodyVariableDataType=UT,y.endpointRequestHeadersArgumentDeclaration=Zd,y.endpointRequestHeadersArgumentDeclarationRef=NT,y.endpointRequestHeadersVariableDataType=LT,y.endpointRequestHeadersVariableDataTypeRef=MT,y.endpointRequestQueryParamsArgumentDeclaration=Jd,y.endpointRequestQueryParamsArgumentDeclarationRef=GT,y.endpointRequestQueryParamsVariableDataType=gT,y.endpointRequestQueryParamsVariableDataTypeRef=$T,y.endpointResponseBodyDataType=iE,y.endpointResponseBodyReturnDeclaration=Yd,y.endpointResponseBodyReturnDeclarationRef=tE,y.endpointResponseCodeDataType=zT,y.endpointResponseCodeReturnDeclaration=Sd,y.endpointResponseCodeReturnDeclarationDefaultValueParentRef=HT,y.endpointResponseCodeReturnDeclarationRef=ST,y.endpointResponseHeadersDataType=QT,y.endpointResponseHeadersDataTypeRef=KT,y.endpointResponseHeadersReturnDeclaration=zd,y.endpointResponseHeadersReturnDeclarationRef=XT,y.endpointReturnStatementRef=YT,y.endpointReturnStatementRefThree=rE,y.endpointReturnStatementRefTwo=eE,y.enrichFromKnownEntities=ja,y.enumOptionsProperty=mf,y.enumOptionsPropertyDataType=hf,y.enumOptionsPropertyDataTypeRef=cf,y.enumOptionsPropertyRef=ff,y.enumPrototype=sr,y.enumPrototypeRef=yf,y.executionBuiltInBaseEntity=To,y.executionBuiltInEntityAbortMethod=tu,y.executionBuiltInEntityAbortMethodParentRef=ZE,y.filterOutDuplicateEntities=p,y.filterOutDuplicateErrors=J3,y.findEntityFromKeys=Jc,y.findReferenceToSelfInList=DP,y.findReferencesToSelfInProject=jW,y.flattenActionDescriptor=OP,y.flattenArgumentDeclaration=PP,y.flattenBreakStatement=wP,y.flattenBuiltInBaseEntity=CP,y.flattenCalls=Ci,y.flattenCanvasAncestorsUntil=Cs,y.flattenCondition=VP,y.flattenContinueStatement=BP,y.flattenDataType=MP,y.flattenDefinitionEntity=_P,y.flattenDefinitionEntityExtensionAndImplementationTypes=ef,y.flattenDefinitionEntityExtensionTypes=$a,y.flattenDefinitionEntityExtensions=Xc,y.flattenDefinitionEntityImplementations=Qc,y.flattenDefinitionEntityImplementionTypes=Ua,y.flattenDerivedCanvasEntities=pi,y.flattenDetachedBranch=lw,y.flattenElementCalls=Ee,y.flattenElementCallsOnTheSameScope=LW,y.flattenEntity=j,y.flattenFunctionCall=NP,y.flattenFunctionDeclaration=LP,y.flattenGlobalEvent=jP,y.flattenInputMap=UP,y.flattenInstalledProject=$P,y.flattenInternalCall=GP,y.flattenLiteralValue=gP,y.flattenLoop=FP,y.flattenOperation=xP,y.flattenOutputMap=kP,y.flattenPrimitiveEntity=ZP,y.flattenProject=qP,y.flattenProjectElements=RP,y.flattenProperty=JP,y.flattenRelatedCanvasElementsOnTheLeft=rw,y.flattenRelatedCanvasElementsOnTheRight=iw,y.flattenReturnDeclaration=WP,y.flattenReturnStatement=SP,y.flattenSearch=zP,y.flattenValueDescriptor=YP,y.flattenVariableDeclaration=HP,y.flattenVariableInstance=KP,y.flattenVariableReads=bP,y.flattenVariableWrites=AP,y.flattenVariables=He,y.fromChangeSetToRecordChangeSet=QW,y.fromZodParseToEntityGenerationErrors=Lc,y.functionCallValidation=AW,y.functionDeclarationValidation=LJ,y.generate=qV,y.generateActionExample=hW,y.generateExecutionDataType=bJ,y.generateIdFromStrategy=yt,y.generateMutablePropertiesExplanation=gl,y.generateRandomBoolean=tA,y.generateRandomDate=MI,y.generateRandomDateAfter=VI,y.generateRandomDateBefore=BI,y.generateRandomDateBetweenRange=_I,y.generateRandomNumber=HI,y.generateRandomNumberAfter=SI,y.generateRandomNumberBefore=zI,y.generateRandomNumberBetweenRange=YI,y.generateRandomText=eA,y.generateRandomTextAfter=KI,y.generateRandomTextBefore=XI,y.generateRandomTextBetweenRange=QI,y.generateUniqueUUID=WI,y.getAllActionDescriptorsForConditions=Wl,y.getAllActionDescriptorsForGlobalEvents=ql,y.getAllActionDescriptorsForLoops=Jl,y.getAllActionDescriptorsForOperations=TW,y.getAllBuiltInEntityIds=$i,y.getAllGloballyDeclaredFunctionDeclarationsExplanation=X1,y.getBaseBuiltInEntities=Wt,y.getBaseSchemaBasedOnType=q1,y.getBuiltInEntityOwner=an,y.getCallableEntityReferenceSchema=Ct,y.getCallableEntityTypeSchema=MD,y.getCalledBy=Ii,y.getCallerEntityReferenceSchema=YZ,y.getCallerEntityTypeSchema=zZ,y.getCalls=Yc,y.getCanvasEntitiesDerivedFromInternalCalls=tw,y.getCanvasEntitiesDerivedFromWrites=Vs,y.getCanvasEntityDerivedFromValueReadingEntity=Ql,y.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=ew,y.getCanvasEntityReferenceSchema=c7,y.getCanvasEntityTypeSchema=p7,y.getChildrenEntityWithValues=CW,y.getColumnProperties=HW,y.getCommonAncestor=zc,y.getCommonChildren=uP,y.getDatabaseEntities=zW,y.getDatabaseEntity=KW,y.getDeclaration=Un,y.getDeclarationOutputedError=tS,y.getDeepestScope=pw,y.getDraggableCallableEntityReferenceSchema=LD,y.getDraggableCallableEntityTypeSchema=ND,y.getDraggableCallerEntityReferenceSchema=KZ,y.getDraggableCallerEntityTypeSchema=HZ,y.getDraggableExecutableEntityReferenceSchema=t7,y.getDraggableExecutableEntityTypeSchema=e7,y.getDraggablePassThroughCallableEntityReferenceSchema=wl,y.getDraggablePassThroughCallableEntityTypeSchema=Pl,y.getDraggablePlayableEntityReferenceSchema=a7,y.getDraggablePlayableEntityTypeSchema=s7,y.getEntitiesCreatedSinceInitialization=od,y.getEntityArgumentDeclarations=Kc,y.getEntityInputMaps=XP,y.getEntityOutputMaps=gW,y.getEntityReferenceSchema=u7,y.getEntityReturnDeclarations=QP,y.getEntityTypeSchema=d7,y.getEntityWithLogicScopeReferenceSchema=vr,y.getEntityWithLogicScopeTypeSchema=i7,y.getEntityWithValueReferenceSchema=_D,y.getEntityWithValueTypeSchema=SZ,y.getEntryPointEntityReferenceSchema=Ot,y.getEntryPointEntityTypeSchema=Ur,y.getEventEntityReferenceSchema=Dl,y.getEventEntityTypeSchema=Rl,y.getExecutableEntityReferenceSchema=QZ,y.getExecutableEntityTypeSchema=XZ,y.getExtendedBuiltInEntity=FW,y.getExtendedDefinitionEntity=sw,y.getFirstNonLoopScopeOwner=It,y.getGenerationTargetSchemaBasedOnType=J1,y.getHeadIfPartOfDetachedBranch=ow,y.getHighestScope=uw,y.getImplementedBuiltInEntity=xW,y.getIsInteractive=Ga,y.getLastInListOperation=Rd,y.getLastInListOperationError=Dy,y.getLastInListOperationErrorParentRef=Ry,y.getLastInListOperationInputListArgument=Iy,y.getLastInListOperationInputListArgumentParentRef=Ey,y.getLastInListOperationInputListArgumentRef=yy,y.getLastInListOperationInputListDataType=my,y.getLastInListOperationOutputElementDataType=Ty,y.getLastInListOperationOutputElementReturn=by,y.getLastInListOperationOutputElementReturnParentRef=Ay,y.getLastInListOperationOutputElementReturnRef=vy,y.getLinkedEntitiesFromArgumentDeclaration=NW,y.getLowestPersistedEntityImplementation=nw,y.getParentCallableEntity=pP,y.getParentCallerEntity=fP,y.getParentCanvasEntities=Gt,y.getParentCanvasEntity=Bt,y.getParentCanvasEntityFromTransfer=Hl,y.getParentEntryPoint=wW,y.getParentPassthroughCallableEntity=cP,y.getPassThroughCallableEntityReferenceSchema=nt,y.getPassThroughCallableEntityTypeSchema=Ol,y.getPeristedEntities=SW,y.getPlayableEntityReferenceSchema=n7,y.getPlayableEntityTypeSchema=r7,y.getProject=SS,y.getPrototypeByType=ga,y.getRecusriveParentsIds=rd,y.getReferenceEntityId=_,y.getReferencedEntitiesStateOrErrors=xl,y.getReferencedEntityStateOrErrors=jc,y.getReferencedIds=Xl,y.getRelatedCanvasElementsOnTheLeft=$n,y.getRelatedCanvasElementsOnTheLeftFromTransfer=UW,y.getRelatedCanvasElementsOnTheRight=sn,y.getRootEntryPointScopeOwner=nf,y.getScopeOwner=St,y.getStateClassFromType=XW,y.getTerminationReferenceSchema=l7,y.getTerminationTypeSchema=o7,y.getTouchedCanvasEntitiesFromChangeSet=eS,y.getUsedArgFromDeclaration=$W,y.getUsedReturnFromDeclaration=GW,y.getValueReadingEntityReferenceSchema=BD,y.getValueReadingEntityTypeSchema=mr,y.getValueWritingEntityReferenceSchema=WZ,y.getValueWritingEntityTypeSchema=Aa,y.getVariableFromInputMapping=yP,y.getVariableFromReturnVariablePointer=TP,y.getVariableReferenceSchema=jr,y.getVariableTypeSchema=Bn,y.getVariablesFromArgumentDeclarations=Kl,y.getVariablesFromInputMaps=mP,y.getVariablesFromOutputMapping=EP,y.getVariablesFromOutputMaps=IP,y.getVariablesFromReturnDeclarations=vP,y.getVariablesInSameOrHigherScope=Ac,y.getWrites=Hc,y.globalEventValidation=kJ,y.groupCallsBasedOnParallelizableExecution=BW,y.handleAfterEntityImplementationSideEffects=sP,y.handleBeforeEntityImplementationSideEffects=nP,y.httpRequestBodyArgument=ro,y.httpRequestBodyArgumentRef=a0,y.httpRequestBodyDataType=o0,y.httpRequestHeadersArgument=io,y.httpRequestHeadersArgumentRef=n0,y.httpRequestHeadersDataType=s0,y.httpRequestMethodArgument=eo,y.httpRequestMethodArgumentRef=i0,y.httpRequestMethodDataType=r0,y.httpRequestMethodDataTypeRef=e0,y.httpRequestOperation=Ns,y.httpRequestOperationErrorValueDescriptor=_d,y.httpRequestOperationErrorValueDescriptorDatatype=P0,y.httpRequestOperationErrorValueDescriptorRef=O0,y.httpRequestOperationRef=A0,y.httpRequestOperationRefEight=R0,y.httpRequestOperationRefFive=E0,y.httpRequestOperationRefFour=T0,y.httpRequestOperationRefNine=D0,y.httpRequestOperationRefSeven=b0,y.httpRequestOperationRefSix=I0,y.httpRequestOperationRefThree=v0,y.httpRequestOperationRefTwo=m0,y.httpRequestQueryParamsArgument=Bd,y.httpRequestQueryParamsArgumentRef=Xm,y.httpRequestQueryParamsDataType=Qm,y.httpRequestVariableURLArgument=to,y.httpRequestVariableURLArgumentRef=Hm,y.httpRequestVariableURLDataType=Km,y.httpRequestVariableURLDataTypeRef=zm,y.httpResponseBodyReturnDataType=y0,y.httpResponseBodyReturnDataTypeRef=f0,y.httpResponseBodyReturnReturn=ao,y.httpResponseBodyReturnReturnRef=h0,y.httpResponseCodeDataType=d0,y.httpResponseCodeReturn=no,y.httpResponseCodeReturnRef=l0,y.httpResponseHeadersDataType=c0,y.httpResponseHeadersDataTypeRef=u0,y.httpResponseHeadersReturn=so,y.httpResponseHeadersReturnRef=p0,y.httpStatusCodeValueValidation=Rw,y.implement=zl,y.inferArgumentDeclarationDataType=WO,y.inferDataType=Ui,y.inferInputMapDataType=Tc,y.inferOutputMapDataType=Ic,y.inferPropertyDataType=YO,y.inferReturnDeclarationDataType=Ec,y.inferValueDescriptorDataType=HO,y.inferVariableDeclarationDataType=zO,y.inferVariableInstanceDataType=SO,y.initBaseProjectEntity=ad,y.initProject=Pw,y.initProjectFromFetchResult=Ow,y.inputMapValidation=XJ,y.installedProjectValidation=HJ,y.internalCallValidation=KJ,y.isPromise=qc,y.iterateOverListActionDescriptorListArgumentDeclaration=av,y.iterateOverListActionDescriptorListArgumentDeclarationDataType=nv,y.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=rv,y.iterateOverListActionDescriptorListArgumentDeclarationParentRef=sv,y.iterateOverListLoopActionDescriptor=Or,y.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=lv,y.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=ov,y.iterateOverListLoopBodyActionDescriptor=Us,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=vv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=mv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Ev,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=Tv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=po,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=uv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=dv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=pv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=yv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=fv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=cv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=hv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Dv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=bv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Av,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=Rv,y.iterateOverObjectKeysLoopActionDescriptor=Sn,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Pv,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=Ov,y.iterateOverObjectKeysLoopBodyActionDescriptor=Ud,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=jv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Lv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=$v,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Uv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=jd,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Cv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=wv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Vv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Nv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=_v,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Bv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Mv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=kv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Fv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=gv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=xv,y.iterateOverObjectValuesLoopActionDescriptor=zn,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=qv,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Zv,y.iterateOverObjectValuesLoopBodyActionDescriptor=Gd,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Qv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Xv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=tT,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=eT,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=$d,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Wv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Jv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Sv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Kv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Yv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=zv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Hv,y.iterateOverStringActionDescriptorDynamicReturnDeclaration=J0,y.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=q0,y.iterateOverStringActionDescriptorStringArgumentDeclaration=Z0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=x0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=F0,y.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=k0,y.iterateOverStringLoopActionDescriptor=js,y.iterateOverStringLoopBodyActionDescriptor=uo,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=Q0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=X0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=tv,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=ev,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Nd,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=S0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=W0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=z0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Ld,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=H0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Y0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=K0,y.joinListOperation=Id,y.joinListOperationError=zh,y.joinListOperationErrorParentRef=Sh,y.joinListOperationFirstListArgument=kh,y.joinListOperationFirstListArgumentParentRef=xh,y.joinListOperationFirstListArgumentRef=jh,y.joinListOperationFirstListDataType=Uh,y.joinListOperationResultListDataType=Fh,y.joinListOperationResultListReturn=Wh,y.joinListOperationResultListReturnParentRef=Jh,y.joinListOperationResultListReturnRef=gh,y.joinListOperationSecondListArgument=qh,y.joinListOperationSecondListArgumentParentRef=Zh,y.joinListOperationSecondListArgumentRef=$h,y.joinListOperationSecondListDataType=Gh,y.joinListWithLastSeparator=se,y.joinStringsOperation=Ms,y.joinStringsOperationDynamicStringArgument=hh,y.joinStringsOperationDynamicStringArgumentParentRef=fh,y.joinStringsOperationDynamicStringArgumentRef=ph,y.joinStringsOperationDynamicStringDataType=ch,y.joinStringsOperationError=uh,y.joinStringsOperationErrorParentRef=dh,y.joinStringsOperationFirstStringArgument=Ka,y.joinStringsOperationFirstStringArgumentParentRef=eh,y.joinStringsOperationFirstStringArgumentRef=zf,y.joinStringsOperationFirstStringDataType=Yf,y.joinStringsOperationResultStringDataType=Qf,y.joinStringsOperationResultStringReturn=_s,y.joinStringsOperationResultStringReturnParentRef=lh,y.joinStringsOperationResultStringReturnRef=Xf,y.joinStringsOperationSecondStringArgument=Xa,y.joinStringsOperationSecondStringArgumentParentRef=oh,y.joinStringsOperationSecondStringArgumentRef=Hf,y.joinStringsOperationSecondStringDataType=Kf,y.joinStringsOperationSeparatorStringArgument=ah,y.joinStringsOperationSeparatorStringArgumentParentRef=sh,y.joinStringsOperationSeparatorStringArgumentRef=th,y.joinStringsOperationSeparatorStringDataType=nh,y.joinStringsOperationSeparatorStringDataTypeDefaultValue=rh,y.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=ih,y.keyValuePrototype=qn,y.literalValudValidation=sW,y.loopValidation=qJ,y.lowercaseFirstLetter=_a,y.manualFlowActionDescriptorDeclarationArgumentDeclaration=Md,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=N0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=M0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=L0,y.manualFlowLoopActionDescriptor=oo,y.manualFlowLoopActionDescriptorDynamicReturnDeclaration=_0,y.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=B0,y.manualFlowLoopBodyActionDescriptor=lo,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=U0,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=j0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=G0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=$0,y.mapActionDescriptorToTypeItRepresents=JW,y.mergeEntityErrorsList=W3,y.mergeListOfEntities=ZW,y.methodDefaultValue=t0,y.mockClientProject=pp,y.moreThanOrEqualCondition=Qn,y.moreThanOrEqualConditionLeftHandArgument=KE,y.moreThanOrEqualConditionLeftHandArgumentDataType=YE,y.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=zE,y.moreThanOrEqualConditionLeftHandArgumentParentRef=HE,y.moreThanOrEqualConditionRightHandArgument=tI,y.moreThanOrEqualConditionRightHandArgumentDataType=QE,y.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=XE,y.moreThanOrEqualConditionRightHandArgumentParentRef=eI,y.noSpacesOrDashesValueValidation=dP,y.noSpacesValueValidation=lP,y.notEmptyCondition=mn,y.notEmptyConditionArgument=WE,y.notEmptyConditionRef=JE,y.nullPrototype=cd,y.numberAdditionOperation=Ha,y.numberAdditionOperationDynamicSummandArgument=Bf,y.numberAdditionOperationDynamicSummandArgumentType=Vf,y.numberAdditionOperationDynamicSummandArgumentTypeParentRef=Cf,y.numberAdditionOperationError=wf,y.numberAdditionOperationErrorParentRef=Pf,y.numberAdditionOperationFirstNumberArgument=fd,y.numberAdditionOperationFirstNumberArgumentRef=Tf,y.numberAdditionOperationFirstNumberDataType=Ef,y.numberAdditionOperationRef=Df,y.numberAdditionOperationRefThree=yd,y.numberAdditionOperationRefTwo=Of,y.numberAdditionOperationResultNumberDataType=Rf,y.numberAdditionOperationResultNumberReturn=md,y.numberAdditionOperationResultNumberReturnRef=bf,y.numberAdditionOperationSecondNumberArgument=hd,y.numberAdditionOperationSecondNumberArgumentRef=If,y.numberAdditionOperationSecondNumberDataType=Af,y.numberPrototype=Te,y.numberSubtractionOperation=Td,y.numberSubtractionOperationDynamicSubtrahendArgument=Wf,y.numberSubtractionOperationDynamicSubtrahendArgumentType=Jf,y.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=qf,y.numberSubtractionOperationError=Zf,y.numberSubtractionOperationErrorParentRef=kf,y.numberSubtractionOperationFirstNumberArgument=$f,y.numberSubtractionOperationFirstNumberArgumentRef=_f,y.numberSubtractionOperationFirstNumberDataType=Mf,y.numberSubtractionOperationRef=vd,y.numberSubtractionOperationRefThree=Ff,y.numberSubtractionOperationRefTwo=Gf,y.numberSubtractionOperationResultNumberDataType=Uf,y.numberSubtractionOperationResultNumberReturn=xf,y.numberSubtractionOperationResultNumberReturnRef=jf,y.numberSubtractionOperationSecondNumberArgument=gf,y.numberSubtractionOperationSecondNumberArgumentRef=Nf,y.numberSubtractionOperationSecondNumberDataType=Lf,y.numberValueAutogenerationSchema=yp,y.operationValidation=GJ,y.outputMapValidation=tW,y.parallelExecutionOperation=Bi,y.parallelExecutionOperationError=Qy,y.parallelExecutionOperationErrorParentRef=Xy,y.parallelExecutionOperationListOfExecutionResultsDataType=Yy,y.parallelExecutionOperationListOfExecutionResultsReturn=wd,y.parallelExecutionOperationListOfExecutionResultsReturnRef=zy,y.parallelExecutionOperationListOfFunctionsArgument=Pd,y.parallelExecutionOperationListOfFunctionsArgumentDatatype=Sy,y.parallelExecutionOperationListOfFunctionsArgumentRef=Wy,y.parallelExecutionOperationListOfFunctionsBlueprint=Jy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Zy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=ky,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=xy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=Fy,y.parallelExecutionOperationListOfFunctionsBlueprintParentRef=qy,y.parallelExecutionOperationRef=Hy,y.parallelExecutionOperationRefThree=Ky,y.persistedBuiltInBaseEntity=Mt,y.persistedBuiltInBaseEntityDatabaseProperty=Hn,y.persistedBuiltInBaseEntityDatabasePropertyDataType=PE,y.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=$w,y.persistedBuiltInBaseEntityDatabasePropertyParentRef=wE,y.persistedBuiltInBaseEntityDatabasePropertyRef=OE,y.persistedBuiltInBaseEntityPrimaryKeyProperty=Kn,y.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=jE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=VE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=CE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=UE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=LE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=_E,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=BE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=NE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=ME,y.processOutputGlobalValueDescriptorDataType=lI,y.processOutputGlobalValueDescriptorReturn=Io,y.processOutputGlobalValueDescriptorReturnRef=oI,y.projectPublicationCompletedGlobalEvent=Eo,y.propertyToZodSchema=wI,y.propertyValidation=VJ,y.relationalDatabaseBuiltInBaseEntity=Dt,y.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Xd,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=AE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=IE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=bE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=EE,y.relationalDatabaseBuiltInBaseEntityDefaultProperty=Kd,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=TE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=mE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=vE,y.relationalDatabaseBuiltInBaseEntityIdentifierProperty=fo,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=oE,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=sE,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=aE,y.relationalDatabaseBuiltInBaseEntityMinSizeProperty=mo,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=yE,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=fE,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=hE,y.relationalDatabaseBuiltInBaseEntityPasswordProperty=yo,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=pE,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=Uw,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDefaultValueParentRef=cE,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=uE,y.relationalDatabaseBuiltInBaseEntityRef=Yn,y.relationalDatabaseBuiltInBaseEntityUsernameProperty=ho,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=dE,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=jw,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=lE,y.resolveActionDescriptorName=i1,y.resolveBaseEntityName=XO,y.resolveBuiltInBaseEntityDataTypeLabel=QO,y.resolveClonedEntityProject=mt,y.resolveConditionOperatorLabel=Gl,y.resolveDataType=jl,y.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Wc,y.resolveDataTypeLabel=$l,y.resolveDefinitionEntityDataTypeLabel=wJ,y.resolveEntityDataTypeLabel=PJ,y.resolveEntityName=x,y.resolveFirstCallsSecond=_W,y.resolveFirstWritesSecond=MW,y.resolvePrimaryKeyProperty=YW,y.resolvePrimitiveEntityName=t1,y.resolveSearchName=e1,y.resolveVariableScope=RJ,y.returnDeclarationValidation=gJ,y.returnStatementValidation=FJ,y.searchStatementErrorGlobalValueDescriptor=nu,y.searchStatementErrorGlobalValueDescriptorDataType=uI,y.searchStatementErrorGlobalValueDescriptorRef=dI,y.searchValidation=YJ,y.sequentialExecutionOperation=lr,y.sequentialExecutionOperationError=Em,y.sequentialExecutionOperationErrorParentRef=Tm,y.sequentialExecutionOperationListOfExecutionResultsDataType=ym,y.sequentialExecutionOperationListOfExecutionResultsReturn=Vd,y.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=vm,y.sequentialExecutionOperationListOfExecutionResultsReturnRef=hm,y.sequentialExecutionOperationListOfFunctionsArgument=Cd,y.sequentialExecutionOperationListOfFunctionsArgumentDatatype=fm,y.sequentialExecutionOperationListOfFunctionsArgumentParentRef=mm,y.sequentialExecutionOperationListOfFunctionsArgumentRef=cm,y.sequentialExecutionOperationListOfFunctionsBlueprint=pm,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=um,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=dm,y.softDeletePersistedEntityMethod=Gw,y.softDeletePersistedEntityMethodParentRef=$E,y.sortCallsBasedOnExecutionDependencies=hP,y.sortChildrenEntitiesBasedOnExecutionDependencies=VW,y.splitListOperation=bd,y.splitListOperationError=cy,y.splitListOperationErrorParentRef=py,y.splitListOperationFirstOutputListDataType=ty,y.splitListOperationFirstOutputListReturn=oy,y.splitListOperationFirstOutputListReturnParentRef=ay,y.splitListOperationFirstOutputListReturnRef=Ad,y.splitListOperationInputListArgument=ry,y.splitListOperationInputListArgumentParentRef=iy,y.splitListOperationInputListArgumentRef=Kh,y.splitListOperationInputListDataType=Xh,y.splitListOperationSecondOutputListDataType=ly,y.splitListOperationSecondOutputListReturn=uy,y.splitListOperationSecondOutputListReturnParentRef=dy,y.splitListOperationSplitIndexArgument=sy,y.splitListOperationSplitIndexArgumentParentRef=ny,y.splitListOperationSplitIndexArgumentRef=Qh,y.splitListOperationSplitIndexDataType=ey,y.splitStringOperation=Ed,y.splitStringOperationError=_h,y.splitStringOperationErrorParentRef=Bh,y.splitStringOperationFirstPartResultStringDataType=Ih,y.splitStringOperationFirstPartResultStringReturn=Vh,y.splitStringOperationFirstPartResultStringReturnParentRef=Ch,y.splitStringOperationFirstPartResultStringReturnRef=Eh,y.splitStringOperationIndexArgument=Ph,y.splitStringOperationIndexArgumentParentRef=Oh,y.splitStringOperationIndexArgumentRef=vh,y.splitStringOperationIndexDataType=Th,y.splitStringOperationSecondPartResultStringDataType=bh,y.splitStringOperationSecondPartResultStringReturn=Nw,y.splitStringOperationSecondPartResultStringReturnParentRef=wh,y.splitStringOperationSecondPartResultStringReturnRef=Ah,y.splitStringOperationStringArgument=Dh,y.splitStringOperationStringArgumentParentRef=Rh,y.splitStringOperationStringArgumentRef=yh,y.splitStringOperationStringDataType=mh,y.stringPrototype=ae,y.stringValueAutogenerationSchema=hp,y.suggestNewIdForEntity=Cc,y.test_primitive_entities_export=$S,y.toCamelCase=DJ,y.toEntityState=Ai,y.toKebabCase=KO,y.toLowerCaseKebabCase=Ul,y.toPascalCase=OJ,y.untypedDataPrototype=wt,y.updateErrorsList=Ke,y.urlDefaultValue=Ym,y.uuidPrototype=ar,y.validateArgumentDeclarationName=Pc,y.validateCalledByErrorIdInAction=mW,y.validateCalledByIdInAction=yW,y.validateCallers=K1,y.validateConditionEntityDeclaration=EW,y.validateDataOperation=pn,y.validateDataOperationDataToValidateArgument=Gm,y.validateDataOperationDataToValidateArgumentParentRef=$m,y.validateDataOperationDataToValidateArgumentRef=jm,y.validateDataOperationDataToValidateDataType=Um,y.validateDataOperationEntityToMatchTypeArgument=km,y.validateDataOperationEntityToMatchTypeArgumentParentRef=xm,y.validateDataOperationEntityToMatchTypeArgumentRef=gm,y.validateDataOperationEntityToMatchTypeDataType=Fm,y.validateDataOperationError=Wm,y.validateDataOperationErrorParentRef=Jm,y.validateDataOperationOutputEntityDeclaration=qm,y.validateDataOperationOutputEntityDeclarationParentRef=Zm,y.validateDefinitionEntityName=bc,y.validateEntryCaller=H1,y.validateErrorCaller=Y1,y.validateFunctionCallDeclaration=Q1,y.validateFunctionDeclarationName=Rc,y.validateGeneratedEntityParentIsNotBuiltInEntity=pW,y.validateGeneration=dW,y.validateGenerationTarget=ut,y.validateGenerationUpdate=uW,y.validateLoopEntityDeclaration=IW,y.validateName=CJ,y.validateOperationEntityDeclaration=eP,y.validatePropertyName=Oc,y.validateReachability=Ar,y.validateReadsValueInActionPayload=vW,y.validateReferenceObject=Fl,y.validateReferenceToOne=Uc,y.validateReferences=bt,y.validateReturnDeclarationName=wc,y.validateSuccessCaller=z1,y.validateValueReaderGenerationUpdate=Na,y.validateValueWritter=kc,y.validateVariableDeclarationName=Dc,y.validateVariableInternalCallUse=Zc,y.valueAutogenerationCurrentDateAndTimeSchema=dD,y.valueAutogenerationGenericSchema=ll,y.valueAutogenerationOptions=vp,y.valueAutogenerationOptionsSchema=lD,y.valueAutogenerationRandomBooleanSchema=fp,y.valueAutogenerationRandomDateBetweenSchema=TD,y.valueAutogenerationRandomDateFromSchema=mD,y.valueAutogenerationRandomDateSchema=pl,y.valueAutogenerationRandomDateUntilSchema=vD,y.valueAutogenerationRandomNumberBetweenSchema=cD,y.valueAutogenerationRandomNumberFromSchema=uD,y.valueAutogenerationRandomNumberSchema=dl,y.valueAutogenerationRandomNumberUntilSchema=pD,y.valueAutogenerationRandomSchema=ha,y.valueAutogenerationRandomTextBetweenSchema=yD,y.valueAutogenerationRandomTextFromSchema=fD,y.valueAutogenerationRandomTextSchema=ul,y.valueAutogenerationRandomTextUntilSchema=hD,y.valueAutogenerationRangeValueTypesSchema=fa,y.valueAutogenerationUniqueSchema=cp,y.valueDescriptorValidation=lW,y.variableDeclarationValidation=SJ,y.variableInstanceValidation=zJ,y.waitOperation=Yt,y.waitOperationMillisecondsNumberArgument=dn,y.waitOperationMillisecondsNumberArgumentRef=im,y.waitOperationMillisecondsNumberDataType=rm,y.waitOperationOperationError=am,y.waitOperationOperationErrorParentRef=sm,y.waitOperationRef=nm,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});