@elyx-code/project-logic-tree 0.0.6345 → 0.0.6347
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.
- package/dist/index.js +9 -9
- package/dist/index.umd.cjs +9 -9
- package/package.json +2 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -43,9 +43,9 @@ You can update the existing 'literal-value' with the 'update' action, for exampl
|
|
|
43
43
|
}
|
|
44
44
|
}\`\`\`
|
|
45
45
|
Or 'delete' and then 'post' actions to replace it.`,issue:null})):i.push(new Q({id:`${d.id}--${d.parent}--${S.InvalidParentReference}`,code:S.InvalidParentReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'input-map' or 'data-type'.`,issue:null})):i.push(new Q({id:`${d.id}--${d.parent}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else i.push(new Q({id:`${d.id}--${oe.InvalidObjectStructure}`,code:oe.InvalidObjectStructure,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null}));else return i.push(new Q({id:`${d.id}--${oe.InvalidObjectStructure}`,code:oe.InvalidObjectStructure,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null})),i;if(d.valueAsTypeSingle){const p=[],t=[],y=d.valueAsTypeSingle;Array.isArray(y)?y.forEach(v=>{typeof v=="string"?t.push(v):p.push(v)}):typeof y=="string"?t.push(y):p.push(y),p.forEach(v=>{const T=Ny(v);i.push(...T),T.length===0&&t.push(v.entityId)}),t.forEach(v=>{const T=u.get(v);T?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(T.type)||i.push(new Q({id:`${d.id}--${v}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'valueAsTypeSingle' reference that isn't pointing to an entity of type 'definition-entity', 'function-declaration' or 'operation'.`,issue:null})):i.push(new Q({id:`${d.id}--${v}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${v}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))})}return i}var dM=(d=>(d.ValueAsTypeSingle="value-as-type-single",d.ValueAsTypeList="value-as-type-list",d))(dM||{});const yt=class yt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"type",f.LiteralValue);D(this,"id");D(this,"name");D(this,"autogeneration",null);D(this,"value",null);D(this,"valueAsTypeSingle",null);D(this,"valueAsTypeList",null);D(this,"errors",[]);D(this,"parent");D(this,"standaloneParent");D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"standalone",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.autogeneration=i.autogeneration,this.value=i.value}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:"",autogeneration:null,value:null,valueAsTypeSingle:null,valueAsTypeList:null,parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l);let t=null,y=null;i.valueAsTypeList?Array.isArray(i.valueAsTypeList)&&(y=i.valueAsTypeList.map(w=>a.get(w)||a.getBuiltIn(w))):i.valueAsTypeSingle&&(t=a.get(i.valueAsTypeSingle)||a.getBuiltIn(i.valueAsTypeSingle));const v={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:i.name,autogeneration:i.autogeneration,valueAsTypeSingle:t,valueAsTypeList:y,value:i.value||null,parent:p},T=ee(v,a);return T.setParent(p,null),T}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Nfe(l,a);return p.push(...t,...vr(l)),{errors:p,modifiedData:l}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}get isFinal(){var i;return!!(this.parent.type===f.Property&&(this.parent.constant||(i=this.parent.implements)!=null&&i.constant)||this.parent.type===f.Property&&this.parent.parent.type===f.DefinitionEntity&&!Rp(this.parent.parent))}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
46
|
-
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return a==="value-as-type-single"&&(this.valueAsTypeSingle=null,l==null||l.add(this,K.Updated)),a==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(T=>T.id!==i.id),l==null||l.add(this,K.Updated)),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return a==="value-as-type-single"&&(this.valueAsTypeSingle=i,l==null||l.add(this,K.Updated)),a==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],i],l==null||l.add(this,K.Updated)),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==f.BuiltInBaseEntity&&this.valueAsTypeSingle.unsubscribeDependents([{entity:this,field:"value-as-type-single"}]),this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)&&this.valueAsTypeList.forEach(i=>{i.type!==f.BuiltInBaseEntity&&i.unsubscribeDependents([{entity:this,field:"value-as-type-list"}])}),this}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(i=>{i.type!==f.BuiltInBaseEntity&&i.subscribeDependents([{entity:this,field:"value-as-type-list"}])}):this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==f.BuiltInBaseEntity&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.valueAsTypeSingle=this.valueAsTypeSingle,i.valueAsTypeList=this.valueAsTypeList?[...this.valueAsTypeList]:this.valueAsTypeList,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new yt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.valueAsTypeSingle=y.valueAsTypeSingle,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent&&i.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else if(i.standaloneParent){const l=W(i.standaloneParent),p=this.project.get(l);if(p)this.setStandaloneParent(p);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.valueAsTypeList&&Array.isArray(i.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],i.valueAsTypeList.forEach(l=>{const p=W(l),t=this.project.get(p);t&&this.valueAsTypeList.push(t)});else if(i.valueAsTypeSingle){const l=W(i.valueAsTypeSingle),p=this.project.get(l);p&&(this.valueAsTypeSingle=p)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else if(this.initialData.standaloneParent){const t=W(this.initialData.standaloneParent),y=this.project.get(t);if(y)this.setStandaloneParent(y);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.valueAsTypeList.push(v)});else if(this.initialData.valueAsTypeSingle){const t=W(this.initialData.valueAsTypeSingle),y=this.project.get(t);y&&(this.valueAsTypeSingle=y)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],p=[],t=[];return((y=this.parent)==null?void 0:y.type)===f.DataType?this.parent.setEntity(this,i):(v=this.parent)==null||v.setDefaultValue(this,i),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setStandaloneParent(i){return this.standaloneParent=i,this}setValueAsTypeSingle(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-as-type-single"))){return this.valueAsTypeSingle!==i&&(this.valueAsTypeSingle=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-as-type-single",this.id),this}setValueAsTypeList(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-as-type-list"))){var l,p;return!i&&this.valueAsTypeList?(this.valueAsTypeList=null,a==null||a.add(this,K.Updated)):i&&!this.valueAsTypeList?(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)):i&&this.valueAsTypeList&&((l=this.valueAsTypeList)==null?void 0:l.length)!==i.length?(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)):i&&this.valueAsTypeList&&((p=this.valueAsTypeList)!=null&&p.every((t,y)=>t!==i[y]))&&(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-as-type-list",this.id),this}setValueAsType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-as-type"))){return i?(Array.isArray(i)?this.setValueAsTypeList(i,a):this.setValueAsTypeSingle(i,a),a==null||a.attemptAutoclose("set-value-as-type",this.id),this):(this.setValueAsTypeSingle(null,a),this.setValueAsTypeList(null,a),this)}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(a=>{if(a.type===f.GenericReference){const p=this.project.findSubscribedBuiltInInstanceFromReference(a);if(!p)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.entityType}' with id '${a.entityId}' that is not part of the project state.`);return p}const l=this.project.get(a.id);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.type}' with id '${a.id}' that is not part of the project state.`);return l});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===f.GenericReference){const l=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=l,this}const a=this.project.get(this.initialData.valueAsTypeSingle.id);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=a}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(a=>{if(a.type===f.GenericReference){const p=this.project.findSubscribedBuiltInInstanceFromReference(a);if(!p)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.entityType}' with id '${a.entityId}' that is not part of the project state.`);return p}const l=this.project.get(a.id);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.type}' with id '${a.id}' that is not part of the project state.`);return l});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===f.GenericReference){const l=W(this.initialData.valueAsTypeSingle),p=l?this.project.get(l):null;if(!p)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=p,this}const a=this.project.get(this.initialData.valueAsTypeSingle.id);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=a}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.autogeneration=i.autogeneration!==void 0?i.autogeneration:p.autogeneration,this.value=i.value!==void 0?i.value:p.value,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await yt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await yt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent&&(this.parent.type===f.DataType?this.parent.setEntity(null,i):ev.includes(this.parent.type)&&this.parent.setDefaultValue(null,i),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlat(i)):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatIds(i)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toJSON(i))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(t=>t.toJSON(i)):null,parent:(l=this.parent)==null?void 0:l.toReference(),standaloneParent:(p=this.standaloneParent)==null?void 0:p.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...i,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(A=>this.project.getBuiltIn(A.id)?A.toJSON():A.toJSONClone({...i,newId:null})):null,parent:(T=this.parent)==null?void 0:T.toReference({seenEntityMaps:i.seenEntityMaps}),standaloneParent:(w=this.standaloneParent)==null?void 0:w.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((p=this.valueAsTypeSingle)==null?void 0:p.toReference(i))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(v=>v.toReference(i)):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.toReference(i),standaloneParent:(y=this.standaloneParent)==null?void 0:y.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatJSON(i)):[]])}toGenerationTarget(){var i,a,l;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((i=this.valueAsTypeSingle)==null?void 0:i.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(p=>p.id):null,value:this.value,autogeneration:this.autogeneration,parent:(a=this.parent)==null?void 0:a.id,standaloneParent:(l=this.standaloneParent)==null?void 0:l.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatGenerationTarget(i)):[]])}clearErrors(){return this.errors=[],this}validate(){const i=lM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const T=Kt(y,t);return T.initChildren(i),a&&T.setParent(a,null),i==null||i.add(T,K.Added),p&&T.subscribe(),i==null||i.attemptAutoclose("clone-entity",this.id),T}merge(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"merge-literal-value"))){const l=[],p=[],t=[],y=[];return this.valueAsTypeSingle!==(i==null?void 0:i.valueAsTypeSingle)&&(this.setValueAsType(i.valueAsTypeSingle,a),l.push(this)),this.value!==i.value&&(this.metaSync({value:i.value},a),l.push(this)),this.autogeneration!==i.autogeneration&&(this.metaSync({autogeneration:i.autogeneration},a),l.push(this)),this.name!==i.name&&(this.metaSync({name:i.name},a),l.push(this)),a==null||a.attemptAutoclose("merge-literal-value",this.id),{updated:R(l),added:R(p),removed:R(t),affected:R(y),self:this}}};D(yt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(yt,"type",f.LiteralValue),D(yt,"USER_MANAGED_PARENT_TYPES",[f.DataType,f.InputMap,f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.VariableInstance,f.ValueDescriptor,f.OutputMap]),D(yt,"PARENT_TYPES",[...yt.USER_MANAGED_PARENT_TYPES]),D(yt,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),D(yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(yt,"BASE_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,...yt.INMUTABLE_BASE_PROPERTIES]),D(yt,"MUTABLE_META_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES]),D(yt,"INMUTABLE_META_PROPERTIES",[...yt.INMUTABLE_BASE_PROPERTIES]),D(yt,"META_PROPERTIES",[...yt.MUTABLE_META_PROPERTIES,...yt.INMUTABLE_META_PROPERTIES]),D(yt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(yt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),D(yt,"UPSTREAM_PROPERTIES",[...yt.MUTABLE_UPSTREAM_PROPERTIES,...yt.INMUTABLE_UPSTREAM_PROPERTIES]),D(yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),D(yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(yt,"DOWNSTREAM_PROPERTIES",[...yt.MUTABLE_DOWNSTREAM_PROPERTIES,...yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(yt,"PROPERTIES",[...yt.META_PROPERTIES,...yt.UPSTREAM_PROPERTIES,...yt.DOWNSTREAM_PROPERTIES]);let bi=yt;function uM(d,u){var t;const i=[],a=[],l=[],p=[];if(((t=d.implements)==null?void 0:t.id)===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id){let y=d.defaultValue;if(!d.defaultValue){const v=bi.new(u);v.name=X.EntityTemplate,v.parent=d.toReference();const T=ee(v,d.project);T.hydrateAncestors(),T.addSelfToProject(u),u==null||u.add(T,K.Added),a.push(T),T.initChildren(u),y=T}if(!y.valueAsTypeSingle){const v=Ix(d.project);v&&y.setValueAsTypeSingle(v,u)}}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:d}}var cM=(d=>(d.PropertyImplements="property-implements",d.PropertyExtends="property-extends",d.DataTypeEntity="data-type-entity",d))(cM||{});const pt=class pt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"private");D(this,"abstract");D(this,"index");D(this,"static");D(this,"required");D(this,"constant",!1);D(this,"type",f.Property);D(this,"hidden",!1);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"implements",null);D(this,"extends",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.Property,name:"",codeName:null,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(i,a){const l=W(i.parent),p=a.get(l);let t=null;if(i.implements){const w=W(i.implements);t=a.get(w)}let y=null;if(i.extends){const w=W(i.extends);y=a.get(w)}const v={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.Property,index:p.properties.length,private:i.private||!1,abstract:i.abstract||!1,static:i.static||!1,required:i.required||!1,constant:i.constant||!1,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:t,extends:y,dataType:null,parent:p},T=ee(v,a);return T.setParent(p,null),T}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=$fe(l,a),y=vb(l,a);return p.push(...t,...y,...vr(l)),{errors:p,modifiedData:l}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(a=>{var l;return a.id===((l=this.extends)==null?void 0:l.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.implements)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
46
|
+
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return a==="value-as-type-single"&&(this.valueAsTypeSingle=null,l==null||l.add(this,K.Updated)),a==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(T=>T.id!==i.id),l==null||l.add(this,K.Updated)),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return a==="value-as-type-single"&&(this.valueAsTypeSingle=i,l==null||l.add(this,K.Updated)),a==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],i],l==null||l.add(this,K.Updated)),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==f.BuiltInBaseEntity&&this.valueAsTypeSingle.unsubscribeDependents([{entity:this,field:"value-as-type-single"}]),this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)&&this.valueAsTypeList.forEach(i=>{i.type!==f.BuiltInBaseEntity&&i.unsubscribeDependents([{entity:this,field:"value-as-type-list"}])}),this}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(i=>{i.type!==f.BuiltInBaseEntity&&i.subscribeDependents([{entity:this,field:"value-as-type-list"}])}):this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==f.BuiltInBaseEntity&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.valueAsTypeSingle=this.valueAsTypeSingle,i.valueAsTypeList=this.valueAsTypeList?[...this.valueAsTypeList]:this.valueAsTypeList,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new yt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.valueAsTypeSingle=y.valueAsTypeSingle,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent&&i.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else if(i.standaloneParent){const l=W(i.standaloneParent),p=this.project.get(l);if(p)this.setStandaloneParent(p);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.valueAsTypeList&&Array.isArray(i.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],i.valueAsTypeList.forEach(l=>{const p=W(l),t=this.project.get(p);t&&this.valueAsTypeList.push(t)});else if(i.valueAsTypeSingle){const l=W(i.valueAsTypeSingle),p=this.project.get(l);p&&(this.valueAsTypeSingle=p)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else if(this.initialData.standaloneParent){const t=W(this.initialData.standaloneParent),y=this.project.get(t);if(y)this.setStandaloneParent(y);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.valueAsTypeList.push(v)});else if(this.initialData.valueAsTypeSingle){const t=W(this.initialData.valueAsTypeSingle),y=this.project.get(t);y&&(this.valueAsTypeSingle=y)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],p=[],t=[];return((y=this.parent)==null?void 0:y.type)===f.DataType?this.parent.setEntity(this,i):(v=this.parent)==null||v.setDefaultValue(this,i),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setStandaloneParent(i){return this.standaloneParent=i,this}setValueAsTypeSingle(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-as-type-single"))){return this.valueAsTypeSingle!==i&&(this.valueAsTypeSingle=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-as-type-single",this.id),this}setValueAsTypeList(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-as-type-list"))){var l,p;return!i&&this.valueAsTypeList?(this.valueAsTypeList=null,a==null||a.add(this,K.Updated)):i&&!this.valueAsTypeList?(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)):i&&this.valueAsTypeList&&((l=this.valueAsTypeList)==null?void 0:l.length)!==i.length?(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)):i&&this.valueAsTypeList&&((p=this.valueAsTypeList)!=null&&p.every((t,y)=>t!==i[y]))&&(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-as-type-list",this.id),this}setValueAsType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-as-type"))){return i?(Array.isArray(i)?this.setValueAsTypeList(i,a):this.setValueAsTypeSingle(i,a),a==null||a.attemptAutoclose("set-value-as-type",this.id),this):(this.setValueAsTypeSingle(null,a),this.setValueAsTypeList(null,a),this)}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(a=>{if(a.type===f.GenericReference){const p=this.project.findSubscribedBuiltInInstanceFromReference(a);if(!p)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.entityType}' with id '${a.entityId}' that is not part of the project state.`);return p}const l=this.project.get(a.id);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.type}' with id '${a.id}' that is not part of the project state.`);return l});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===f.GenericReference){const l=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=l,this}const a=this.project.get(this.initialData.valueAsTypeSingle.id);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=a}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(a=>{if(a.type===f.GenericReference){const p=this.project.findSubscribedBuiltInInstanceFromReference(a);if(!p)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.entityType}' with id '${a.entityId}' that is not part of the project state.`);return p}const l=this.project.get(a.id);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.type}' with id '${a.id}' that is not part of the project state.`);return l});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===f.GenericReference){const l=W(this.initialData.valueAsTypeSingle),p=l?this.project.get(l):null;if(!p)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=p,this}const a=this.project.get(this.initialData.valueAsTypeSingle.id);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=a}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.autogeneration=i.autogeneration!==void 0?i.autogeneration:p.autogeneration,this.value=i.value!==void 0?i.value:p.value,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await yt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await yt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent&&(this.parent.type===f.DataType?this.parent.setEntity(null,i):ev.includes(this.parent.type)&&this.parent.setDefaultValue(null,i),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlat(i)):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatIds(i)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toJSON(i))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(t=>t.toJSON(i)):null,parent:(l=this.parent)==null?void 0:l.toReference(),standaloneParent:(p=this.standaloneParent)==null?void 0:p.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...i,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(A=>this.project.getBuiltIn(A.id)?A.toJSON():A.toJSONClone({...i,newId:null})):null,parent:(T=this.parent)==null?void 0:T.toReference({seenEntityMaps:i.seenEntityMaps}),standaloneParent:(w=this.standaloneParent)==null?void 0:w.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((p=this.valueAsTypeSingle)==null?void 0:p.toReference(i))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(v=>v.toReference(i)):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.toReference(i),standaloneParent:(y=this.standaloneParent)==null?void 0:y.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatJSON(i)):[]])}toGenerationTarget(){var i,a,l;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((i=this.valueAsTypeSingle)==null?void 0:i.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(p=>p.id):null,value:this.value,autogeneration:this.autogeneration,parent:(a=this.parent)==null?void 0:a.id,standaloneParent:(l=this.standaloneParent)==null?void 0:l.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatGenerationTarget(i)):[]])}clearErrors(){return this.errors=[],this}validate(){const i=lM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const T=Kt(y,t);return T.initChildren(i),a&&T.setParent(a,null),i==null||i.add(T,K.Added),p&&T.subscribe(),i==null||i.attemptAutoclose("clone-entity",this.id),T}merge(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"merge-literal-value"))){const l=[],p=[],t=[],y=[];return this.valueAsTypeSingle!==(i==null?void 0:i.valueAsTypeSingle)&&(this.setValueAsType(i.valueAsTypeSingle,a),l.push(this)),this.value!==i.value&&(this.metaSync({value:i.value},a),l.push(this)),this.autogeneration!==i.autogeneration&&(this.metaSync({autogeneration:i.autogeneration},a),l.push(this)),this.name!==i.name&&(this.metaSync({name:i.name},a),l.push(this)),a==null||a.attemptAutoclose("merge-literal-value",this.id),{updated:R(l),added:R(p),removed:R(t),affected:R(y),self:this}}};D(yt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(yt,"type",f.LiteralValue),D(yt,"USER_MANAGED_PARENT_TYPES",[f.DataType,f.InputMap,f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.VariableInstance,f.ValueDescriptor,f.OutputMap]),D(yt,"PARENT_TYPES",[...yt.USER_MANAGED_PARENT_TYPES]),D(yt,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),D(yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(yt,"BASE_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,...yt.INMUTABLE_BASE_PROPERTIES]),D(yt,"MUTABLE_META_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES]),D(yt,"INMUTABLE_META_PROPERTIES",[...yt.INMUTABLE_BASE_PROPERTIES]),D(yt,"META_PROPERTIES",[...yt.MUTABLE_META_PROPERTIES,...yt.INMUTABLE_META_PROPERTIES]),D(yt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(yt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),D(yt,"UPSTREAM_PROPERTIES",[...yt.MUTABLE_UPSTREAM_PROPERTIES,...yt.INMUTABLE_UPSTREAM_PROPERTIES]),D(yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),D(yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(yt,"DOWNSTREAM_PROPERTIES",[...yt.MUTABLE_DOWNSTREAM_PROPERTIES,...yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(yt,"PROPERTIES",[...yt.META_PROPERTIES,...yt.UPSTREAM_PROPERTIES,...yt.DOWNSTREAM_PROPERTIES]);let bi=yt;function uM(d,u){var t;const i=[],a=[],l=[],p=[];if(((t=d.implements)==null?void 0:t.id)===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id){let y=d.defaultValue;if(!d.defaultValue){const v=bi.new(u);v.name=X.EntityTemplate,v.parent=d.toReference();const T=ee(v,d.project);T.hydrateAncestors(),T.addSelfToProject(u),u==null||u.add(T,K.Added),a.push(T),T.initChildren(u),y=T}if(!y.valueAsTypeSingle){const v=Ix(d.project);v&&y.setValueAsTypeSingle(v,u)}}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:d}}var cM=(d=>(d.PropertyImplements="property-implements",d.PropertyExtends="property-extends",d.DataTypeEntity="data-type-entity",d))(cM||{});const pt=class pt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"private");D(this,"abstract");D(this,"index");D(this,"static");D(this,"required");D(this,"constant",!1);D(this,"type",f.Property);D(this,"hidden",!1);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"implements",null);D(this,"extends",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.Property,name:"",codeName:null,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(i,a){const l=W(i.parent),p=a.get(l);let t=null;if(i.implements){const w=W(i.implements);t=a.get(w)}let y=null;if(i.extends){const w=W(i.extends);y=a.get(w)}const v={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.Property,index:p.properties.length,private:i.private||!1,abstract:i.abstract||!1,static:i.static||!1,required:i.required||!1,constant:i.constant||!1,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:t,extends:y,dataType:null,parent:p},T=ee(v,a);return T.setParent(p,null),T}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=$fe(l,a),y=vb(l,a);return p.push(...t,...y,...vr(l)),{errors:p,modifiedData:l}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(a=>{var l;return a.id===((l=this.extends)==null?void 0:l.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.implements)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
47
47
|
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})),(i.readsValue||i.writesValue)&&a.push(new Q({id:`${this.id}--${oe.InvalidObjectStructure}`,code:oe.InvalidObjectStructure,severity:Z.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
|
|
48
|
-
${By}`,issue:null})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return uM(this,a),a==null||a.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,l),p.push(this)),a==="property-extends"){const{updated:T,added:w,removed:A,affected:V}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A),v.push(...V)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,l),p.push(this)),a==="property-extends"){const{updated:T,added:w,removed:A,affected:V}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A),v.push(...V)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(t=this.dataType)==null?void 0:t.entity)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.off(yr.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,l,p,t,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(t=this.dataType)==null?void 0:t.entity)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.on(yr.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new pt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new pt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=W(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(i.extends){const l=W(i.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const t=W(this.initialData.implements),y=this.project.get(t);if(y)this.setImplements(y,null),i.push(y);else if(t)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${t}" which is missing in the project`)}if(this.initialData.extends){const t=W(this.initialData.extends),y=this.project.get(t);if(y)this.setExtends(y,null),i.push(y);else if(t)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'extends' reference "${t}" which is missing in the project`)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T,affected:w}=this.syncWithImplementation(i);a.push(...y),l.push(...v),p.push(...T),t.push(...w);const{updated:A,added:V,removed:N,affected:j}=uM(this,i);return a.push(...A),l.push(...V),p.push(...N),t.push(...j),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent.addProperty(this),a.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=ee(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=ee(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=ee(this.initialData.extends,this.project);this.setExtends(a,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.abstract=i.abstract!==void 0?i.abstract:p.abstract,this.private=i.private!==void 0?i.private:p.private,this.index=i.index||(i.index!==0?p.index:0),this.static=i.static!==void 0?i.static:p.static,this.hidden=i.hidden!==void 0?i.hidden:p.hidden,this.constant=i.constant!==void 0?i.constant:p.constant,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await pt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await pt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await pt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await pt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await pt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await pt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.DefinitionEntity&&(this.parent.removeProperty(this),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.dataType){const{updated:v,removed:T}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===f.DefinitionEntity&&(this.parent.addProperty(this),t.push(this.parent)),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,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(i=new Set){var a,l,p,t;return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,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:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,extends:((t=this.extends)==null?void 0:t.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,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.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:(()=>{var A;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),extends:(()=>{var A;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y,v;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,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:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((t=this.dataType)==null?void 0:t.toReference(i))||null,implements:((y=this.implements)==null?void 0:y.toReference(i))||null,extends:((v=this.extends)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p,t;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...((t=this.implements)==null?void 0:t.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i,a;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:(i=this.implements)==null?void 0:i.id,extends:(a=this.extends)==null?void 0:a.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){return this.errors=nM(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),l=null){const p=l||P.UUID.uuid(),t=pt.new(a);t.id=p,t.name=this.name,t.description=this.description,t.index=this.index,t.private=this.private,t.required=this.required,t.static=this.static,t.constant=this.constant,t.hidden=this.hidden,t.parent=i.toReference(),t.implements=this.toJSON();const y=ee(t,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var N,j;let t=Ir(a,this);const y=l||P.UUID.uuid();let v=a||this.parent;const T={hidden:!1,id:y,version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,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:v},w=Kt(T,t);p&&w.subscribe(),w.hydrateAncestors(),p&&w.addSelfToProject(i),w.setParent(v,null),w.initChildren(i),i==null||i.add(w,K.Added);const A=((N=this.dataType)==null?void 0:N.clone(i,w,P.UUID.uuid(),p))||null;A&&w.setDataType(A,i);const V=(j=this.defaultValue)==null?void 0:j.clone(i,w,P.UUID.uuid(),p);return w.setDefaultValue(V||null,i),this.implements&&w.setImplements(this.implements,i),w.addSelfToProject(null),i==null||i.attemptAutoclose("clone-entity",this.id),w}setDataType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],l=[],p=[],t=[];if(this.implements){const v=this.implements;if(!this.dataType&&v.dataType){const T=v.dataType.clone(i,this,P.UUID.uuid(),!0);this.setDataType(T,i),l.push(T)}if(this.implements.defaultValue&&!this.defaultValue){const T=(y=this.implements.defaultValue)==null?void 0:y.clone(i,this,P.UUID.uuid(),!0);this.setDefaultValue(T||null,i),l.push(T)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(pt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(pt,"type",f.Property),D(pt,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),D(pt,"PARENT_TYPES",[...pt.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),D(pt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant"]),D(pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(pt,"BASE_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,...pt.INMUTABLE_BASE_PROPERTIES]),D(pt,"MUTABLE_META_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,"index"]),D(pt,"INMUTABLE_META_PROPERTIES",[...pt.INMUTABLE_BASE_PROPERTIES]),D(pt,"META_PROPERTIES",[...pt.MUTABLE_META_PROPERTIES,...pt.INMUTABLE_META_PROPERTIES]),D(pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(pt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),D(pt,"UPSTREAM_PROPERTIES",[...pt.MUTABLE_UPSTREAM_PROPERTIES,...pt.INMUTABLE_UPSTREAM_PROPERTIES]),D(pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),D(pt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(pt,"DOWNSTREAM_PROPERTIES",[...pt.MUTABLE_DOWNSTREAM_PROPERTIES,...pt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(pt,"PROPERTIES",[...pt.META_PROPERTIES,...pt.UPSTREAM_PROPERTIES,...pt.DOWNSTREAM_PROPERTIES]);let ua=pt;function pM(d){const u=Ice(),i=d.toJSON();u.safeParse(i).success;const l=Lfe(d),p=Bfe(d),t=Xi(d);d.inputs.forEach(v=>v.validate()),t.forEach(v=>v.validate());const y=[...l,...p];return zt(d.errors,y)}function Lfe(d){const u=[];if(!d.calls.length&&!d.extends){const i=nt({id:`${d.id}--${se.ScopeWithoutLogic}`,message:`Action "${re(d,d.project)}" with id "${d.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:Z.Warning,code:se.ScopeWithoutLogic,entity:d});u.push(i.error)}return zt(d.errors,u)}function Bfe(d){const u=[];return d.implements,zt(d.errors,u)}const Mfe=Object.freeze(Object.defineProperty({__proto__:null,validate:pM},Symbol.toStringTag,{value:"Module"}));var fM=(d=>(d.FunctionDeclarationImplements="function-declaration-implements",d.FunctionDeclarationExtends="function-declaration-extends",d))(fM||{});const mt=class mt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"x");D(this,"y");D(this,"collapsed");D(this,"private");D(this,"index",null);D(this,"type",f.FunctionDeclaration);D(this,"implements",null);D(this,"extends",null);D(this,"inputs",[]);D(this,"calls",[]);D(this,"parent");D(this,"detachedChildren",[]);D(this,"errors",[]);D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.collapsed=i.collapsed,this.x=i.x,this.y=i.y,this.index=i.index}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.FunctionDeclaration,name:"",codeName:null,description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const T=W(i.parent);l=a.get(T)}let p=null;if(i.implements){const T=W(i.implements);p=a.get(T)}let t=null;if(i.extends){const T=W(i.extends);t=a.get(T)}const y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.FunctionDeclaration,index:l.type===f.DefinitionEntity?l.methods.length:null,codeName:i.codeName||null,description:i.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:p,extends:t,x:0,y:0,parent:l},v=ee(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){var A;let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop],optional:!0},implements:{list:!1,types:[f.ActionDescriptor],optional:!0}},a);l=t.modifiedData;const y=yb(l,a),v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DefinitionEntity){const V=v,j=wi(V).filter(q=>!q.interactive),k=V.methods.find(q=>{var Y;return((Y=q.implements)==null?void 0:Y.id)===l.implements});if(k&&p.push(new Q({id:`${l.id}--${oe.MethodOverwritesOtherSiblingWithSameImplementation}`,code:oe.MethodOverwritesOtherSiblingWithSameImplementation,severity:Z.Error,message:`The '${f.FunctionDeclaration}' with id "${l.id}" is trying to implement the '${f.ActionDescriptor}' with id "${l.implements}", but the parent definition-entity already has a ${f.FunctionDeclaration} with id '${k.id}' that implements the same base method.
|
|
48
|
+
${By}`,issue:null})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return uM(this,a),a==null||a.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,l),p.push(this)),a==="property-extends"){const{updated:T,added:w,removed:A,affected:V}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A),v.push(...V)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,l),p.push(this)),a==="property-extends"){const{updated:T,added:w,removed:A,affected:V}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A),v.push(...V)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(t=this.dataType)==null?void 0:t.entity)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.off(yr.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,l,p,t,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(t=this.dataType)==null?void 0:t.entity)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.on(yr.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new pt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new pt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=W(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(i.extends){const l=W(i.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const t=W(this.initialData.implements),y=this.project.get(t);if(y)this.setImplements(y,null),i.push(y);else if(t)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${t}" which is missing in the project`)}if(this.initialData.extends){const t=W(this.initialData.extends),y=this.project.get(t);if(y)this.setExtends(y,null),i.push(y);else if(t)throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'extends' reference "${t}" which is missing in the project`)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T,affected:w}=this.syncWithImplementation(i);a.push(...y),l.push(...v),p.push(...T),t.push(...w);const{updated:A,added:V,removed:N,affected:j}=uM(this,i);return a.push(...A),l.push(...V),p.push(...N),t.push(...j),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent.addProperty(this),a.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=ee(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=ee(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=ee(this.initialData.extends,this.project);this.setExtends(a,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.abstract=i.abstract!==void 0?i.abstract:p.abstract,this.private=i.private!==void 0?i.private:p.private,this.index=i.index||(i.index!==0?p.index:0),this.static=i.static!==void 0?i.static:p.static,this.hidden=i.hidden!==void 0?i.hidden:p.hidden,this.constant=i.constant!==void 0?i.constant:p.constant,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await pt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await pt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await pt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await pt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await pt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await pt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.DefinitionEntity&&(this.parent.removeProperty(this),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.dataType){const{updated:v,removed:T}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===f.DefinitionEntity&&(this.parent.addProperty(this),t.push(this.parent)),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,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(i=new Set){var a,l,p,t;return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,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:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,extends:((t=this.extends)==null?void 0:t.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,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.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:(()=>{var A;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),extends:(()=>{var A;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y,v;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,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:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((t=this.dataType)==null?void 0:t.toReference(i))||null,implements:((y=this.implements)==null?void 0:y.toReference(i))||null,extends:((v=this.extends)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p,t;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...((t=this.implements)==null?void 0:t.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i,a;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:(i=this.implements)==null?void 0:i.id,extends:(a=this.extends)==null?void 0:a.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){return this.errors=nM(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),l=null){const p=l||P.UUID.uuid(),t=pt.new(a);t.id=p,t.name=this.name,t.description=this.description,t.index=this.index,t.private=this.private,t.required=this.required,t.static=this.static,t.constant=this.constant,t.hidden=this.hidden,t.parent=i.toReference(),t.implements=this.toJSON();const y=ee(t,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var N,j;let t=Ir(a,this);const y=l||P.UUID.uuid();let v=a||this.parent;const T={hidden:!1,id:y,version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,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:v},w=Kt(T,t);p&&w.subscribe(),w.hydrateAncestors(),p&&w.addSelfToProject(i),w.setParent(v,null),w.initChildren(i),i==null||i.add(w,K.Added);const A=((N=this.dataType)==null?void 0:N.clone(i,w,P.UUID.uuid(),p))||null;A&&w.setDataType(A,i);const V=(j=this.defaultValue)==null?void 0:j.clone(i,w,P.UUID.uuid(),p);return w.setDefaultValue(V||null,i),this.implements&&w.setImplements(this.implements,i),w.addSelfToProject(null),i==null||i.attemptAutoclose("clone-entity",this.id),w}setDataType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],l=[],p=[],t=[];if(this.implements){const v=this.implements;if(!this.dataType&&v.dataType){const T=v.dataType.clone(i,this,P.UUID.uuid(),!0);this.setDataType(T,i),l.push(T)}if(this.implements.defaultValue&&!this.defaultValue){const T=(y=this.implements.defaultValue)==null?void 0:y.clone(i,this,P.UUID.uuid(),!0);this.setDefaultValue(T||null,i),l.push(T)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(pt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(pt,"type",f.Property),D(pt,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),D(pt,"PARENT_TYPES",[...pt.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),D(pt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant"]),D(pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(pt,"BASE_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,...pt.INMUTABLE_BASE_PROPERTIES]),D(pt,"MUTABLE_META_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,"index"]),D(pt,"INMUTABLE_META_PROPERTIES",[...pt.INMUTABLE_BASE_PROPERTIES]),D(pt,"META_PROPERTIES",[...pt.MUTABLE_META_PROPERTIES,...pt.INMUTABLE_META_PROPERTIES]),D(pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(pt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),D(pt,"UPSTREAM_PROPERTIES",[...pt.MUTABLE_UPSTREAM_PROPERTIES,...pt.INMUTABLE_UPSTREAM_PROPERTIES]),D(pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),D(pt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(pt,"DOWNSTREAM_PROPERTIES",[...pt.MUTABLE_DOWNSTREAM_PROPERTIES,...pt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(pt,"PROPERTIES",[...pt.META_PROPERTIES,...pt.UPSTREAM_PROPERTIES,...pt.DOWNSTREAM_PROPERTIES]);let ua=pt;function pM(d){const u=Ice(),i=d.toJSON();u.safeParse(i).success;const l=Lfe(d),p=Bfe(d),t=Xi(d);d.inputs.forEach(v=>v.validate()),t.forEach(v=>v.validate());const y=[...l,...p];return zt(d.errors,y)}function Lfe(d){const u=[];if(!d.calls.length&&!d.extends){const i=nt({id:`${d.id}--${se.ScopeWithoutLogic}`,message:`Action "${re(d,d.project)}" with id "${d.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:Z.Warning,code:se.ScopeWithoutLogic,entity:d});u.push(i.error)}return zt(d.errors,u)}function Bfe(d){const u=[];return d.implements,zt(d.errors,u)}const Mfe=Object.freeze(Object.defineProperty({__proto__:null,validate:pM},Symbol.toStringTag,{value:"Module"}));var fM=(d=>(d.FunctionDeclarationImplements="function-declaration-implements",d.FunctionDeclarationExtends="function-declaration-extends",d))(fM||{});const mt=class mt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"x");D(this,"y");D(this,"collapsed");D(this,"private");D(this,"index",null);D(this,"type",f.FunctionDeclaration);D(this,"implements",null);D(this,"extends",null);D(this,"inputs",[]);D(this,"calls",[]);D(this,"parent");D(this,"detachedChildren",[]);D(this,"errors",[]);D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.collapsed=i.collapsed,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.index=i.index}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.FunctionDeclaration,name:"",codeName:null,description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const T=W(i.parent);l=a.get(T)}let p=null;if(i.implements){const T=W(i.implements);p=a.get(T)}let t=null;if(i.extends){const T=W(i.extends);t=a.get(T)}const y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.FunctionDeclaration,index:l.type===f.DefinitionEntity?l.methods.length:null,codeName:i.codeName||null,description:i.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:p,extends:t,x:0,y:0,parent:l},v=ee(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){var A;let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop],optional:!0},implements:{list:!1,types:[f.ActionDescriptor],optional:!0}},a);l=t.modifiedData;const y=yb(l,a),v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DefinitionEntity){const V=v,j=wi(V).filter(q=>!q.interactive),k=V.methods.find(q=>{var Y;return((Y=q.implements)==null?void 0:Y.id)===l.implements});if(k&&p.push(new Q({id:`${l.id}--${oe.MethodOverwritesOtherSiblingWithSameImplementation}`,code:oe.MethodOverwritesOtherSiblingWithSameImplementation,severity:Z.Error,message:`The '${f.FunctionDeclaration}' with id "${l.id}" is trying to implement the '${f.ActionDescriptor}' with id "${l.implements}", but the parent definition-entity already has a ${f.FunctionDeclaration} with id '${k.id}' that implements the same base method.
|
|
49
49
|
A ${f.FunctionDeclaration} that has a parent of type '${f.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${f.ActionDescriptor}' more than once.
|
|
50
50
|
${f.ActionDescriptor} entities inside a ${f.DefinitionEntity} are considered abstract methods that can be implemented by ${f.FunctionDeclaration} entities inside the same parent.
|
|
51
51
|
If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${f.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null})),!l.implements&&j.length){let q=j.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${V.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${qe(j.map(Y=>re(Y,Y.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${V.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${re(j[0],j[0].project)}").`;q+=`
|
|
@@ -70,7 +70,7 @@ All built-in 'action-descriptor' entity ids are:
|
|
|
70
70
|
`;p.push(new Q({id:`${l.id}--${S.InvalidReference}`,code:S.InvalidReference,severity:Z.Error,message:`Entity of type "${f.Operation}" with id "${l.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'action-descriptor' entity.
|
|
71
71
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${v}`,issue:null}))}return{errors:p,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
72
72
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
73
|
-
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Et(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Et(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:w,added:A,removed:V}=this.syncOutputs(i),{updated:N,added:j,removed:k}=this.declaration.syncOperationInstance(this,i);return a.push(...y,...w,...N),l.push(...v,...A,...N),p.push(...T,...V,...N),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addOperation(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&l.setParent(this.parent,null);return l.initChildren(i),l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=ee(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Et.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Et.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Et.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Et.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Et.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Et.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeOperation(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.process){const{updated:T,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:T,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[]])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),error:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=yM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(j=this.inputs)==null?void 0:j.map((q,Y)=>q.clone(i,A,w+"-input-map-"+Y+"-id",p));A.inputs=V;const N=(k=this.outputs)==null?void 0:k.map((q,Y)=>q.clone(i,A,w+"-output-map-"+Y+"-id",p));return A.outputs=N,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],t=[];return this.outputs.forEach(v=>{if(!this.declaration.outputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,T)=>{const w=this.outputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===ue.FixedArguments&&!this.inputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id}));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.outputs.filter(A=>A.parentRelationType===ue.FixedReturns&&!this.outputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id}));this.outputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.outputs.forEach(j=>{j.index>=A.index&&j.index++});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:A.toJSON(),defaultValue:null,writesValues:[],index:A.index,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i)}),this.outputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedOutputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Et,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Et,"type",f.Operation),D(Et,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(Et,"PARENT_TYPES",[...Et.USER_MANAGED_PARENT_TYPES]),D(Et,"MUTABLE_BASE_PROPERTIES",[]),D(Et,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Et,"BASE_PROPERTIES",[...Et.MUTABLE_BASE_PROPERTIES,...Et.INMUTABLE_BASE_PROPERTIES]),D(Et,"MUTABLE_META_PROPERTIES",[...Et.MUTABLE_BASE_PROPERTIES,"x","y"]),D(Et,"INMUTABLE_META_PROPERTIES",[...Et.INMUTABLE_BASE_PROPERTIES]),D(Et,"META_PROPERTIES",[...Et.MUTABLE_META_PROPERTIES,...Et.INMUTABLE_META_PROPERTIES]),D(Et,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),D(Et,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),D(Et,"UPSTREAM_PROPERTIES",[...Et.MUTABLE_UPSTREAM_PROPERTIES,...Et.INMUTABLE_UPSTREAM_PROPERTIES]),D(Et,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),D(Et,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Et,"DOWNSTREAM_PROPERTIES",[...Et.MUTABLE_DOWNSTREAM_PROPERTIES,...Et.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Et,"PROPERTIES",[...Et.META_PROPERTIES,...Et.UPSTREAM_PROPERTIES,...Et.DOWNSTREAM_PROPERTIES]);let ja=Et;function vM(d){var p;const u=$de(),i=d.toJSON();u.safeParse(i).success,(p=d.dataType)==null||p.validate();const l=[];if(d.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const t=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(t.error)}return zt(d.errors,l)}const Gfe=Object.freeze(Object.defineProperty({__proto__:null,validate:vM},Symbol.toStringTag,{value:"Module"}));var EM=(d=>(d.Implements="implements",d.DataTypeEntity="data-type-entity",d))(EM||{});const Tt=class Tt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"index");D(this,"required");D(this,"constant",!0);D(this,"isError");D(this,"type",f.ReturnDeclaration);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"readsValue",null);D(this,"implements",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name,this.description=i.description,this.required=i.required,this.constant=!0,this.isError=i.isError}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ReturnDeclaration,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l);let t=null;if(i.readsValue){const T=W(i.readsValue);t=a.get(T)}const y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ReturnDeclaration,index:p.outputs.length,isError:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:null,required:i.required,constant:!0,readsValue:t,dataType:null,parent:p},v=ee(y,a);return v.setParent(p,null),v}static validateGenerationTarget(i,a){var v,T;let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.ReturnStatement,f.Search,f.BreakStatement,f.ContinueStatement]}},a),y=Tb(l,a);if(l=t.modifiedData,l.parent){const w=a.get(W(l.parent));if(w&&[f.BreakStatement,f.ContinueStatement].includes(w.type)){const A=w,V=A.parent,N=[...V.breakStatements.filter(k=>k.id!==w.id),...V.continueStatements.filter(k=>k.id!==w.id)];if(A.outputs.length)p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ReturnDeclaration}' with id '${l.id}' cannot be added to the parent entity of type '${A.type}' with id '${A.id}'. This '${A.type}' already has return declarations.
|
|
73
|
+
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Et(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Et(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:w,added:A,removed:V}=this.syncOutputs(i),{updated:N,added:j,removed:k}=this.declaration.syncOperationInstance(this,i);return a.push(...y,...w,...N),l.push(...v,...A,...N),p.push(...T,...V,...N),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addOperation(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&l.setParent(this.parent,null);return l.initChildren(i),l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=ee(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Et.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Et.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Et.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Et.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Et.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Et.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeOperation(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.process){const{updated:T,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:T,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[]])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),error:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=yM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(j=this.inputs)==null?void 0:j.map((q,Y)=>q.clone(i,A,w+"-input-map-"+Y+"-id",p));A.inputs=V;const N=(k=this.outputs)==null?void 0:k.map((q,Y)=>q.clone(i,A,w+"-output-map-"+Y+"-id",p));return A.outputs=N,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],t=[];return this.outputs.forEach(v=>{if(!this.declaration.outputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,T)=>{const w=this.outputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===ue.FixedArguments&&!this.inputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id}));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.outputs.filter(A=>A.parentRelationType===ue.FixedReturns&&!this.outputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id}));this.outputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.outputs.forEach(j=>{j.index>=A.index&&j.index++});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:A.toJSON(),defaultValue:null,writesValues:[],index:A.index,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i)}),this.outputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedOutputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Et,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Et,"type",f.Operation),D(Et,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(Et,"PARENT_TYPES",[...Et.USER_MANAGED_PARENT_TYPES]),D(Et,"MUTABLE_BASE_PROPERTIES",[]),D(Et,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Et,"BASE_PROPERTIES",[...Et.MUTABLE_BASE_PROPERTIES,...Et.INMUTABLE_BASE_PROPERTIES]),D(Et,"MUTABLE_META_PROPERTIES",[...Et.MUTABLE_BASE_PROPERTIES,"x","y"]),D(Et,"INMUTABLE_META_PROPERTIES",[...Et.INMUTABLE_BASE_PROPERTIES]),D(Et,"META_PROPERTIES",[...Et.MUTABLE_META_PROPERTIES,...Et.INMUTABLE_META_PROPERTIES]),D(Et,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),D(Et,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),D(Et,"UPSTREAM_PROPERTIES",[...Et.MUTABLE_UPSTREAM_PROPERTIES,...Et.INMUTABLE_UPSTREAM_PROPERTIES]),D(Et,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),D(Et,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Et,"DOWNSTREAM_PROPERTIES",[...Et.MUTABLE_DOWNSTREAM_PROPERTIES,...Et.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Et,"PROPERTIES",[...Et.META_PROPERTIES,...Et.UPSTREAM_PROPERTIES,...Et.DOWNSTREAM_PROPERTIES]);let ja=Et;function vM(d){var p;const u=$de(),i=d.toJSON();u.safeParse(i).success,(p=d.dataType)==null||p.validate();const l=[];if(d.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const t=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(t.error)}return zt(d.errors,l)}const Gfe=Object.freeze(Object.defineProperty({__proto__:null,validate:vM},Symbol.toStringTag,{value:"Module"}));var EM=(d=>(d.Implements="implements",d.DataTypeEntity="data-type-entity",d))(EM||{});const Tt=class Tt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"index");D(this,"required");D(this,"constant",!0);D(this,"isError");D(this,"type",f.ReturnDeclaration);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"readsValue",null);D(this,"implements",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name,this.description=i.description,this.required=i.required,this.constant=!0,this.codeName=i.codeName,this.isError=i.isError}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ReturnDeclaration,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l);let t=null;if(i.readsValue){const T=W(i.readsValue);t=a.get(T)}const y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ReturnDeclaration,index:p.outputs.length,isError:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:null,required:i.required,constant:!0,readsValue:t,dataType:null,parent:p},v=ee(y,a);return v.setParent(p,null),v}static validateGenerationTarget(i,a){var v,T;let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.ReturnStatement,f.Search,f.BreakStatement,f.ContinueStatement]}},a),y=Tb(l,a);if(l=t.modifiedData,l.parent){const w=a.get(W(l.parent));if(w&&[f.BreakStatement,f.ContinueStatement].includes(w.type)){const A=w,V=A.parent,N=[...V.breakStatements.filter(k=>k.id!==w.id),...V.continueStatements.filter(k=>k.id!==w.id)];if(A.outputs.length)p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ReturnDeclaration}' with id '${l.id}' cannot be added to the parent entity of type '${A.type}' with id '${A.id}'. This '${A.type}' already has return declarations.
|
|
74
74
|
${zb}`,issue:null}));else{const k=(T=(v=N[0])==null?void 0:v.outputs[0])==null?void 0:T.name;k!==l.name&&p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ReturnDeclaration}' with id '${l.id}' cannot be added to the parent entity of type '${A.type}' with id '${A.id}'. This new 'return-declaration' doesn't have the same name "${k}" as the return declarations on the other statements in the same scope.
|
|
75
75
|
${zb}`,issue:null}))}}else if(w&&w.type===f.ReturnStatement){const A=w.parent;if(A&&Wt.includes(A.type)){const V=A.implements;if(V){const N=V.outputs.find(te=>te.name===l.name),j=V.outputs.filter(te=>!w.outputs.find(ne=>ne.type===f.ReturnDeclaration&&ne.name===te.name)),k=w.outputs.filter(te=>te.type===f.ReturnDeclaration),q=k.find(te=>te.name===l.name),Y=k.length?`The parent entity already implements the following return declarations: ${qe(k.map(te=>`'${te.id}' (${te.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",ie=j.length?`The parent entity is still missing the following returns in the implementation: ${qe(j.map(te=>`'${te.id}' (${te.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";N?q&&p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ReturnDeclaration}' with id '${l.id}' should not exist in a parent entity of type '${w.type}' with id '${w.id}' that implements a ${f.ActionDescriptor} with fixed outputs.
|
|
76
76
|
Adding a new return would make the implementation invalid. An return with the same name already exists in the parent entity.
|
|
@@ -89,7 +89,7 @@ Specifically for return statements the parent needs to always be the 'function-d
|
|
|
89
89
|
${Uy(a)}`,issue:null}));else if(!a.get(i.implements))p.push(new Q({id:`${i.id}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that isn't found in the project. The 'implements' property must point to one of the built-in action descriptors reserved for 'global-event' entities.
|
|
90
90
|
${Uy(a)}`,issue:null}));else if(!a.globalEventActionDescriptors.find(T=>T.id===i.implements))p.push(new Q({id:`${i.id}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that isn't pointing to an action descriptor reserved for 'global-event' entities.
|
|
91
91
|
${Uy(a)}`,issue:null}));else{const T=a.events.find(w=>w.implements.id===i.implements);T&&p.push(new Q({id:`${i.id}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that points to an action descriptor that is already implemented by another global event with id '${T.id}' in the project. Each global event must implement a unique action descriptor.
|
|
92
|
-
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:p,modifiedData:l}}get returnStatements(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===Db.Parent&&a.entity.type===f.ReturnStatement&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new bt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.calls=[...this.calls],i.implements=this.implements,i.detachedChildren=[...this.detachedChildren],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new bt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.calls=y.calls,this.implements=y.implements,this.detachedChildren=y.detachedChildren,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=W(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${Hr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const t=W(this.initialData.implements),y=this.project.get(t);if(y)this.setImplements(y,null),i.push(y);else throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${t}" which is missing in the project`)}else throw new Error(`${Hr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}replaceDetachedChild(i,a){const l=this.detachedChildren.indexOf(i);return l!==-1&&(this.detachedChildren[l]=a),this}subscribeDetachedChild(i){return this.detachedChildren.includes(i)||this.detachedChildren.push(i),this}unsubscribeDetachedChild(i){const a=this.detachedChildren.indexOf(i);return a!==-1&&this.detachedChildren.splice(a,1),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}addCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-call"))){return this.calls.includes(i)||(this.calls.push(i),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("add-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call"))){const l=this.calls.indexOf(i);return l!==-1&&(this.calls.splice(l,1),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(i),a==null||a.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input-declaration"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.calls=this.initialData.calls.map(a=>{const l=ee(a,this.project);if(l.addEntryCaller(this,null),l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this,null),l.initChildren(i));return l}),this.implements=ee(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,this.collapsed=i.collapsed!==void 0?i.collapsed:p.collapsed,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await bt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await bt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await bt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await bt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await bt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await bt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project&&(this.project.removeGlobalEvent(this),i==null||i.add(this.parent,K.Affected),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),Xi(this).forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRestored(this,v.field,i);l.push(...T),p.push(...w),a.push(...A)}),this.inputs.forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),Xi(this).forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.calls.flatMap(l=>l.toFlat(i)),...this.returnStatements.flatMap(l=>l.toFlat(i)),...this.implements?this.implements.toFlat(i):[]])}toFlatIds(i=new Set){if(i.has(this.id))return[];i.add(this.id);const a=Xi(this);return[this.id,...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.calls.flatMap(p=>p.toFlatIds(i)),...this.returnStatements.flatMap(p=>p.toFlatIds(i)),...this.implements?this.implements.toFlatIds(i):[],...a.flatMap(p=>p.toFlatIds(i))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(i),inputs:this.inputs.map(a=>a.toJSON(i)),calls:this.calls.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(T=>T.toJSONClone({...i,newId:null})),calls:this.calls.map(T=>T.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(i),inputs:this.inputs.map(p=>p.toReference(i)),calls:this.calls.map(p=>p.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.calls.flatMap(l=>l.toFlatJSON(i)),...this.returnStatements.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.calls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.returnStatements.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.calls.forEach(i=>i.clearErrors()),this.returnStatements.forEach(i=>i.clearErrors()),this}validate(){const i=IM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){const i=Xi(this);return[...this.errors,...this.inputs.flatMap(l=>l.getErrors()),...i.flatMap(l=>l.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0,t=!1){var k;let y=Ir(a,this);const v=this.toJSON(),T=l||P.UUID.uuid();v.inputs=[];const w=T.split("-id"),A=w[w.length-1||0]||T;v.id=T,v.version=P.UUID.uuid(),v.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),v.author=(i==null?void 0:i.author)||"1",v.previousVersion=null,v.deleted=!1;const V=Kt(v,y);a?V.setParent(a,null):V.setParent(this.parent,null),p&&V.subscribe(),V.initChildren(i),i==null||i.add(V,K.Added);const N=(k=this.inputs)==null?void 0:k.map((q,Y)=>q.clone(i,V,A+"-argument-declaration-"+Y+"-id",p));return V.inputs=N,t?(Xi(this).map((q,Y)=>q.clone(i,V,A+"-body-entity-"+Y+"-id")),i==null||i.attemptAutoclose("clone-entity",this.id),V):(i==null||i.attemptAutoclose("clone-entity",this.id),V)}getVariableInstances(){return Ht(this).filter(l=>l.type===f.VariableInstance)}addReturnStatement(i){return this.returnStatements.includes(i)||this.returnStatements.push(i),this}removeReturnStatement(i){const a=this.returnStatements.indexOf(i);return a!==-1&&this.returnStatements.splice(a,1),this}};D(bt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(bt,"type",f.GlobalEvent),D(bt,"USER_MANAGED_PARENT_TYPES",[f.Project]),D(bt,"PARENT_TYPES",[...bt.USER_MANAGED_PARENT_TYPES]),D(bt,"MUTABLE_BASE_PROPERTIES",["description"]),D(bt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(bt,"BASE_PROPERTIES",[...bt.MUTABLE_BASE_PROPERTIES,...bt.INMUTABLE_BASE_PROPERTIES]),D(bt,"MUTABLE_META_PROPERTIES",[...bt.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),D(bt,"INMUTABLE_META_PROPERTIES",[...bt.INMUTABLE_BASE_PROPERTIES]),D(bt,"META_PROPERTIES",[...bt.MUTABLE_META_PROPERTIES,...bt.INMUTABLE_META_PROPERTIES]),D(bt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(bt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),D(bt,"UPSTREAM_PROPERTIES",[...bt.MUTABLE_UPSTREAM_PROPERTIES,...bt.INMUTABLE_UPSTREAM_PROPERTIES]),D(bt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),D(bt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(bt,"DOWNSTREAM_PROPERTIES",[...bt.MUTABLE_DOWNSTREAM_PROPERTIES,...bt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(bt,"PROPERTIES",[...bt.META_PROPERTIES,...bt.UPSTREAM_PROPERTIES,...bt.DOWNSTREAM_PROPERTIES]);let Fa=bt;function Ob(d){var t,y;const u=Ede(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),(t=d.error)==null||t.validate(),(y=d.body)==null||y.validate();const p=[...fa(d)];return zt(d.errors,p)}function Sfe(d){return Ob(d)}const Zfe=Object.freeze(Object.defineProperty({__proto__:null,validate:Ob,validateListLoop:Sfe},Symbol.toStringTag,{value:"Module"}));function wM(d){const u=b4(),i=d.toJSON();u.safeParse(i).success,d.inputs.flatMap(p=>p.validate()),d.outputs.flatMap(p=>p.validate());const l=[];return zt(d.errors,l)}const Jfe=Object.freeze(Object.defineProperty({__proto__:null,validate:wM},Symbol.toStringTag,{value:"Module"}));var Ze=(d=>(d.Success="success",d.Error="error",d.Break="break",d.Continue="continue",d.Return="return",d))(Ze||{});const At=class At extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"type",f.ActionDescriptor);D(this,"inputs",[]);D(this,"outputs",[]);D(this,"error",null);D(this,"implementation",null);D(this,"parent",null);D(this,"errors",[]);D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"autoexecutable",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ActionDescriptor,name:"",codeName:null,description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(i,a){let l=null;if(i.parent){const y=W(i.parent);l=a.get(y)}const p={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ActionDescriptor,codeName:i.codeName,description:i.description,inputs:[],outputs:[],error:null,parent:l},t=ee(p,a);return l&&t.setParent(l,null),t}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.DefinitionEntity,f.DataType]}},a);l=t.modifiedData;const y=l.parent?a.get(l.parent):null;if(y&&y.type===f.DefinitionEntity){const v=y,w=wi(v).filter(A=>!A.interactive);if(w.length){let A=w.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${qe(w.map(V=>re(V,V.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${re(w[0],w[0].project)}").`;A+=`
|
|
92
|
+
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:p,modifiedData:l}}get returnStatements(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===Db.Parent&&a.entity.type===f.ReturnStatement&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new bt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.calls=[...this.calls],i.implements=this.implements,i.detachedChildren=[...this.detachedChildren],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new bt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.calls=y.calls,this.implements=y.implements,this.detachedChildren=y.detachedChildren,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=W(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${Hr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const t=W(this.initialData.implements),y=this.project.get(t);if(y)this.setImplements(y,null),i.push(y);else throw new Error(`${Hr(this.type)} with id '${this.id}' has a 'implements' reference "${t}" which is missing in the project`)}else throw new Error(`${Hr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}replaceDetachedChild(i,a){const l=this.detachedChildren.indexOf(i);return l!==-1&&(this.detachedChildren[l]=a),this}subscribeDetachedChild(i){return this.detachedChildren.includes(i)||this.detachedChildren.push(i),this}unsubscribeDetachedChild(i){const a=this.detachedChildren.indexOf(i);return a!==-1&&this.detachedChildren.splice(a,1),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}addCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-call"))){return this.calls.includes(i)||(this.calls.push(i),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("add-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call"))){const l=this.calls.indexOf(i);return l!==-1&&(this.calls.splice(l,1),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(i),a==null||a.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input-declaration"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.calls=this.initialData.calls.map(a=>{const l=ee(a,this.project);if(l.addEntryCaller(this,null),l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this,null),l.initChildren(i));return l}),this.implements=ee(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,this.collapsed=i.collapsed!==void 0?i.collapsed:p.collapsed,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await bt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await bt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await bt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await bt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await bt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await bt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project&&(this.project.removeGlobalEvent(this),i==null||i.add(this.parent,K.Affected),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),Xi(this).forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRestored(this,v.field,i);l.push(...T),p.push(...w),a.push(...A)}),this.inputs.forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),Xi(this).forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.calls.flatMap(l=>l.toFlat(i)),...this.returnStatements.flatMap(l=>l.toFlat(i)),...this.implements?this.implements.toFlat(i):[]])}toFlatIds(i=new Set){if(i.has(this.id))return[];i.add(this.id);const a=Xi(this);return[this.id,...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.calls.flatMap(p=>p.toFlatIds(i)),...this.returnStatements.flatMap(p=>p.toFlatIds(i)),...this.implements?this.implements.toFlatIds(i):[],...a.flatMap(p=>p.toFlatIds(i))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(i),inputs:this.inputs.map(a=>a.toJSON(i)),calls:this.calls.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(T=>T.toJSONClone({...i,newId:null})),calls:this.calls.map(T=>T.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(i),inputs:this.inputs.map(p=>p.toReference(i)),calls:this.calls.map(p=>p.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.calls.flatMap(l=>l.toFlatJSON(i)),...this.returnStatements.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.calls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.returnStatements.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.calls.forEach(i=>i.clearErrors()),this.returnStatements.forEach(i=>i.clearErrors()),this}validate(){const i=IM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){const i=Xi(this);return[...this.errors,...this.inputs.flatMap(l=>l.getErrors()),...i.flatMap(l=>l.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0,t=!1){var k;let y=Ir(a,this);const v=this.toJSON(),T=l||P.UUID.uuid();v.inputs=[];const w=T.split("-id"),A=w[w.length-1||0]||T;v.id=T,v.version=P.UUID.uuid(),v.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),v.author=(i==null?void 0:i.author)||"1",v.previousVersion=null,v.deleted=!1;const V=Kt(v,y);a?V.setParent(a,null):V.setParent(this.parent,null),p&&V.subscribe(),V.initChildren(i),i==null||i.add(V,K.Added);const N=(k=this.inputs)==null?void 0:k.map((q,Y)=>q.clone(i,V,A+"-argument-declaration-"+Y+"-id",p));return V.inputs=N,t?(Xi(this).map((q,Y)=>q.clone(i,V,A+"-body-entity-"+Y+"-id")),i==null||i.attemptAutoclose("clone-entity",this.id),V):(i==null||i.attemptAutoclose("clone-entity",this.id),V)}getVariableInstances(){return Ht(this).filter(l=>l.type===f.VariableInstance)}addReturnStatement(i){return this.returnStatements.includes(i)||this.returnStatements.push(i),this}removeReturnStatement(i){const a=this.returnStatements.indexOf(i);return a!==-1&&this.returnStatements.splice(a,1),this}};D(bt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(bt,"type",f.GlobalEvent),D(bt,"USER_MANAGED_PARENT_TYPES",[f.Project]),D(bt,"PARENT_TYPES",[...bt.USER_MANAGED_PARENT_TYPES]),D(bt,"MUTABLE_BASE_PROPERTIES",["description"]),D(bt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(bt,"BASE_PROPERTIES",[...bt.MUTABLE_BASE_PROPERTIES,...bt.INMUTABLE_BASE_PROPERTIES]),D(bt,"MUTABLE_META_PROPERTIES",[...bt.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),D(bt,"INMUTABLE_META_PROPERTIES",[...bt.INMUTABLE_BASE_PROPERTIES]),D(bt,"META_PROPERTIES",[...bt.MUTABLE_META_PROPERTIES,...bt.INMUTABLE_META_PROPERTIES]),D(bt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(bt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),D(bt,"UPSTREAM_PROPERTIES",[...bt.MUTABLE_UPSTREAM_PROPERTIES,...bt.INMUTABLE_UPSTREAM_PROPERTIES]),D(bt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),D(bt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(bt,"DOWNSTREAM_PROPERTIES",[...bt.MUTABLE_DOWNSTREAM_PROPERTIES,...bt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(bt,"PROPERTIES",[...bt.META_PROPERTIES,...bt.UPSTREAM_PROPERTIES,...bt.DOWNSTREAM_PROPERTIES]);let Fa=bt;function Ob(d){var t,y;const u=Ede(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),(t=d.error)==null||t.validate(),(y=d.body)==null||y.validate();const p=[...fa(d)];return zt(d.errors,p)}function Sfe(d){return Ob(d)}const Zfe=Object.freeze(Object.defineProperty({__proto__:null,validate:Ob,validateListLoop:Sfe},Symbol.toStringTag,{value:"Module"}));function wM(d){const u=b4(),i=d.toJSON();u.safeParse(i).success,d.inputs.flatMap(p=>p.validate()),d.outputs.flatMap(p=>p.validate());const l=[];return zt(d.errors,l)}const Jfe=Object.freeze(Object.defineProperty({__proto__:null,validate:wM},Symbol.toStringTag,{value:"Module"}));var Ze=(d=>(d.Success="success",d.Error="error",d.Break="break",d.Continue="continue",d.Return="return",d))(Ze||{});const At=class At extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"type",f.ActionDescriptor);D(this,"inputs",[]);D(this,"outputs",[]);D(this,"error",null);D(this,"implementation",null);D(this,"parent",null);D(this,"errors",[]);D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"autoexecutable",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.codeName=i.codeName,this.description=i.description}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ActionDescriptor,name:"",codeName:null,description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(i,a){let l=null;if(i.parent){const y=W(i.parent);l=a.get(y)}const p={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ActionDescriptor,codeName:i.codeName,description:i.description,inputs:[],outputs:[],error:null,parent:l},t=ee(p,a);return l&&t.setParent(l,null),t}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.DefinitionEntity,f.DataType]}},a);l=t.modifiedData;const y=l.parent?a.get(l.parent):null;if(y&&y.type===f.DefinitionEntity){const v=y,w=wi(v).filter(A=>!A.interactive);if(w.length){let A=w.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${qe(w.map(V=>re(V,V.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${re(w[0],w[0].project)}").`;A+=`
|
|
93
93
|
${Ha}`,p.push(new Q({id:`${i.id}--${S.NonInteractiveEntityReferenced}`,code:S.NonInteractiveEntityReferenced,severity:Z.Error,message:A,issue:null}))}}else if(y&&y.type===f.DataType){const v=y;v.entity&&p.push(new Q({id:`${i.id}--${S.NewEntityWouldOverriteExisting}`,code:S.NewEntityWouldOverriteExisting,severity:Z.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
94
94
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
95
95
|
${On({describe_entity:v.entity.id})}
|
|
@@ -106,7 +106,7 @@ ${xy(a)}`,issue:null})),{errors:p,modifiedData:l}}validateGeneratedUpdate(i){con
|
|
|
106
106
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.`,issue:null})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Nt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.declaration=this.declaration,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Nt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.declaration=y.declaration,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i);return a.push(...y),l.push(...v),p.push(...T),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Nt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Nt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Nt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Nt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Nt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Nt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.inputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(T=>{l.push(T),T.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(i),successCalls:this.successCalls.map(a=>a.toJSON(i)),errorCalls:this.errorCalls.map(a=>a.toJSON(i)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),inputs:this.inputs.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().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(T=>T.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(T=>T.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(T=>T.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(T=>T.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(T=>T.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(T=>T.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i),inputs:this.inputs.map(p=>p.toReference(i)),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this}validate(){const i=_M(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var N;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(N=this.inputs)==null?void 0:N.map((j,k)=>j.clone(i,A,w+"-input-map-"+k+"-id",p));return A.inputs=V,i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===ue.FixedArguments&&!this.inputs.find(V=>V.declaration.id===A.id));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Nt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Nt,"type",f.Condition),D(Nt,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(Nt,"PARENT_TYPES",[...Nt.USER_MANAGED_PARENT_TYPES]),D(Nt,"MUTABLE_BASE_PROPERTIES",["operator"]),D(Nt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Nt,"BASE_PROPERTIES",[...Nt.MUTABLE_BASE_PROPERTIES,...Nt.INMUTABLE_BASE_PROPERTIES]),D(Nt,"MUTABLE_META_PROPERTIES",["x","y"]),D(Nt,"INMUTABLE_META_PROPERTIES",[...Nt.INMUTABLE_BASE_PROPERTIES]),D(Nt,"META_PROPERTIES",[...Nt.MUTABLE_META_PROPERTIES,...Nt.INMUTABLE_META_PROPERTIES]),D(Nt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),D(Nt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),D(Nt,"UPSTREAM_PROPERTIES",[...Nt.MUTABLE_UPSTREAM_PROPERTIES,...Nt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Nt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),D(Nt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Nt,"DOWNSTREAM_PROPERTIES",[...Nt.MUTABLE_DOWNSTREAM_PROPERTIES,...Nt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Nt,"PROPERTIES",[...Nt.META_PROPERTIES,...Nt.UPSTREAM_PROPERTIES,...Nt.DOWNSTREAM_PROPERTIES]);let Ga=Nt;function DM(d){var y;const u=Vue(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...fa(d)];if(d.id==="random-company-employee-test-variable-id"){const v=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});p.push(v.error)}if(d.id==="company-dto-variable-one-id"){const v=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});p.push(v.error)}const t=iA(d);return p.push(...t),zt(d.errors,p)}const Yfe=Object.freeze(Object.defineProperty({__proto__:null,validate:DM},Symbol.toStringTag,{value:"Module"}));function OM(d){const u=Uue(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...fa(d)];if(d.id==="exec-sequentially-result-variable-id"){const y=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});p.push(y.error)}const t=iA(d);return p.push(...t),zt(d.errors,p)}const Hfe=Object.freeze(Object.defineProperty({__proto__:null,validate:OM},Symbol.toStringTag,{value:"Module"}));var Cb=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(Cb||{});const It=class It extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"x");D(this,"y");D(this,"type",f.VariableInstance);D(this,"defaultValue",null);D(this,"writesValues",[]);D(this,"readsValue",null);D(this,"declaration");D(this,"inputs",[]);D(this,"outputs",[]);D(this,"calledBySuccess",[]);D(this,"calledByError",[]);D(this,"calledByEntry",[]);D(this,"successCalls",[]);D(this,"errorCalls",[]);D(this,"internalCalls",[]);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const N=W(i.parent);l=a.get(N)}const p=W(i.declaration),t=a.get(p),y=i.calledByEntry.map(N=>{const j=W(N);return a.get(j)}),v=i.calledBySuccess.map(N=>{const j=W(N);return a.get(j)}),T=i.calledByError.map(N=>{const j=W(N);return a.get(j)});let w=null;if(i.readsValue){const N=W(i.readsValue);w=a.get(N)}const A={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:t.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:T,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:w,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:l},V=ee(A,a);return V.setParent(l,null),V}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[...br,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return l=t.modifiedData,p.push(...t.errors,...vr(l)),{errors:p,modifiedData:l}}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const p=bp(l,this);return l=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
107
107
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
108
108
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
109
|
-
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:a,modifiedData:l}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t,y,v;return(a=(i=this.parent)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"parent"}]),(t=(p=(l=this.declaration.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),(v=(y=this.declaration)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var i,a,l,p;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(l=(a=this.declaration.dataType)==null?void 0:a.entity)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new It(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new It(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=W(i.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.readsValue),y=this.project.get(t);y&&(this.setValueWriter(y,null),i.push(y))}if(this.initialData.declaration){const t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){var Ie;const a=[],l=[],p=[],t=[];if(this.initialized=!0,!this.declaration.dataType||(Ie=this.declaration.dataType)!=null&&Ie.inferred){const{added:_e,updated:Me,removed:Ce,affected:ze}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(i);l.push(..._e),a.push(...Me),p.push(...Ce),t.push(...ze)}const{added:y,updated:v,removed:T,affected:w}=this.syncInputs(i);l.push(...y),a.push(...v),p.push(...T),t.push(...w);const{added:A,updated:V,removed:N,affected:j}=this.syncOutputs(i);l.push(...A),a.push(...V),p.push(...N),t.push(...j);const{added:k,updated:q,removed:Y,affected:ie}=this.generateUnusedInternalCalls(i);l.push(...k),a.push(...q),p.push(...Y),t.push(...ie);const{added:te,updated:pe,removed:ne,affected:me}=this.removeUnrecognizedInputs(i);l.push(...te),a.push(...pe),p.push(...ne),t.push(...me);const{added:J,updated:ae,removed:ce,affected:H}=this.removeUnrecognizedOutputs(i);l.push(...J),a.push(...ae),p.push(...ce),t.push(...H);const{added:de,updated:ve,removed:Pe,affected:Oe}=this.removeUnrecognizedInternalCalls(i);return l.push(...de),a.push(...ve),p.push(...Pe),t.push(...Oe),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){const i=this.usedInternalCalls;return this.internalCalls.filter(l=>!(i.find(y=>y.id===l.id)||i.find(y=>y.declaration===l.declaration)))}removeInternalCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-variable-instance-internal-call"))){const l=this.internalCalls.findIndex(p=>p.id===i.id);return l>-1&&(this.internalCalls.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-variable-instance-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration.type===f.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!a)return this;this.declaration=a}else this.declaration=ee(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(i);return Cp.initWritesValues(this,this.parent),Op.initReadsValue(this),this.initialData.inputs.forEach(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addInput(l,null),l}),this.initialData.outputs.forEach(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addOutput(l,i),l}),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.internalCalls=this.initialData.internalCalls.reduce((a,l)=>{if(l.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(l);if(!p)return a;const t=p;return t.setParent(this,null),[...a,t]}else{const p=ee(l,this.project);return p.setParent(this,null),p.initChildren(i),[...a,p]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.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(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await It.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await It.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await It.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await It.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await It.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await It.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeVariableInstance(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{l.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.outputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(T=>{l.push(T),T.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}return this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...this.writesValues.flatMap(t=>t.toFlat(i)),...((p=this.readsValue)==null?void 0:p.toFlat(i))||[],...this.successCalls.flatMap(t=>t.toFlat(i)),...this.errorCalls.flatMap(t=>t.toFlat(i)),...this.inputs.flatMap(t=>t.toFlat(i)),...this.outputs.flatMap(t=>t.toFlat(i)),...this.internalCalls.flatMap(t=>t.toFlat(i))])}toFlatIds(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...this.writesValues.flatMap(p=>p.toFlatIds(i)),...this.successCalls.flatMap(p=>p.toFlatIds(i)),...this.errorCalls.flatMap(p=>p.toFlatIds(i)),...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.outputs.flatMap(p=>p.toFlatIds(i)),...this.internalCalls.flatMap(p=>p.toFlatIds(i))])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(i),defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference())||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),internalCalls:this.internalCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:i.seenEntityMaps}),readsValue:((w=this.readsValue)==null?void 0:w.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map(A=>this.calledBy.length||this.readsValue?A.toJSONClone({...i,newId:null}):A.toReference({seenEntityMaps:i.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:((t=this.declaration)==null?void 0:t.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),internalCalls:this.internalCalls.map(v=>v.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.declaration)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(t=>t.toFlatJSON(i)),...this.successCalls.flatMap(t=>t.toFlatJSON(i)),...this.errorCalls.flatMap(t=>t.toFlatJSON(i)),...this.inputs.flatMap(t=>t.toFlatJSON(i)),...this.outputs.flatMap(t=>t.toFlatJSON(i)),...this.internalCalls.flatMap(t=>t.toFlatJSON(i)),...this.calledBy.flatMap(t=>t.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var l,p,t;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.declaration)==null?void 0:p.toFlatGenerationTarget(i))||[],...((t=this.readsValue)==null?void 0:t.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(y=>y.toFlatGenerationTarget(i)),...this.successCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.inputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(y=>y.toFlatGenerationTarget(i))])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),this.internalCalls.forEach(a=>a.clearErrors()),this}validate(){const i=OM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...this.inputs.flatMap(p=>p.getErrors()),...this.internalCalls.flatMap(p=>p.getErrors()),...this.outputs.flatMap(p=>p.getErrors()),...((l=this.readsValue)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k,q,Y;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[],y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const T=Kt(y,t);a?T.setParent(a,null):T.setParent(this.parent,null),p&&T.subscribe(),T.initChildren(i),i==null||i.add(T,K.Added);const w=(j=this.defaultValue)==null?void 0:j.clone(i,T,P.UUID.uuid(),p);T.defaultValue=w||null;const A=(k=this.inputs)==null?void 0:k.map(ie=>ie.clone(i,T,P.UUID.uuid(),p));T.inputs=A;const V=(q=this.outputs)==null?void 0:q.map(ie=>ie.clone(i,T,P.UUID.uuid(),p));T.outputs=V;const N=(Y=this.internalCalls)==null?void 0:Y.map(ie=>ie.clone(i,T,P.UUID.uuid(),p));return T.internalCalls=N,i==null||i.attemptAutoclose("clone-entity",this.id),T}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}setDeclaration(i){return this.declaration!==i&&(this.declaration=i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-inputs"))){const a=[],l=[],p=[],t=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.inputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.inputs].forEach(y=>{var T;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((T=this.declaration.dataType)==null?void 0:T.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-outputs"))){const a=[],l=[],p=[],t=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.outputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.outputs].forEach(y=>{var T;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((T=this.declaration.dataType)==null?void 0:T.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],l=[],p=[],t=[];if(!this.declaration.dataType||!this.declaration.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type))[...this.internalCalls].forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.declaration.dataType&&this.declaration.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const T=[...((v=this.declaration.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(w=>{if(!w.declaration){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}if(!T.find(V=>w.declaration===V)){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}})}return this.internalCalls.filter((T,w)=>{const A=this.internalCalls.findIndex(N=>N.declaration===T.declaration&&N!==T);if(A===-1)return!1;const V=this.internalCalls[A];return L(V==null?void 0:V.createdAt).isSame(L(T.createdAt))?w>A:!!L(V==null?void 0:V.createdAt).isAfter(T.createdAt)}).forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-inputs"))){const a=[],l=[],p=[],t=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList){const y=[...this.declaration.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const V=this.inputs.find(k=>re(k,this.project)===re(A,this.project));if(!V)return;const N=this.declaration.getMasterInputWithValueWritterFromAllInstances(V);if(!N)return;const j=zs(N);A.setDataType(j,i),V.setDeclaration(A)}),y.filter(A=>!this.inputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id})).forEach(A=>{const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},N=ee(V,this.project);return N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),this.addInput(N,i),N}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const V=y.find(N=>re(N,this.project)===re(A,this.project));V&&A.setDeclaration(V)})}}else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-outputs"))){const a=[],l=[],p=[],t=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.properties].filter(T=>!this.outputs.find(w=>w.declaration===T)).map(T=>{const w={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,parent:this.toReference(),defaultValue:null,declaration:T,index:T.index,writesValues:[]},A=ee(w,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,K.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],l=[],p=[],t=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(T=>!this.internalCalls.find(A=>{var N,j,k,q,Y;return(((N=A.declaration)==null?void 0:N.id)||((k=(j=A.initialData)==null?void 0:j.declaration)==null?void 0:k.entityId)||((Y=(q=A.initialData)==null?void 0:q.declaration)==null?void 0:Y.id))===T.id})).map(T=>{const w=T.createInternalCall(i,this);return i==null||i.add(w,K.Added),this.addInternalCall(w),w});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var a;return((a=this.declaration)==null?void 0:a.getDataType(i))||null}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};D(It,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(It,"type",f.VariableInstance),D(It,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(It,"PARENT_TYPES",[...It.USER_MANAGED_PARENT_TYPES]),D(It,"MUTABLE_BASE_PROPERTIES",[]),D(It,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(It,"BASE_PROPERTIES",[...It.MUTABLE_BASE_PROPERTIES,...It.INMUTABLE_BASE_PROPERTIES]),D(It,"MUTABLE_META_PROPERTIES",[...It.MUTABLE_BASE_PROPERTIES,"x","y"]),D(It,"INMUTABLE_META_PROPERTIES",[...It.INMUTABLE_BASE_PROPERTIES]),D(It,"META_PROPERTIES",[...It.MUTABLE_META_PROPERTIES,...It.INMUTABLE_META_PROPERTIES]),D(It,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),D(It,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),D(It,"UPSTREAM_PROPERTIES",[...It.MUTABLE_UPSTREAM_PROPERTIES,...It.INMUTABLE_UPSTREAM_PROPERTIES]),D(It,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),D(It,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(It,"DOWNSTREAM_PROPERTIES",[...It.MUTABLE_DOWNSTREAM_PROPERTIES,...It.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(It,"PROPERTIES",[...It.META_PROPERTIES,...It.UPSTREAM_PROPERTIES,...It.DOWNSTREAM_PROPERTIES]);let Ka=It;var CM=(d=>(d.Parent="parent",d.DataTypeEntity="variable-data-type-entity",d.DataType="variable-data-type",d))(CM||{});const wt=class wt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"required",!1);D(this,"constant",!1);D(this,"x");D(this,"y");D(this,"type",f.VariableDeclaration);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"writesValues",[]);D(this,"readsValue",null);D(this,"inputs",[]);D(this,"outputs",[]);D(this,"calledBySuccess",[]);D(this,"calledByError",[]);D(this,"calledByEntry",[]);D(this,"successCalls",[]);D(this,"errorCalls",[]);D(this,"internalCalls",[]);D(this,"parent");D(this,"errors",[]);D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.constant=i.constant,this.required=i.required,this.x=i.x,this.y=i.y}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:"",codeName:null,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(i,a){let l=a;if(i.parent){const A=W(i.parent);l=a.get(A)}const p=i.calledByEntry.map(A=>{const V=W(A);return a.get(V)}),t=i.calledBySuccess.map(A=>{const V=W(A);return a.get(V)}),y=i.calledByError.map(A=>{const V=W(A);return a.get(V)});let v=null;if(i.readsValue){const A=W(i.readsValue);v=a.get(A)}const T={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:i.name,defaultValue:null,codeName:i.codeName||null,description:i.description||null,constant:i.constant||!1,required:i.required||!1,calledByEntry:p,calledBySuccess:t,calledByError:y,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:v,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:l},w=ee(T,a);return w.setParent(l,null),w}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[...br,f.Project],optional:!0}},a);l=t.modifiedData;const y=mb(l,a);return p.push(...t.errors,...y,...vr(l)),{errors:p,modifiedData:l}}get variableInstances(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===Cb.VarDeclaration&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const p=bp(l,this);return l=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
109
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:a,modifiedData:l}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t,y,v;return(a=(i=this.parent)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"parent"}]),(t=(p=(l=this.declaration.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),(v=(y=this.declaration)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var i,a,l,p;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(l=(a=this.declaration.dataType)==null?void 0:a.entity)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new It(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new It(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=W(i.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.readsValue),y=this.project.get(t);y&&(this.setValueWriter(y,null),i.push(y))}if(this.initialData.declaration){const t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){var Ie;const a=[],l=[],p=[],t=[];if(this.initialized=!0,!this.declaration.dataType||(Ie=this.declaration.dataType)!=null&&Ie.inferred){const{added:_e,updated:Me,removed:Ce,affected:ze}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(i);l.push(..._e),a.push(...Me),p.push(...Ce),t.push(...ze)}const{added:y,updated:v,removed:T,affected:w}=this.syncInputs(i);l.push(...y),a.push(...v),p.push(...T),t.push(...w);const{added:A,updated:V,removed:N,affected:j}=this.syncOutputs(i);l.push(...A),a.push(...V),p.push(...N),t.push(...j);const{added:k,updated:q,removed:Y,affected:ie}=this.generateUnusedInternalCalls(i);l.push(...k),a.push(...q),p.push(...Y),t.push(...ie);const{added:te,updated:pe,removed:ne,affected:me}=this.removeUnrecognizedInputs(i);l.push(...te),a.push(...pe),p.push(...ne),t.push(...me);const{added:J,updated:ae,removed:ce,affected:H}=this.removeUnrecognizedOutputs(i);l.push(...J),a.push(...ae),p.push(...ce),t.push(...H);const{added:de,updated:ve,removed:Pe,affected:Oe}=this.removeUnrecognizedInternalCalls(i);return l.push(...de),a.push(...ve),p.push(...Pe),t.push(...Oe),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){const i=this.usedInternalCalls;return this.internalCalls.filter(l=>!(i.find(y=>y.id===l.id)||i.find(y=>y.declaration===l.declaration)))}removeInternalCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-variable-instance-internal-call"))){const l=this.internalCalls.findIndex(p=>p.id===i.id);return l>-1&&(this.internalCalls.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-variable-instance-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration.type===f.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!a)return this;this.declaration=a}else this.declaration=ee(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(i);return Cp.initWritesValues(this,this.parent),Op.initReadsValue(this),this.initialData.inputs.forEach(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addInput(l,null),l}),this.initialData.outputs.forEach(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addOutput(l,i),l}),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.internalCalls=this.initialData.internalCalls.reduce((a,l)=>{if(l.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(l);if(!p)return a;const t=p;return t.setParent(this,null),[...a,t]}else{const p=ee(l,this.project);return p.setParent(this,null),p.initChildren(i),[...a,p]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.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(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await It.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await It.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await It.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await It.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await It.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await It.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeVariableInstance(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{l.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.outputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(T=>{l.push(T),T.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}return this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...this.writesValues.flatMap(t=>t.toFlat(i)),...((p=this.readsValue)==null?void 0:p.toFlat(i))||[],...this.successCalls.flatMap(t=>t.toFlat(i)),...this.errorCalls.flatMap(t=>t.toFlat(i)),...this.inputs.flatMap(t=>t.toFlat(i)),...this.outputs.flatMap(t=>t.toFlat(i)),...this.internalCalls.flatMap(t=>t.toFlat(i))])}toFlatIds(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...this.writesValues.flatMap(p=>p.toFlatIds(i)),...this.successCalls.flatMap(p=>p.toFlatIds(i)),...this.errorCalls.flatMap(p=>p.toFlatIds(i)),...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.outputs.flatMap(p=>p.toFlatIds(i)),...this.internalCalls.flatMap(p=>p.toFlatIds(i))])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(i),defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference())||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),internalCalls:this.internalCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:i.seenEntityMaps}),readsValue:((w=this.readsValue)==null?void 0:w.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map(A=>this.calledBy.length||this.readsValue?A.toJSONClone({...i,newId:null}):A.toReference({seenEntityMaps:i.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:((t=this.declaration)==null?void 0:t.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),internalCalls:this.internalCalls.map(v=>v.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.declaration)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(t=>t.toFlatJSON(i)),...this.successCalls.flatMap(t=>t.toFlatJSON(i)),...this.errorCalls.flatMap(t=>t.toFlatJSON(i)),...this.inputs.flatMap(t=>t.toFlatJSON(i)),...this.outputs.flatMap(t=>t.toFlatJSON(i)),...this.internalCalls.flatMap(t=>t.toFlatJSON(i)),...this.calledBy.flatMap(t=>t.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var l,p,t;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.declaration)==null?void 0:p.toFlatGenerationTarget(i))||[],...((t=this.readsValue)==null?void 0:t.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(y=>y.toFlatGenerationTarget(i)),...this.successCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.inputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(y=>y.toFlatGenerationTarget(i))])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),this.internalCalls.forEach(a=>a.clearErrors()),this}validate(){const i=OM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...this.inputs.flatMap(p=>p.getErrors()),...this.internalCalls.flatMap(p=>p.getErrors()),...this.outputs.flatMap(p=>p.getErrors()),...((l=this.readsValue)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k,q,Y;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[],y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const T=Kt(y,t);a?T.setParent(a,null):T.setParent(this.parent,null),p&&T.subscribe(),T.initChildren(i),i==null||i.add(T,K.Added);const w=(j=this.defaultValue)==null?void 0:j.clone(i,T,P.UUID.uuid(),p);T.defaultValue=w||null;const A=(k=this.inputs)==null?void 0:k.map(ie=>ie.clone(i,T,P.UUID.uuid(),p));T.inputs=A;const V=(q=this.outputs)==null?void 0:q.map(ie=>ie.clone(i,T,P.UUID.uuid(),p));T.outputs=V;const N=(Y=this.internalCalls)==null?void 0:Y.map(ie=>ie.clone(i,T,P.UUID.uuid(),p));return T.internalCalls=N,i==null||i.attemptAutoclose("clone-entity",this.id),T}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}setDeclaration(i){return this.declaration!==i&&(this.declaration=i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-inputs"))){const a=[],l=[],p=[],t=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.inputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.inputs].forEach(y=>{var T;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((T=this.declaration.dataType)==null?void 0:T.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-outputs"))){const a=[],l=[],p=[],t=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.outputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.outputs].forEach(y=>{var T;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((T=this.declaration.dataType)==null?void 0:T.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],l=[],p=[],t=[];if(!this.declaration.dataType||!this.declaration.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type))[...this.internalCalls].forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.declaration.dataType&&this.declaration.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const T=[...((v=this.declaration.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(w=>{if(!w.declaration){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}if(!T.find(V=>w.declaration===V)){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}})}return this.internalCalls.filter((T,w)=>{const A=this.internalCalls.findIndex(N=>N.declaration===T.declaration&&N!==T);if(A===-1)return!1;const V=this.internalCalls[A];return L(V==null?void 0:V.createdAt).isSame(L(T.createdAt))?w>A:!!L(V==null?void 0:V.createdAt).isAfter(T.createdAt)}).forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-inputs"))){const a=[],l=[],p=[],t=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList){const y=[...this.declaration.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const V=this.inputs.find(k=>re(k,this.project)===re(A,this.project));if(!V)return;const N=this.declaration.getMasterInputWithValueWritterFromAllInstances(V);if(!N)return;const j=zs(N);A.setDataType(j,i),V.setDeclaration(A)}),y.filter(A=>!this.inputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id})).forEach(A=>{const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},N=ee(V,this.project);return N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),this.addInput(N,i),N}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const V=y.find(N=>re(N,this.project)===re(A,this.project));V&&A.setDeclaration(V)})}}else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-outputs"))){const a=[],l=[],p=[],t=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.properties].filter(T=>!this.outputs.find(w=>w.declaration===T)).map(T=>{const w={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,parent:this.toReference(),defaultValue:null,declaration:T,index:T.index,writesValues:[]},A=ee(w,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,K.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],l=[],p=[],t=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(T=>!this.internalCalls.find(A=>{var N,j,k,q,Y;return(((N=A.declaration)==null?void 0:N.id)||((k=(j=A.initialData)==null?void 0:j.declaration)==null?void 0:k.entityId)||((Y=(q=A.initialData)==null?void 0:q.declaration)==null?void 0:Y.id))===T.id})).map(T=>{const w=T.createInternalCall(i,this);return i==null||i.add(w,K.Added),this.addInternalCall(w),w});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var a;return((a=this.declaration)==null?void 0:a.getDataType(i))||null}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};D(It,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(It,"type",f.VariableInstance),D(It,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(It,"PARENT_TYPES",[...It.USER_MANAGED_PARENT_TYPES]),D(It,"MUTABLE_BASE_PROPERTIES",[]),D(It,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(It,"BASE_PROPERTIES",[...It.MUTABLE_BASE_PROPERTIES,...It.INMUTABLE_BASE_PROPERTIES]),D(It,"MUTABLE_META_PROPERTIES",[...It.MUTABLE_BASE_PROPERTIES,"x","y"]),D(It,"INMUTABLE_META_PROPERTIES",[...It.INMUTABLE_BASE_PROPERTIES]),D(It,"META_PROPERTIES",[...It.MUTABLE_META_PROPERTIES,...It.INMUTABLE_META_PROPERTIES]),D(It,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),D(It,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),D(It,"UPSTREAM_PROPERTIES",[...It.MUTABLE_UPSTREAM_PROPERTIES,...It.INMUTABLE_UPSTREAM_PROPERTIES]),D(It,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),D(It,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(It,"DOWNSTREAM_PROPERTIES",[...It.MUTABLE_DOWNSTREAM_PROPERTIES,...It.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(It,"PROPERTIES",[...It.META_PROPERTIES,...It.UPSTREAM_PROPERTIES,...It.DOWNSTREAM_PROPERTIES]);let Ka=It;var CM=(d=>(d.Parent="parent",d.DataTypeEntity="variable-data-type-entity",d.DataType="variable-data-type",d))(CM||{});const wt=class wt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"required",!1);D(this,"constant",!1);D(this,"x");D(this,"y");D(this,"type",f.VariableDeclaration);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"writesValues",[]);D(this,"readsValue",null);D(this,"inputs",[]);D(this,"outputs",[]);D(this,"calledBySuccess",[]);D(this,"calledByError",[]);D(this,"calledByEntry",[]);D(this,"successCalls",[]);D(this,"errorCalls",[]);D(this,"internalCalls",[]);D(this,"parent");D(this,"errors",[]);D(this,"project");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.constant=i.constant,this.codeName=i.codeName,this.required=i.required,this.x=i.x,this.y=i.y}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:"",codeName:null,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(i,a){let l=a;if(i.parent){const A=W(i.parent);l=a.get(A)}const p=i.calledByEntry.map(A=>{const V=W(A);return a.get(V)}),t=i.calledBySuccess.map(A=>{const V=W(A);return a.get(V)}),y=i.calledByError.map(A=>{const V=W(A);return a.get(V)});let v=null;if(i.readsValue){const A=W(i.readsValue);v=a.get(A)}const T={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:i.name,defaultValue:null,codeName:i.codeName||null,description:i.description||null,constant:i.constant||!1,required:i.required||!1,calledByEntry:p,calledBySuccess:t,calledByError:y,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:v,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:l},w=ee(T,a);return w.setParent(l,null),w}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[...br,f.Project],optional:!0}},a);l=t.modifiedData;const y=mb(l,a);return p.push(...t.errors,...y,...vr(l)),{errors:p,modifiedData:l}}get variableInstances(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===Cb.VarDeclaration&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const p=bp(l,this);return l=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
110
110
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
111
111
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
112
112
|
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:a,modifiedData:l}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t,y;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),(p=(l=(a=this.dataType)==null?void 0:a.entity)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"variable-data-type-entity"}]),(y=(t=this.dataType)==null?void 0:t.unsubscribeDependents)==null||y.call(t,[{entity:this,field:"variable-data-type"}]),this}subscribeToDependencies(){var i,a,l,p,t,y;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(l=(a=this.dataType)==null?void 0:a.entity)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"variable-data-type-entity"}]),(y=(t=this.dataType)==null?void 0:t.subscribeDependents)==null||y.call(t,[{entity:this,field:"variable-data-type"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new wt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new wt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=W(i.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.readsValue),y=this.project.get(t);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];if(this.initialized=!0,!this.dataType||this.dataType.inferred){const{added:Ie,updated:_e,removed:Me,affected:Ce}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(i);l.push(...Ie),a.push(..._e),p.push(...Me),t.push(...Ce)}const{added:y,updated:v,removed:T,affected:w}=this.syncInputs(i);l.push(...y),a.push(...v),p.push(...T),t.push(...w);const{added:A,updated:V,removed:N,affected:j}=this.syncOutputs(i);l.push(...A),a.push(...V),p.push(...N),t.push(...j);const{added:k,updated:q,removed:Y,affected:ie}=this.generateUnusedInternalCalls(i);l.push(...k),a.push(...q),p.push(...Y),t.push(...ie);const{added:te,updated:pe,removed:ne,affected:me}=this.removeUnrecognizedInputs(i);l.push(...te),a.push(...pe),p.push(...ne),t.push(...me);const{added:J,updated:ae,removed:ce,affected:H}=this.removeUnrecognizedOutputs(i);l.push(...J),a.push(...ae),p.push(...ce),t.push(...H);const{added:de,updated:ve,removed:Pe,affected:Oe}=this.removeUnrecognizedInternalCalls(i);return l.push(...de),a.push(...ve),p.push(...Pe),t.push(...Oe),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(i=>!i.calledBy.length)}removeInternalCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-variable-declaration-internal-call"))){const l=this.internalCalls.findIndex(p=>p.id===i.id);return l>-1&&(this.internalCalls.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-variable-declaration-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this)}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=ee(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),Cp.initWritesValues(this,this.parent),Op.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.initialData.inputs.forEach(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addInput(l,null),l}),this.initialData.outputs.forEach(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addOutput(l,null),l}),this.initialData.internalCalls.forEach(a=>{if(a.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(a);if(!p)return;p.setParent(this,null),p.initChildren(i),this.addInternalCall(p);return}const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addInternalCall(l),l}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.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(i){return R([...this.inputs,...this.variableInstances.flatMap(p=>p.inputs)]).find(p=>re(p,this.project)===re(i,this.project)&&!!p.readsValue)||i}inferDataTypeAndSyncInstancesInputsAndOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var Y,ie,te,pe,ne,me,J;const a=[],l=[],p=[],t=[];if(!this.dataType){const ae=Hi.new(i);ae.parent=this.toReference(),ae.inferred=!0;const ce=ee(ae,this.project);ce.hydrateAncestors(),ce.addSelfToProject(i),this.setDataType(ce,i),ce.setParent(this,i),ce.initChildren(i),i==null||i.add(ce,K.Added),ce.metaSync({inferred:!0,like:!0},i)}if(this.readsValue&&((Y=this.dataType)!=null&&Y.inferred)){const ae=this.readsValue.getDataType(null);ae&&((ie=this.dataType)==null||ie.merge(ae,i),this.dataType.metaSync({inferred:!0,like:!0},i))}const y=R([...this.inputs,...this.variableInstances.flatMap(ae=>ae.inputs)]),v=[];if(y.forEach(ae=>{v.find(H=>re(H,this.project)===re(ae,this.project))||v.push(ae)}),(!((te=this.dataType)!=null&&te.entity)||((ne=(pe=this.dataType)==null?void 0:pe.entity)==null?void 0:ne.type)===f.DefinitionEntity&&((me=this.dataType)==null?void 0:me.entity.parent)===this.dataType)&&((J=this.dataType)==null||J.inferFromInputs(v,i)),!this.dataType)return i==null||i.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:R(l),added:R(a),removed:R(p),affected:R(t),self:this};const{updated:T,added:w,removed:A,affected:V}=this.syncInputs(i);a.push(...w),l.push(...T),p.push(...A),t.push(...V);const{updated:N,added:j,removed:k,affected:q}=this.syncOutputs(i);return a.push(...j),l.push(...N),p.push(...k),t.push(...q),this.variableInstances.forEach(ae=>{const{updated:ce,added:H,removed:de,affected:ve}=ae.syncInputs(i);a.push(...H),l.push(...ce),p.push(...de),t.push(...ve);const{updated:Pe,added:Oe,removed:Ie,affected:_e}=ae.syncOutputs(i);a.push(...Oe),l.push(...Pe),p.push(...Ie),t.push(..._e)}),i==null||i.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:R(l),added:R(a),removed:R(p),affected:R(t),self:this}}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,this.constant=i.constant!==void 0?i.constant:p.constant,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await wt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await wt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await wt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await wt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await wt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await wt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeVariableDeclaration(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{l.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.outputs.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.dataType){const{updated:v,removed:T}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(T=>{l.push(T),T.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p,t;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...((t=this.readsValue)==null?void 0:t.toFlat(i))||[],...this.writesValues.flatMap(y=>y.toFlat(i)),...this.successCalls.flatMap(y=>y.toFlat(i)),...this.errorCalls.flatMap(y=>y.toFlat(i)),...this.inputs.flatMap(y=>y.toFlat(i)),...this.outputs.flatMap(y=>y.toFlat(i)),...this.internalCalls.flatMap(y=>y.toFlat(i)),...this.calledBy.flatMap(y=>y.toFlat(i))])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.writesValues.flatMap(t=>t.toFlatIds(i)),...this.successCalls.flatMap(t=>t.toFlatIds(i)),...this.errorCalls.flatMap(t=>t.toFlatIds(i)),...this.inputs.flatMap(t=>t.toFlatIds(i)),...this.outputs.flatMap(t=>t.toFlatIds(i)),...this.internalCalls.flatMap(t=>t.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p;return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,description:this.description,constant:this.constant,required:this.required,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((p=this.readsValue)==null?void 0:p.toReference())||null,writesValues:this.writesValues.map(t=>t.toJSON(i)),inputs:this.inputs.map(t=>t.toJSON(i)),outputs:this.outputs.map(t=>t.toJSON(i)),successCalls:this.successCalls.map(t=>t.toJSON(i)),errorCalls:this.errorCalls.map(t=>t.toJSON(i)),internalCalls:this.internalCalls.map(t=>t.toJSON(i)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(i=Ne){var l,p,t,y,v,T,w,A;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,readsValue:((A=this.readsValue)==null?void 0:A.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map(V=>V.toJSONClone({...i,newId:null})),inputs:this.inputs.map(V=>V.toJSONClone({...i,newId:null})),outputs:this.outputs.map(V=>V.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(V=>V.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(V=>V.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map(V=>this.calledBy.length||this.readsValue?V.toJSONClone({...i,newId:null}):V.toReference({seenEntityMaps:i.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(V=>V.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(V=>V.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(V=>V.toReference({seenEntityMaps:i.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,codeName:this.codeName,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((t=this.dataType)==null?void 0:t.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),internalCalls:this.internalCalls.map(v=>v.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(t=>t.toFlatJSON(i)),...this.successCalls.flatMap(t=>t.toFlatJSON(i)),...this.errorCalls.flatMap(t=>t.toFlatJSON(i)),...this.inputs.flatMap(t=>t.toFlatJSON(i)),...this.outputs.flatMap(t=>t.toFlatJSON(i)),...this.internalCalls.flatMap(t=>t.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(t=>t.toFlatGenerationTarget(i)),...this.successCalls.flatMap(t=>t.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(t=>t.toFlatGenerationTarget(i)),...this.inputs.flatMap(t=>t.toFlatGenerationTarget(i)),...this.outputs.flatMap(t=>t.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(t=>t.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),this.internalCalls.forEach(l=>l.clearErrors()),(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this}validate(){const i=DM(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l,p;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.inputs.flatMap(t=>t.getErrors()),...this.internalCalls.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...((p=this.readsValue)==null?void 0:p.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var k,q,Y,ie,te;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[],y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const T=Kt(y,t);a?T.setParent(a,null):T.setParent(this.parent,null),p&&T.subscribe(),T.initChildren(i),i==null||i.add(T,K.Added);const w=(k=this.dataType)==null?void 0:k.clone(i,T,P.UUID.uuid(),p);T.setDataType(w||null,i);const A=(q=this.defaultValue)==null?void 0:q.clone(i,T,P.UUID.uuid(),p);T.defaultValue=A||null;const V=(Y=this.inputs)==null?void 0:Y.map(pe=>pe.clone(i,T,P.UUID.uuid(),p));T.inputs=V;const N=(ie=this.outputs)==null?void 0:ie.map(pe=>pe.clone(i,T,P.UUID.uuid(),p));T.outputs=N;const j=(te=this.internalCalls)==null?void 0:te.map(pe=>pe.clone(i,T,P.UUID.uuid(),p));return T.internalCalls=j,i==null||i.attemptAutoclose("clone-entity",this.id),T}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}createInstance(i=this.project,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"create-instance")),l={}){const p={id:l.id||P.UUID.uuid(),version:l.version||P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,parent:i.toReference(),defaultValue:l.defaultValue||null,successCalls:l.successCalls||[],errorCalls:l.errorCalls||[],inputs:l.inputs||[],outputs:l.outputs||[],writesValues:l.writesValues||[],internalCalls:l.internalCalls||[],readsValue:l.readsValue||null,calledByEntry:l.calledByEntry||[],calledBySuccess:l.calledBySuccess||[],calledByError:l.calledByError||[],declaration:this.toReference(),x:0,y:0},t=ee(p,this.project);return t.hydrateAncestors(),t.setParent(i,a),a==null||a.add(t,K.Added),t.addSelfToProject(a),t.initChildren(a),i===this.project&&this.project.addVariableInstance(t),a==null||a.attemptAutoclose("create-instance",this.id),t}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-inputs"))){var v;const a=[],l=[],p=[],t=[];if(this.dataType&&!this.dataType.isObject())[...this.inputs].forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.dataType&&this.dataType.hasStrictObjectStructure()){const T=[...((v=this.dataType)==null?void 0:v.entity).allProperties];[...this.inputs].forEach(w=>{if(!w.declaration){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}if(!T.find(V=>w.declaration===V)){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated)}})}return this.inputs.filter((T,w)=>{const A=this.inputs.findIndex(N=>N.declaration===T.declaration&&N!==T);if(A===-1)return!1;const V=this.inputs[A];return L(V==null?void 0:V.createdAt).isSame(L(T.createdAt))?w>A:!!L(V==null?void 0:V.createdAt).isAfter(T.createdAt)}).forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-outputs"))){var v;const a=[],l=[],p=[],t=[];if(this.dataType&&!this.dataType.isObject())[...this.outputs].forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.dataType&&this.dataType.hasStrictObjectStructure()){const T=[...((v=this.dataType)==null?void 0:v.entity).allProperties];[...this.outputs].forEach(w=>{if(!w.declaration){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}if(!T.find(V=>w.declaration===V)){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}})}return this.outputs.filter((T,w)=>{const A=this.outputs.findIndex(N=>N.declaration===T.declaration&&N!==T);if(A===-1)return!1;const V=this.outputs[A];return L(V==null?void 0:V.createdAt).isSame(L(T.createdAt))?w>A:!!L(V==null?void 0:V.createdAt).isAfter(T.createdAt)}).forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],l=[],p=[],t=[];if(!this.dataType||!this.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.dataType.entity.type))[...this.internalCalls].forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.dataType&&this.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.dataType.entity.type)){const T=[...((v=this.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(w=>{if(!w.declaration){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}if(!T.find(V=>w.declaration===V)){const V=w.remove({ignoreUpstream:!1},i);p.push(...V.removed),a.push(...V.updated);return}})}return this.internalCalls.filter((T,w)=>{const A=this.internalCalls.findIndex(N=>N.declaration===T.declaration&&N!==T);if(A===-1)return!1;const V=this.internalCalls[A];return L(V==null?void 0:V.createdAt).isSame(L(T.createdAt))?w>A:!!L(V==null?void 0:V.createdAt).isAfter(T.createdAt)}).forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-variable-declaration-inputs"))){const a=[],l=[],p=[],t=[];if(this.dataType)if(this.dataType.entity){if(this.dataType.isObject()){const y=[...this.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const V=this.inputs.find(k=>re(k,this.project)===re(A,this.project));if(!V)return;const N=this.getMasterInputWithValueWritterFromAllInstances(V);if(!N)return;const j=zs(N);A.setDataType(j,i),V.setDeclaration(A)}),y.filter(A=>!this.inputs.find(V=>{var N;return((N=V.declaration)==null?void 0:N.id)===A.id})).forEach(A=>{const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},N=ee(V,this.project);return N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),this.addInput(N,i),N}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const V=y.find(N=>re(N,this.project)===re(A,this.project));V&&A.setDeclaration(V)})}}else return i==null||i.attemptAutoclose("sync-variable-declaration-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-declaration-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-declaration-inputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-variable-declaration-outputs"))){const a=[],l=[],p=[],t=[];if(this.dataType)if(this.dataType.entity)this.dataType.isObject()&&[...this.dataType.entity.properties].filter(T=>!this.outputs.find(w=>w.declaration===T)).map(T=>{const w={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,defaultValue:null,parent:this.toReference(),declaration:T,index:T.index,writesValues:[]},A=ee(w,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,K.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-declaration-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-declaration-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-declaration-outputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],l=[],p=[],t=[];if(this.dataType)if(this.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(T=>!this.internalCalls.find(A=>{var N,j,k,q,Y;return(((N=A.declaration)==null?void 0:N.id)||((k=(j=A.initialData)==null?void 0:j.declaration)==null?void 0:k.entityId)||((Y=(q=A.initialData)==null?void 0:q.declaration)==null?void 0:Y.id))===T.id})).map(T=>{const w=T.createInternalCall(i,this);return i==null||i.add(w,K.Added),this.addInternalCall(w),w});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}setDataType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.project.initialized&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(i),this.dataType||null}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};D(wt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(wt,"type",f.VariableDeclaration),D(wt,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(wt,"PARENT_TYPES",[...wt.USER_MANAGED_PARENT_TYPES]),D(wt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","constant","required"]),D(wt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(wt,"BASE_PROPERTIES",[...wt.MUTABLE_BASE_PROPERTIES,...wt.INMUTABLE_BASE_PROPERTIES]),D(wt,"MUTABLE_META_PROPERTIES",[...wt.MUTABLE_BASE_PROPERTIES,"x","y"]),D(wt,"INMUTABLE_META_PROPERTIES",[...wt.INMUTABLE_BASE_PROPERTIES]),D(wt,"META_PROPERTIES",[...wt.MUTABLE_META_PROPERTIES,...wt.INMUTABLE_META_PROPERTIES]),D(wt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),D(wt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),D(wt,"UPSTREAM_PROPERTIES",[...wt.MUTABLE_UPSTREAM_PROPERTIES,...wt.INMUTABLE_UPSTREAM_PROPERTIES]),D(wt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),D(wt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(wt,"DOWNSTREAM_PROPERTIES",[...wt.MUTABLE_DOWNSTREAM_PROPERTIES,...wt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(wt,"PROPERTIES",[...wt.META_PROPERTIES,...wt.UPSTREAM_PROPERTIES,...wt.DOWNSTREAM_PROPERTIES]);let ka=wt;function $M(d){var t;const u=zde(),i=d.toJSON();u.safeParse(i).success,d.inputsDeclarations.forEach(y=>y.validate()),d.inputs.forEach(y=>y.validate()),d.outputsDeclarations.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),(t=d.error)==null||t.validate();const p=[...fa(d)];return zt(d.errors,p)}const zfe=Object.freeze(Object.defineProperty({__proto__:null,validate:$M},Symbol.toStringTag,{value:"Module"}));var md={},PM={},VM={};Object.defineProperty(VM,"__esModule",{value:!0});var NM={};Object.defineProperty(NM,"__esModule",{value:!0});var LM={};Object.defineProperty(LM,"__esModule",{value:!0});var BM={};Object.defineProperty(BM,"__esModule",{value:!0});var MM={};Object.defineProperty(MM,"__esModule",{value:!0});var UM={};Object.defineProperty(UM,"__esModule",{value:!0});var jM={};Object.defineProperty(jM,"__esModule",{value:!0});var xM={};Object.defineProperty(xM,"__esModule",{value:!0});var FM={};Object.defineProperty(FM,"__esModule",{value:!0});var GM={};Object.defineProperty(GM,"__esModule",{value:!0});var KM={};Object.defineProperty(KM,"__esModule",{value:!0});var kM={};Object.defineProperty(kM,"__esModule",{value:!0});var qM={};Object.defineProperty(qM,"__esModule",{value:!0});var SM={};Object.defineProperty(SM,"__esModule",{value:!0});var ZM={};Object.defineProperty(ZM,"__esModule",{value:!0});var JM={};Object.defineProperty(JM,"__esModule",{value:!0});var WM={};Object.defineProperty(WM,"__esModule",{value:!0});var YM={};Object.defineProperty(YM,"__esModule",{value:!0});var HM={};Object.defineProperty(HM,"__esModule",{value:!0});var zM={};Object.defineProperty(zM,"__esModule",{value:!0});var XM={};Object.defineProperty(XM,"__esModule",{value:!0});var QM={};Object.defineProperty(QM,"__esModule",{value:!0});var e3={};Object.defineProperty(e3,"__esModule",{value:!0});var t3={};Object.defineProperty(t3,"__esModule",{value:!0});var r3={};Object.defineProperty(r3,"__esModule",{value:!0});var i3={};Object.defineProperty(i3,"__esModule",{value:!0});var s3={};Object.defineProperty(s3,"__esModule",{value:!0});var n3={};Object.defineProperty(n3,"__esModule",{value:!0});var a3={};Object.defineProperty(a3,"__esModule",{value:!0});var o3={};Object.defineProperty(o3,"__esModule",{value:!0});var l3={};Object.defineProperty(l3,"__esModule",{value:!0});var d3={};Object.defineProperty(d3,"__esModule",{value:!0});var u3={};Object.defineProperty(u3,"__esModule",{value:!0});var c3={};Object.defineProperty(c3,"__esModule",{value:!0});var p3={};Object.defineProperty(p3,"__esModule",{value:!0});var f3={};Object.defineProperty(f3,"__esModule",{value:!0});var h3={};Object.defineProperty(h3,"__esModule",{value:!0});var y3={};Object.defineProperty(y3,"__esModule",{value:!0});var m3={};Object.defineProperty(m3,"__esModule",{value:!0});var v3={};Object.defineProperty(v3,"__esModule",{value:!0});var E3={};Object.defineProperty(E3,"__esModule",{value:!0});var T3={};Object.defineProperty(T3,"__esModule",{value:!0});var b3={};Object.defineProperty(b3,"__esModule",{value:!0}),function(d){var u=ds&&ds.__createBinding||(Object.create?function(a,l,p,t){t===void 0&&(t=p);var y=Object.getOwnPropertyDescriptor(l,p);(!y||("get"in y?!l.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return l[p]}}),Object.defineProperty(a,t,y)}:function(a,l,p,t){t===void 0&&(t=p),a[t]=l[p]}),i=ds&&ds.__exportStar||function(a,l){for(var p in a)p!=="default"&&!Object.prototype.hasOwnProperty.call(l,p)&&u(l,a,p)};Object.defineProperty(d,"__esModule",{value:!0}),i(VM,d),i(NM,d),i(LM,d),i(BM,d),i(MM,d),i(UM,d),i(jM,d),i(xM,d),i(FM,d),i(GM,d),i(KM,d),i(kM,d),i(qM,d),i(SM,d),i(ZM,d),i(JM,d),i(WM,d),i(YM,d),i(HM,d),i(zM,d),i(XM,d),i(QM,d),i(e3,d),i(t3,d),i(r3,d),i(i3,d),i(s3,d),i(n3,d),i(a3,d),i(o3,d),i(l3,d),i(d3,d),i(u3,d),i(c3,d),i(p3,d),i(f3,d),i(h3,d),i(y3,d),i(m3,d),i(v3,d),i(E3,d),i(T3,d),i(b3,d)}(PM);var A3={},Ii={};Object.defineProperty(Ii,"__esModule",{value:!0}),Ii.isObject=Ii.isString=Ii.isDefined=Ii.last=Ii.identity=void 0;const Xfe=d=>d;Ii.identity=Xfe;const Qfe=d=>d[d.length-1];Ii.last=Qfe;const ehe=d=>d!==void 0;Ii.isDefined=ehe;const the=d=>typeof d=="string";Ii.isString=the;const rhe=d=>typeof d=="object"&&d!==null&&!(d instanceof Array);Ii.isObject=rhe,function(d){Object.defineProperty(d,"__esModule",{value:!0}),d.cstVisitor=d.VisitorAction=void 0;const u=Ii;var i;(function(p){p[p.SKIP=1]="SKIP"})(i=d.VisitorAction||(d.VisitorAction={}));function a(p){const t=y=>{const v=p[y.type];if((v==null?void 0:v(y))!==i.SKIP)for(const w of Object.values(y))l(w)?t(w):w instanceof Array&&w.filter(l).forEach(A=>t(A))};return t}d.cstVisitor=a;const l=p=>(0,u.isObject)(p)&&(0,u.isString)(p.type)}(A3);var bc={};Object.defineProperty(bc,"__esModule",{value:!0}),bc.cstTransformer=void 0;function ihe(d){return u=>{const i=d[u.type];if(!i)throw u.type?new Error(`No transform map entry for ${u.type}`):new Error(`No type field on node: ${JSON.stringify(u)}`);return i(u)}}bc.cstTransformer=ihe;var I3={},Ac={};Object.defineProperty(Ac,"__esModule",{value:!0}),Ac.bigqueryKeywords=void 0,Ac.bigqueryKeywords={ALL:!0,AND:!0,ANY:!0,ARRAY:!0,AS:!0,ASC:!0,ASSERT_ROWS_MODIFIED:!0,AT:!0,BETWEEN:!0,BY:!0,CASE:!0,CAST:!0,COLLATE:!0,CONTAINS:!0,CREATE:!0,CROSS:!0,CUBE:!0,CURRENT:!0,DEFAULT:!0,DEFINE:!0,DESC:!0,DISTINCT:!0,ELSE:!0,END:!0,ENUM:!0,ESCAPE:!0,EXCEPT:!0,EXCLUDE:!0,EXISTS:!0,EXTRACT:!0,FALSE:!0,FETCH:!0,FOLLOWING:!0,FOR:!0,FROM:!0,FULL:!0,GROUP:!0,GROUPING:!0,GROUPS:!0,HASH:!0,HAVING:!0,IF:!0,IGNORE:!0,IN:!0,INNER:!0,INTERSECT:!0,INTERVAL:!0,INTO:!0,IS:!0,JOIN:!0,LATERAL:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LOOKUP:!0,MERGE:!0,NATURAL:!0,NEW:!0,NO:!0,NOT:!0,NULL:!0,NULLS:!0,OF:!0,ON:!0,OR:!0,ORDER:!0,OUTER:!0,OVER:!0,PARTITION:!0,PRECEDING:!0,PROTO:!0,QUALIFY:!0,RANGE:!0,RECURSIVE:!0,RESPECT:!0,RIGHT:!0,ROLLUP:!0,ROWS:!0,SELECT:!0,SET:!0,SOME:!0,STRUCT:!0,TABLESAMPLE:!0,THEN:!0,TO:!0,TREAT:!0,TRUE:!0,UNBOUNDED:!0,UNION:!0,UNNEST:!0,USING:!0,WHEN:!0,WHERE:!0,WINDOW:!0,WITH:!0,WITHIN:!0};var Ic={};Object.defineProperty(Ic,"__esModule",{value:!0}),Ic.mariadbKeywords=void 0,Ic.mariadbKeywords={ACCESSIBLE:!0,ADD:!0,ALL:!0,ALTER:!0,ANALYZE:!0,AND:!0,AS:!0,ASC:!0,ASENSITIVE:!0,BEFORE:!0,BETWEEN:!0,BIGINT:!0,BINARY:!0,BLOB:!0,BOTH:!0,BY:!0,CALL:!0,CASCADE:!0,CASE:!0,CHANGE:!0,CHAR:!0,CHARACTER:!0,CHECK:!0,COLLATE:!0,COLUMN:!0,CONDITION:!0,CONSTRAINT:!0,CONTINUE:!0,CONVERT:!0,CREATE:!0,CROSS:!0,CURRENT_DATE:!0,CURRENT_ROLE:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,CURRENT_USER:!0,CURSOR:!0,DATABASE:!0,DATABASES:!0,DAY_HOUR:!0,DAY_MICROSECOND:!0,DAY_MINUTE:!0,DAY_SECOND:!0,DEC:!0,DECIMAL:!0,DECLARE:!0,DEFAULT:!0,DELAYED:!0,DELETE:!0,DELETE_DOMAIN_ID:!0,DESC:!0,DESCRIBE:!0,DETERMINISTIC:!0,DISTINCT:!0,DISTINCTROW:!0,DIV:!0,DO_DOMAIN_IDS:!0,DOUBLE:!0,DROP:!0,DUAL:!0,EACH:!0,ELSE:!0,ELSEIF:!0,ENCLOSED:!0,ESCAPED:!0,EXCEPT:!0,EXISTS:!0,EXIT:!0,EXPLAIN:!0,FALSE:!0,FETCH:!0,FLOAT:!0,FLOAT4:!0,FLOAT8:!0,FOR:!0,FORCE:!0,FOREIGN:!0,FROM:!0,FULLTEXT:!0,GENERAL:!0,GRANT:!0,GROUP:!0,HAVING:!0,HIGH_PRIORITY:!0,HOUR_MICROSECOND:!0,HOUR_MINUTE:!0,HOUR_SECOND:!0,IF:!0,IGNORE:!0,IGNORE_DOMAIN_IDS:!0,IGNORE_SERVER_IDS:!0,IN:!0,INDEX:!0,INFILE:!0,INNER:!0,INOUT:!0,INSENSITIVE:!0,INSERT:!0,INT:!0,INT1:!0,INT2:!0,INT3:!0,INT4:!0,INT8:!0,INTEGER:!0,INTERSECT:!0,INTERVAL:!0,INTO:!0,IS:!0,ITERATE:!0,JOIN:!0,KEY:!0,KEYS:!0,KILL:!0,LEADING:!0,LEAVE:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LINEAR:!0,LINES:!0,LOAD:!0,LOCALTIME:!0,LOCALTIMESTAMP:!0,LOCK:!0,LONG:!0,LONGBLOB:!0,LONGTEXT:!0,LOOP:!0,LOW_PRIORITY:!0,MASTER_HEARTBEAT_PERIOD:!0,MASTER_SSL_VERIFY_SERVER_CERT:!0,MATCH:!0,MAXVALUE:!0,MEDIUMBLOB:!0,MEDIUMINT:!0,MEDIUMTEXT:!0,MIDDLEINT:!0,MINUTE_MICROSECOND:!0,MINUTE_SECOND:!0,MOD:!0,MODIFIES:!0,NATURAL:!0,NOT:!0,NO_WRITE_TO_BINLOG:!0,NULL:!0,NUMERIC:!0,OFFSET:!0,ON:!0,OPTIMIZE:!0,OPTION:!0,OPTIONALLY:!0,OR:!0,ORDER:!0,OUT:!0,OUTER:!0,OUTFILE:!0,OVER:!0,PAGE_CHECKSUM:!0,PARSE_VCOL_EXPR:!0,PARTITION:!0,POSITION:!0,PRECISION:!0,PRIMARY:!0,PROCEDURE:!0,PURGE:!0,RANGE:!0,READ:!0,READS:!0,READ_WRITE:!0,REAL:!0,RECURSIVE:!0,REF_SYSTEM_ID:!0,REFERENCES:!0,REGEXP:!0,RELEASE:!0,RENAME:!0,REPEAT:!0,REPLACE:!0,REQUIRE:!0,RESIGNAL:!0,RESTRICT:!0,RETURN:!0,RETURNING:!0,REVOKE:!0,RIGHT:!0,RLIKE:!0,ROWS:!0,SCHEMA:!0,SCHEMAS:!0,SECOND_MICROSECOND:!0,SELECT:!0,SENSITIVE:!0,SEPARATOR:!0,SET:!0,SHOW:!0,SIGNAL:!0,SLOW:!0,SMALLINT:!0,SPATIAL:!0,SPECIFIC:!0,SQL:!0,SQLEXCEPTION:!0,SQLSTATE:!0,SQLWARNING:!0,SQL_BIG_RESULT:!0,SQL_CALC_FOUND_ROWS:!0,SQL_SMALL_RESULT:!0,SSL:!0,STARTING:!0,STATS_AUTO_RECALC:!0,STATS_PERSISTENT:!0,STATS_SAMPLE_PAGES:!0,STRAIGHT_JOIN:!0,TABLE:!0,TERMINATED:!0,THEN:!0,TINYBLOB:!0,TINYINT:!0,TINYTEXT:!0,TO:!0,TRAILING:!0,TRIGGER:!0,TRUE:!0,UNDO:!0,UNION:!0,UNIQUE:!0,UNLOCK:!0,UNSIGNED:!0,UPDATE:!0,USAGE:!0,USE:!0,USING:!0,UTC_DATE:!0,UTC_TIME:!0,UTC_TIMESTAMP:!0,VALUES:!0,VARBINARY:!0,VARCHAR:!0,VARCHARACTER:!0,VARYING:!0,WHEN:!0,WHERE:!0,WHILE:!0,WINDOW:!0,WITH:!0,WRITE:!0,XOR:!0,YEAR_MONTH:!0,ZEROFILL:!0};var wc={};Object.defineProperty(wc,"__esModule",{value:!0}),wc.mysqlKeywords=void 0,wc.mysqlKeywords={ACCESSIBLE:!0,ADD:!0,ALL:!0,ALTER:!0,ANALYZE:!0,AND:!0,AS:!0,ASC:!0,ASENSITIVE:!0,BEFORE:!0,BETWEEN:!0,BIGINT:!0,BINARY:!0,BLOB:!0,BOTH:!0,BY:!0,CALL:!0,CASCADE:!0,CASE:!0,CHANGE:!0,CHAR:!0,CHARACTER:!0,CHECK:!0,COLLATE:!0,COLUMN:!0,CONDITION:!0,CONSTRAINT:!0,CONTINUE:!0,CONVERT:!0,CREATE:!0,CROSS:!0,CUBE:!0,CUME_DIST:!0,CURRENT_DATE:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,CURRENT_USER:!0,CURSOR:!0,DATABASE:!0,DATABASES:!0,DAY_HOUR:!0,DAY_MICROSECOND:!0,DAY_MINUTE:!0,DAY_SECOND:!0,DEC:!0,DECIMAL:!0,DECLARE:!0,DEFAULT:!0,DELAYED:!0,DELETE:!0,DENSE_RANK:!0,DESC:!0,DESCRIBE:!0,DETERMINISTIC:!0,DISTINCT:!0,DISTINCTROW:!0,DIV:!0,DOUBLE:!0,DROP:!0,DUAL:!0,EACH:!0,ELSE:!0,ELSEIF:!0,EMPTY:!0,ENCLOSED:!0,ESCAPED:!0,EXCEPT:!0,EXISTS:!0,EXIT:!0,EXPLAIN:!0,FALSE:!0,FETCH:!0,FIRST_VALUE:!0,FLOAT:!0,FLOAT4:!0,FLOAT8:!0,FOR:!0,FORCE:!0,FOREIGN:!0,FROM:!0,FULLTEXT:!0,FUNCTION:!0,GENERATED:!0,GET:!0,GRANT:!0,GROUP:!0,GROUPING:!0,GROUPS:!0,HAVING:!0,HIGH_PRIORITY:!0,HOUR_MICROSECOND:!0,HOUR_MINUTE:!0,HOUR_SECOND:!0,IF:!0,IGNORE:!0,IN:!0,INDEX:!0,INFILE:!0,INNER:!0,INOUT:!0,INSENSITIVE:!0,INSERT:!0,INT:!0,INT1:!0,INT2:!0,INT3:!0,INT4:!0,INT8:!0,INTEGER:!0,INTERSECT:!0,INTERVAL:!0,INTO:!0,IO_AFTER_GTIDS:!0,IO_BEFORE_GTIDS:!0,IS:!0,ITERATE:!0,JOIN:!0,JSON_TABLE:!0,KEY:!0,KEYS:!0,KILL:!0,LAG:!0,LAST_VALUE:!0,LATERAL:!0,LEAD:!0,LEADING:!0,LEAVE:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LINEAR:!0,LINES:!0,LOAD:!0,LOCALTIME:!0,LOCALTIMESTAMP:!0,LOCK:!0,LONG:!0,LONGBLOB:!0,LONGTEXT:!0,LOOP:!0,LOW_PRIORITY:!0,MASTER_BIND:!0,MASTER_SSL_VERIFY_SERVER_CERT:!0,MATCH:!0,MAXVALUE:!0,MEDIUMBLOB:!0,MEDIUMINT:!0,MEDIUMTEXT:!0,MIDDLEINT:!0,MINUTE_MICROSECOND:!0,MINUTE_SECOND:!0,MOD:!0,MODIFIES:!0,NATURAL:!0,NOT:!0,NO_WRITE_TO_BINLOG:!0,NTH_VALUE:!0,NTILE:!0,NULL:!0,NUMERIC:!0,OF:!0,ON:!0,OPTIMIZE:!0,OPTIMIZER_COSTS:!0,OPTION:!0,OPTIONALLY:!0,OR:!0,ORDER:!0,OUT:!0,OUTER:!0,OUTFILE:!0,OVER:!0,PARTITION:!0,PERCENT_RANK:!0,PRECISION:!0,PRIMARY:!0,PROCEDURE:!0,PURGE:!0,RANGE:!0,RANK:!0,READ:!0,READS:!0,READ_WRITE:!0,REAL:!0,RECURSIVE:!0,REFERENCES:!0,REGEXP:!0,RELEASE:!0,RENAME:!0,REPEAT:!0,REPLACE:!0,REQUIRE:!0,RESIGNAL:!0,RESTRICT:!0,RETURN:!0,REVOKE:!0,RIGHT:!0,RLIKE:!0,ROW:!0,ROWS:!0,ROW_NUMBER:!0,SCHEMA:!0,SCHEMAS:!0,SECOND_MICROSECOND:!0,SELECT:!0,SENSITIVE:!0,SEPARATOR:!0,SET:!0,SHOW:!0,SIGNAL:!0,SMALLINT:!0,SPATIAL:!0,SPECIFIC:!0,SQL:!0,SQLEXCEPTION:!0,SQLSTATE:!0,SQLWARNING:!0,SQL_BIG_RESULT:!0,SQL_CALC_FOUND_ROWS:!0,SQL_SMALL_RESULT:!0,SSL:!0,STARTING:!0,STORED:!0,STRAIGHT_JOIN:!0,SYSTEM:!0,TABLE:!0,TERMINATED:!0,THEN:!0,TINYBLOB:!0,TINYINT:!0,TINYTEXT:!0,TO:!0,TRAILING:!0,TRIGGER:!0,TRUE:!0,UNDO:!0,UNION:!0,UNIQUE:!0,UNLOCK:!0,UNSIGNED:!0,UPDATE:!0,USAGE:!0,USE:!0,USING:!0,UTC_DATE:!0,UTC_TIME:!0,UTC_TIMESTAMP:!0,VALUES:!0,VARBINARY:!0,VARCHAR:!0,VARCHARACTER:!0,VARYING:!0,VIRTUAL:!0,WHEN:!0,WHERE:!0,WHILE:!0,WINDOW:!0,WITH:!0,WRITE:!0,XOR:!0,YEAR_MONTH:!0,ZEROFILL:!0};var Rc={};Object.defineProperty(Rc,"__esModule",{value:!0}),Rc.sqliteKeywords=void 0,Rc.sqliteKeywords={ABORT:!0,ACTION:!0,ADD:!0,AFTER:!0,ALL:!0,ALTER:!0,ALWAYS:!0,ANALYZE:!0,AND:!0,AS:!0,ASC:!0,ATTACH:!0,AUTOINCREMENT:!0,BEFORE:!0,BEGIN:!0,BETWEEN:!0,BY:!0,CASCADE:!0,CASE:!0,CAST:!0,CHECK:!0,COLLATE:!0,COMMIT:!0,CONFLICT:!0,CONSTRAINT:!0,CREATE:!0,CROSS:!0,CURRENT:!0,CURRENT_DATE:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,DATABASE:!0,DEFAULT:!0,DEFERRABLE:!0,DEFERRED:!0,DELETE:!0,DESC:!0,DETACH:!0,DISTINCT:!0,DO:!0,DROP:!0,EACH:!0,ELSE:!0,END:!0,ESCAPE:!0,EXCEPT:!0,EXCLUDE:!0,EXCLUSIVE:!0,EXISTS:!0,EXPLAIN:!0,FAIL:!0,FILTER:!0,FIRST:!0,FOLLOWING:!0,FOR:!0,FOREIGN:!0,FROM:!0,FULL:!0,GENERATED:!0,GLOB:!0,GROUP:!0,GROUPS:!0,HAVING:!0,IF:!0,IGNORE:!0,IMMEDIATE:!0,IN:!0,INDEX:!0,INDEXED:!0,INITIALLY:!0,INNER:!0,INSERT:!0,INSTEAD:!0,INTERSECT:!0,INTO:!0,IS:!0,ISNULL:!0,JOIN:!0,LAST:!0,LEFT:!0,LIKE:!0,LIMIT:!0,MATCH:!0,MATERIALIZED:!0,NATURAL:!0,NO:!0,NOT:!0,NOTHING:!0,NOTNULL:!0,NULL:!0,NULLS:!0,OF:!0,OFFSET:!0,ON:!0,OR:!0,ORDER:!0,OTHERS:!0,OUTER:!0,OVER:!0,PARTITION:!0,PLAN:!0,PRAGMA:!0,PRECEDING:!0,PRIMARY:!0,QUERY:!0,RAISE:!0,RANGE:!0,RECURSIVE:!0,REFERENCES:!0,REGEXP:!0,REINDEX:!0,RELEASE:!0,RENAME:!0,REPLACE:!0,RESTRICT:!0,RETURNING:!0,RIGHT:!0,ROLLBACK:!0,ROW:!0,ROWS:!0,SAVEPOINT:!0,SELECT:!0,SET:!0,TABLE:!0,TEMP:!0,TEMPORARY:!0,THEN:!0,TIES:!0,TO:!0,TRANSACTION:!0,TRIGGER:!0,UNBOUNDED:!0,UNION:!0,UNIQUE:!0,UPDATE:!0,USING:!0,VACUUM:!0,VALUES:!0,VIEW:!0,VIRTUAL:!0,WHEN:!0,WHERE:!0,WINDOW:!0,WITH:!0,WITHOUT:!0};var _c={};Object.defineProperty(_c,"__esModule",{value:!0}),_c.postgresqlKeywords=void 0,_c.postgresqlKeywords={ALL:!0,ANALYSE:!0,ANALYZE:!0,AND:!0,ANY:!0,ARRAY:!0,AS:!0,ASC:!0,ASYMMETRIC:!0,AUTHORIZATION:!0,BOTH:!0,CASE:!0,CAST:!0,CHECK:!0,COLLATE:!0,COLUMN:!0,CONSTRAINT:!0,CREATE:!0,CROSS:!0,CURRENT_CATALOG:!0,CURRENT_DATE:!0,CURRENT_ROLE:!0,CURRENT_SCHEMA:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,CURRENT_USER:!0,DAY:!0,DEFAULT:!0,DEFERRABLE:!0,DESC:!0,DISTINCT:!0,DO:!0,ELSE:!0,END:!0,EXCEPT:!0,FALSE:!0,FETCH:!0,FILTER:!0,FOR:!0,FOREIGN:!0,FREEZE:!0,FROM:!0,FULL:!0,GRANT:!0,GROUP:!0,HAVING:!0,HOUR:!0,ILIKE:!0,IN:!0,INITIALLY:!0,INNER:!0,INTERSECT:!0,INTO:!0,IS:!0,ISNULL:!0,JOIN:!0,LATERAL:!0,LEADING:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LOCALTIME:!0,LOCALTIMESTAMP:!0,MINUTE:!0,MONTH:!0,NATURAL:!0,NOT:!0,NOTNULL:!0,NULL:!0,OFFSET:!0,ON:!0,ONLY:!0,OR:!0,ORDER:!0,OUTER:!0,OVER:!0,OVERLAPS:!0,PLACING:!0,PRECISION:!0,PRIMARY:!0,REFERENCES:!0,RETURNING:!0,RIGHT:!0,SECOND:!0,SELECT:!0,SESSION_USER:!0,SIMILAR:!0,SOME:!0,SYMMETRIC:!0,SYSTEM_USER:!0,TABLE:!0,TABLESAMPLE:!0,THEN:!0,TO:!0,TRAILING:!0,TRUE:!0,UNION:!0,UNIQUE:!0,USER:!0,USING:!0,VARIADIC:!0,VARYING:!0,VERBOSE:!0,WHEN:!0,WHERE:!0,WINDOW:!0,WITH:!0,WITHIN:!0,WITHOUT:!0,YEAR:!0,SET:!0},function(d){var u=ds&&ds.__createBinding||(Object.create?function(a,l,p,t){t===void 0&&(t=p);var y=Object.getOwnPropertyDescriptor(l,p);(!y||("get"in y?!l.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return l[p]}}),Object.defineProperty(a,t,y)}:function(a,l,p,t){t===void 0&&(t=p),a[t]=l[p]}),i=ds&&ds.__exportStar||function(a,l){for(var p in a)p!=="default"&&!Object.prototype.hasOwnProperty.call(l,p)&&u(l,a,p)};Object.defineProperty(d,"__esModule",{value:!0}),i(Ac,d),i(Ic,d),i(wc,d),i(Rc,d),i(_c,d)}(I3);var gc={};Object.defineProperty(gc,"__esModule",{value:!0}),gc.FormattedSyntaxError=void 0;class she extends Error{constructor(u,i,a){super(nhe(u,i,a))}}gc.FormattedSyntaxError=she;function nhe(d,u,i){const a=d.location.start.line,l=d.location.start.column,p=u.split(/\r\n|\n|\r/)[a-1],t="".padStart(String(a).length),y=ohe(ahe(d.found,l,p)),v=lhe(d.expected);return`Syntax Error: Unexpected ${y}
|
|
@@ -156,7 +156,7 @@ ${Ha}`);const N=l.declaration;if(!a.get(N))p.push(new Q({id:`${l.id}--${S.Refere
|
|
|
156
156
|
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.${V}`,issue:null})):p.push(new Q({id:`${l.id}--${oe.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:oe.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:Z.Error,message:`Entity of type "${l.type}" with id "${l.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${l.declaration}".${V}`,issue:null}))}}(v.inputs.length||v.outputs.length||v.internalCalls.length)&&p.push(new Q({id:`${l.id}--${S.InvalidInternalCallParentRelation}`,code:S.InvalidInternalCallParentRelation,severity:Z.Error,message:`Entity of type "${l.type}" with id "${l.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.
|
|
157
157
|
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.
|
|
158
158
|
The you can attach the new internal-call to it.`,issue:null}))}return p.push(...t.errors,...vr(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
159
|
-
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Rt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Rt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:w,added:A,removed:V}=this.syncOutputs(i);return a.push(...y,...w),l.push(...v,...A),p.push(...T,...V),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parent.addInternalCall(this),t.push(this.parent),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==f.GenericReference){const a=ee(this.initialData.parent,this.project);this.setParent(a,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const l=this.calledBy.find(p=>!!p.parent&&br.includes(p.parent.type));if(l){const p=ee(l.parent,this.project);this.parent.setParent(p,null)}else if(!l&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this.parent,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this.parent,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=ee(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Rt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Rt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Rt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Rt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Rt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Rt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent&&(this.parent.removeInternalCall(this,i),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.process){const{updated:T,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:T,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(i):[],...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=kU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid();const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(j=this.inputs)==null?void 0:j.map((q,Y)=>q.clone(i,A,w+"-input-map-"+Y+"-id",p));A.inputs=V;const N=(k=this.outputs)==null?void 0:k.map((q,Y)=>q.clone(i,A,w+"-output-map-"+Y+"-id",p));return A.outputs=N,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],t=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,T)=>{const w=this.outputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>!this.inputs.find(V=>V.declaration.id===A.id));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i),l.push(N)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],t=[],y=[];this.outputs=this.initialData.outputs.map(V=>{const N=ee(V,this.project);return y.push(N.index),N.setParent(this,null),N.initChildren(i),N});const v=this.declaration.getUniqueReturnDeclarations().filter(V=>!this.outputs.find(N=>N.declaration.id===V.id));this.outputs.sort((V,N)=>V.index-N.index),v.forEach((V,N)=>{this.outputs.forEach(Y=>{Y.index>=V.index&&Y.index++});const j=y.includes(V.index)?this.outputs.length-1+N:V.index,k={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:V.toJSON(),defaultValue:null,writesValues:[],index:j,parent:this.toReference()},q=ee(k,this.project);q.setParent(this,i),q.initChildren(i),i==null||i.add(q,K.Added),q.addSelfToProject(i)}),this.outputs.sort((V,N)=>V.index-N.index);const{updated:T,added:w,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...w),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Rt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Rt,"type",f.InternalCall),D(Rt,"USER_MANAGED_PARENT_TYPES",[...rt]),D(Rt,"PARENT_TYPES",[...Rt.USER_MANAGED_PARENT_TYPES]),D(Rt,"MUTABLE_BASE_PROPERTIES",[]),D(Rt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Rt,"BASE_PROPERTIES",[...Rt.MUTABLE_BASE_PROPERTIES,...Rt.INMUTABLE_BASE_PROPERTIES]),D(Rt,"MUTABLE_META_PROPERTIES",[...Rt.MUTABLE_BASE_PROPERTIES,"index"]),D(Rt,"INMUTABLE_META_PROPERTIES",[...Rt.INMUTABLE_BASE_PROPERTIES]),D(Rt,"META_PROPERTIES",[...Rt.MUTABLE_META_PROPERTIES,...Rt.INMUTABLE_META_PROPERTIES]),D(Rt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),D(Rt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),D(Rt,"UPSTREAM_PROPERTIES",[...Rt.MUTABLE_UPSTREAM_PROPERTIES,...Rt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Rt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),D(Rt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Rt,"DOWNSTREAM_PROPERTIES",[...Rt.MUTABLE_DOWNSTREAM_PROPERTIES,...Rt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Rt,"PROPERTIES",[...Rt.META_PROPERTIES,...Rt.UPSTREAM_PROPERTIES,...Rt.DOWNSTREAM_PROPERTIES]);let Za=Rt;function ZU(d){const u=nue(),i=d.toJSON();u.safeParse(i).success;const l=[];if(d.id==="exec-sequentially-argument-map-id"){const p=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(p.error)}return zt(d.errors,l)}const qye=Object.freeze(Object.defineProperty({__proto__:null,validate:ZU},Symbol.toStringTag,{value:"Module"}));var JU=(d=>(d.Declaration="declaration",d.DataTypeEntity="data-type-entity",d))(JU||{});const _t=class _t extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"index");D(this,"name",null);D(this,"codeName",null);D(this,"description",null);D(this,"type",f.InputMap);D(this,"defaultValue",null);D(this,"readsValue",null);D(this,"dataType",null);D(this,"declaration",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name||null,this.description=i.description||null}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l);let t=null;if(i.declaration){const w=W(i.declaration);t=a.get(w)}let y=null;if(i.readsValue){const w=W(i.readsValue);y=a.get(w)}const v={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,type:f.InputMap,index:(p.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:t,readsValue:y,defaultValue:null,parent:p},T=ee(v,a);return T.setParent(p,null),T}static validateGenerationTarget(i,a){var w;let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[...Xt,f.InputMap]}},a);l=t.modifiedData;const y=a.get(l.parent),v=l.declaration&&(a.get(l.declaration)||a.getBuiltIn(l.declaration)),T=((y==null?void 0:y.inputs)||[]).find(A=>{var V;return l.declaration&&((V=A.declaration)==null?void 0:V.id)===l.declaration});if(l.declaration?v?[f.Property,f.ArgumentDeclaration,f.ValueDescriptor].includes(v.type)?y&&v.type===f.ArgumentDeclaration&&![f.FunctionCall,f.Search,f.InternalCall].includes(y.type)?p.push(new Q({id:`${l.id}--${S.InvalidInputMapDeclaration}`,code:S.InvalidInputMapDeclaration,severity:Z.Error,message:`Entity of type '${f.InputMap}' with id '${l.id}' has a 'declaration' property pointing to an entity with type '${f.ArgumentDeclaration}' with id '${l.declaration}'.
|
|
159
|
+
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Rt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Rt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:w,added:A,removed:V}=this.syncOutputs(i);return a.push(...y,...w),l.push(...v,...A),p.push(...T,...V),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parent.addInternalCall(this),t.push(this.parent),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==f.GenericReference){const a=ee(this.initialData.parent,this.project);this.setParent(a,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const l=this.calledBy.find(p=>!!p.parent&&br.includes(p.parent.type));if(l){const p=ee(l.parent,this.project);this.parent.setParent(p,null)}else if(!l&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this.parent,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this.parent,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=ee(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Rt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Rt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Rt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Rt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Rt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Rt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent&&(this.parent.removeInternalCall(this,i),t.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.process){const{updated:T,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:T,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(i):[],...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=kU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid();const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(j=this.inputs)==null?void 0:j.map((q,Y)=>q.clone(i,A,w+"-input-map-"+Y+"-id",p));A.inputs=V;const N=(k=this.outputs)==null?void 0:k.map((q,Y)=>q.clone(i,A,w+"-output-map-"+Y+"-id",p));return A.outputs=N,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],t=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,T)=>{const w=this.outputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>!this.inputs.find(V=>V.declaration.id===A.id));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i),l.push(N)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],t=[],y=[];this.outputs=this.initialData.outputs.map(V=>{const N=ee(V,this.project);return y.push(N.index),N.setParent(this,null),N.initChildren(i),N});const v=this.declaration.getUniqueReturnDeclarations().filter(V=>!this.outputs.find(N=>N.declaration.id===V.id));this.outputs.sort((V,N)=>V.index-N.index),v.forEach((V,N)=>{this.outputs.forEach(Y=>{Y.index>=V.index&&Y.index++});const j=y.includes(V.index)?this.outputs.length-1+N:V.index,k={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:V.toJSON(),defaultValue:null,writesValues:[],index:j,parent:this.toReference()},q=ee(k,this.project);q.setParent(this,i),q.initChildren(i),i==null||i.add(q,K.Added),q.addSelfToProject(i)}),this.outputs.sort((V,N)=>V.index-N.index);const{updated:T,added:w,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...w),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Rt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Rt,"type",f.InternalCall),D(Rt,"USER_MANAGED_PARENT_TYPES",[...rt]),D(Rt,"PARENT_TYPES",[...Rt.USER_MANAGED_PARENT_TYPES]),D(Rt,"MUTABLE_BASE_PROPERTIES",[]),D(Rt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Rt,"BASE_PROPERTIES",[...Rt.MUTABLE_BASE_PROPERTIES,...Rt.INMUTABLE_BASE_PROPERTIES]),D(Rt,"MUTABLE_META_PROPERTIES",[...Rt.MUTABLE_BASE_PROPERTIES,"index"]),D(Rt,"INMUTABLE_META_PROPERTIES",[...Rt.INMUTABLE_BASE_PROPERTIES]),D(Rt,"META_PROPERTIES",[...Rt.MUTABLE_META_PROPERTIES,...Rt.INMUTABLE_META_PROPERTIES]),D(Rt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),D(Rt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),D(Rt,"UPSTREAM_PROPERTIES",[...Rt.MUTABLE_UPSTREAM_PROPERTIES,...Rt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Rt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),D(Rt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Rt,"DOWNSTREAM_PROPERTIES",[...Rt.MUTABLE_DOWNSTREAM_PROPERTIES,...Rt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Rt,"PROPERTIES",[...Rt.META_PROPERTIES,...Rt.UPSTREAM_PROPERTIES,...Rt.DOWNSTREAM_PROPERTIES]);let Za=Rt;function ZU(d){const u=nue(),i=d.toJSON();u.safeParse(i).success;const l=[];if(d.id==="exec-sequentially-argument-map-id"){const p=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(p.error)}return zt(d.errors,l)}const qye=Object.freeze(Object.defineProperty({__proto__:null,validate:ZU},Symbol.toStringTag,{value:"Module"}));var JU=(d=>(d.Declaration="declaration",d.DataTypeEntity="data-type-entity",d))(JU||{});const _t=class _t extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"index");D(this,"name",null);D(this,"codeName",null);D(this,"description",null);D(this,"type",f.InputMap);D(this,"defaultValue",null);D(this,"readsValue",null);D(this,"dataType",null);D(this,"declaration",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name||null,this.codeName=i.codeName||null,this.description=i.description||null}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l);let t=null;if(i.declaration){const w=W(i.declaration);t=a.get(w)}let y=null;if(i.readsValue){const w=W(i.readsValue);y=a.get(w)}const v={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,type:f.InputMap,index:(p.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:t,readsValue:y,defaultValue:null,parent:p},T=ee(v,a);return T.setParent(p,null),T}static validateGenerationTarget(i,a){var w;let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[...Xt,f.InputMap]}},a);l=t.modifiedData;const y=a.get(l.parent),v=l.declaration&&(a.get(l.declaration)||a.getBuiltIn(l.declaration)),T=((y==null?void 0:y.inputs)||[]).find(A=>{var V;return l.declaration&&((V=A.declaration)==null?void 0:V.id)===l.declaration});if(l.declaration?v?[f.Property,f.ArgumentDeclaration,f.ValueDescriptor].includes(v.type)?y&&v.type===f.ArgumentDeclaration&&![f.FunctionCall,f.Search,f.InternalCall].includes(y.type)?p.push(new Q({id:`${l.id}--${S.InvalidInputMapDeclaration}`,code:S.InvalidInputMapDeclaration,severity:Z.Error,message:`Entity of type '${f.InputMap}' with id '${l.id}' has a 'declaration' property pointing to an entity with type '${f.ArgumentDeclaration}' with id '${l.declaration}'.
|
|
160
160
|
The parent entity of type '${y.type}' with id '${y.id}' is not compatible with this type of declaration.
|
|
161
161
|
Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`,issue:null})):y&&v.type===f.Property&&!rt.includes(y.type)?p.push(new Q({id:`${l.id}--${S.InvalidInputMapDeclaration}`,code:S.InvalidInputMapDeclaration,severity:Z.Error,message:`Entity of type '${f.InputMap}' with id '${l.id}' has a 'declaration' property pointing to an entity with type '${f.Property}' with id '${l.declaration}'.
|
|
162
162
|
The parent entity of type '${y.type}' with id '${y.id}' is not compatible with this type of declaration.
|
|
@@ -185,7 +185,7 @@ ${Xb}`,issue:null})):p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSig
|
|
|
185
185
|
${Xb}`,issue:null}))}else if(w){const A=y.outputs.find(V=>V.declaration.id===l.declaration);A&&p.push(new Q({id:`${l.id}--${S.OutputOverwrite}`,code:S.OutputOverwrite,severity:Z.Error,message:`Entity of type '${f.OutputMap}' with id '${l.id}' cannot be added to the parent entity of type '${y.type}' with id '${y.id}'. The parent already has an output-map with id '${A.id}' that points to the same declaration.
|
|
186
186
|
Any value reads can be done with that output-map instead.
|
|
187
187
|
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 p.push(...t.errors,...vr(l)),{errors:p,modifiedData:l}}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
188
|
-
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t;return(a=(i=this.declaration)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"declaration"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,a,l,p,t;return(a=(i=this.declaration)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"declaration"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new gt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.declaration=this.declaration,i.defaultValue=this.defaultValue,i.writesValues=[...this.writesValues],i.dataType=this.dataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new gt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.declaration=y.declaration,this.defaultValue=y.defaultValue,this.writesValues=y.writesValues,this.dataType=y.dataType,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);if(p)this.setDeclaration(p);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 this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);if(y)this.setDeclaration(y),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parentRelationType===gl.Error?rt.includes(this.parent.type)||(this.parent.error=this):((y=this.declaration)==null?void 0:y.id)===Ee["value-descriptor"][Ol.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this,i),this.writesValues.forEach(v=>{v.setValueWriter(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this)}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDataType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),Cp.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=ee(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),this.parentRelationType=i.parentRelationType!==void 0?i.parentRelationType:this.parentRelationType,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await gt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await gt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await gt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await gt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await gt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await gt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.writesValues.forEach(v=>{l.push(v),v.readsValue=null}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),y.push(this.parent),this.parentRelationType===gl.Error?rt.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this,a)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}return this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),t.push(this.parent),this.parentRelationType===gl.Error?rt.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this,i),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.writesValues.flatMap(t=>t.toFlat(i)),...this.declaration?this.declaration.toFlat(i):[]])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.writesValues.flatMap(t=>t.toFlatIds(i)),...this.declaration?this.declaration.toFlatIds(i):[]])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),declaration:((l=this.declaration)==null?void 0:l.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w,A,V,N;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,writesValues:this.writesValues.map(j=>j.toJSONClone({...i,newId:null})),declaration:(w=this.declaration)!=null&&w.id&&this.project.getBuiltIn((A=this.declaration)==null?void 0:A.id)?(V=this.declaration)==null?void 0:V.toJSON(i.seenEntities):((N=this.declaration)==null?void 0:N.toJSONClone({...i,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:(t=this.declaration)==null?void 0:t.toReference(i),writesValues:this.writesValues.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(t=>t.toFlatJSON(i)),...this.declaration?this.declaration.toFlatJSON(i):[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,declaration:((i=this.declaration)==null?void 0:i.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(t=>t.toFlatGenerationTarget(i)),...this.declaration?this.declaration.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this}validate(){const i=WU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,N;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.id=v;const T=Kt(y,t);a?T.setParent(a,null):T.setParent(this.parent,null),p&&T.subscribe(),T.initChildren(i),i==null||i.add(T,K.Added);const w=(V=this.dataType)==null?void 0:V.clone(i,T,P.UUID.uuid(),p);T.setDataType(w||null,i);const A=(N=this.defaultValue)==null?void 0:N.clone(i,T,P.UUID.uuid(),p);return T.defaultValue=A||null,i==null||i.attemptAutoclose("clone-entity",this.id),T}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var l;return this.parent.type===f.Operation?this.parent.declaration.inferOutputMapDataType(this,i).self:((l=this.declaration)==null?void 0:l.getDataType(i))||null}};D(gt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(gt,"type",f.OutputMap),D(gt,"USER_MANAGED_PARENT_TYPES",[...oR]),D(gt,"PARENT_TYPES",[...gt.USER_MANAGED_PARENT_TYPES]),D(gt,"MUTABLE_BASE_PROPERTIES",[]),D(gt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(gt,"BASE_PROPERTIES",[...gt.MUTABLE_BASE_PROPERTIES,...gt.INMUTABLE_BASE_PROPERTIES]),D(gt,"MUTABLE_META_PROPERTIES",[...gt.MUTABLE_BASE_PROPERTIES,"index"]),D(gt,"INMUTABLE_META_PROPERTIES",[...gt.INMUTABLE_BASE_PROPERTIES]),D(gt,"META_PROPERTIES",[...gt.MUTABLE_META_PROPERTIES,...gt.INMUTABLE_META_PROPERTIES]),D(gt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(gt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),D(gt,"UPSTREAM_PROPERTIES",[...gt.MUTABLE_UPSTREAM_PROPERTIES,...gt.INMUTABLE_UPSTREAM_PROPERTIES]),D(gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),D(gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(gt,"DOWNSTREAM_PROPERTIES",[...gt.MUTABLE_DOWNSTREAM_PROPERTIES,...gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(gt,"PROPERTIES",[...gt.META_PROPERTIES,...gt.UPSTREAM_PROPERTIES,...gt.DOWNSTREAM_PROPERTIES]);let Qs=gt;class Wye extends Qs{constructor(i,a){super(i,a);D(this,"declaration");D(this,"parent");D(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}class Yye extends Qs{constructor(i,a){super(i,a);D(this,"declaration");D(this,"parent");D(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}function HU(d){var p;const u=Ece(),i=d.toJSON();u.safeParse(i).success,(p=d.dataType)==null||p.validate();const l=[];if(d.id==="company-dto-func-declaration-argument-dcl-id"){const t=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(t.error)}if(d.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const t=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(t.error)}return zt(d.errors,l)}const Hye=Object.freeze(Object.defineProperty({__proto__:null,validate:HU},Symbol.toStringTag,{value:"Module"}));var zU=(d=>(d.DataTypeEntity="data-type-entity",d.Implements="implements",d))(zU||{});const Dt=class Dt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"index");D(this,"required");D(this,"constant",!0);D(this,"type",f.ArgumentDeclaration);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"writesValues",[]);D(this,"implements",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name,this.description=i.description,this.required=i.required,this.constant=!0}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ArgumentDeclaration,name:"",codeName:null,description:"",index:0,required:!1,constant:!0,implements:null,dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l),t={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ArgumentDeclaration,index:p.inputs.length,defaultValue:null,codeName:i.codeName||null,description:i.description||null,required:i.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:p},y=ee(t,a);return y.setParent(p,null),y}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.FunctionDeclaration,f.Search,f.Condition]}},a);l=t.modifiedData;const y=Eb(l,a);if(l.parent){const v=a.get(W(l.parent));if(v&&Wt.includes(v.type)){const T=v.implements;if(T){const w=T.inputs.find(q=>q.name===l.name),A=T.inputs.filter(q=>!v.inputs.find(ie=>ie.type===f.ArgumentDeclaration&&ie.name===q.name)),V=v.inputs.filter(q=>q.type===f.ArgumentDeclaration),N=V.find(q=>q.name===l.name),j=V.length?`The parent entity already implements the following arguments: ${qe(V.map(q=>`'${q.id}' (${q.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",k=A.length?`The parent entity is still missing the following arguments in the implementation: ${qe(A.map(q=>`'${q.id}' (${q.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";w?N&&p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ArgumentDeclaration}' with id '${l.id}' should not exist in a parent entity of type '${v.type}' with id '${v.id}' that implements a ${f.ActionDescriptor} with fixed arguments.
|
|
188
|
+
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t;return(a=(i=this.declaration)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"declaration"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,a,l,p,t;return(a=(i=this.declaration)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"declaration"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new gt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.declaration=this.declaration,i.defaultValue=this.defaultValue,i.writesValues=[...this.writesValues],i.dataType=this.dataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new gt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.declaration=y.declaration,this.defaultValue=y.defaultValue,this.writesValues=y.writesValues,this.dataType=y.dataType,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);if(p)this.setDeclaration(p);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 this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);if(y)this.setDeclaration(y),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parentRelationType===gl.Error?rt.includes(this.parent.type)||(this.parent.error=this):((y=this.declaration)==null?void 0:y.id)===Ee["value-descriptor"][Ol.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this,i),this.writesValues.forEach(v=>{v.setValueWriter(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this)}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDataType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),Cp.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=ee(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),this.parentRelationType=i.parentRelationType!==void 0?i.parentRelationType:this.parentRelationType,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await gt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await gt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await gt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await gt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await gt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await gt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.writesValues.forEach(v=>{l.push(v),v.readsValue=null}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),y.push(this.parent),this.parentRelationType===gl.Error?rt.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this,a)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}return this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),t.push(this.parent),this.parentRelationType===gl.Error?rt.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this,i),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.writesValues.flatMap(t=>t.toFlat(i)),...this.declaration?this.declaration.toFlat(i):[]])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.writesValues.flatMap(t=>t.toFlatIds(i)),...this.declaration?this.declaration.toFlatIds(i):[]])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),declaration:((l=this.declaration)==null?void 0:l.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w,A,V,N;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,writesValues:this.writesValues.map(j=>j.toJSONClone({...i,newId:null})),declaration:(w=this.declaration)!=null&&w.id&&this.project.getBuiltIn((A=this.declaration)==null?void 0:A.id)?(V=this.declaration)==null?void 0:V.toJSON(i.seenEntities):((N=this.declaration)==null?void 0:N.toJSONClone({...i,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:(t=this.declaration)==null?void 0:t.toReference(i),writesValues:this.writesValues.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(t=>t.toFlatJSON(i)),...this.declaration?this.declaration.toFlatJSON(i):[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,declaration:((i=this.declaration)==null?void 0:i.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(t=>t.toFlatGenerationTarget(i)),...this.declaration?this.declaration.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this}validate(){const i=WU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,N;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.id=v;const T=Kt(y,t);a?T.setParent(a,null):T.setParent(this.parent,null),p&&T.subscribe(),T.initChildren(i),i==null||i.add(T,K.Added);const w=(V=this.dataType)==null?void 0:V.clone(i,T,P.UUID.uuid(),p);T.setDataType(w||null,i);const A=(N=this.defaultValue)==null?void 0:N.clone(i,T,P.UUID.uuid(),p);return T.defaultValue=A||null,i==null||i.attemptAutoclose("clone-entity",this.id),T}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var l;return this.parent.type===f.Operation?this.parent.declaration.inferOutputMapDataType(this,i).self:((l=this.declaration)==null?void 0:l.getDataType(i))||null}};D(gt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(gt,"type",f.OutputMap),D(gt,"USER_MANAGED_PARENT_TYPES",[...oR]),D(gt,"PARENT_TYPES",[...gt.USER_MANAGED_PARENT_TYPES]),D(gt,"MUTABLE_BASE_PROPERTIES",[]),D(gt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(gt,"BASE_PROPERTIES",[...gt.MUTABLE_BASE_PROPERTIES,...gt.INMUTABLE_BASE_PROPERTIES]),D(gt,"MUTABLE_META_PROPERTIES",[...gt.MUTABLE_BASE_PROPERTIES,"index"]),D(gt,"INMUTABLE_META_PROPERTIES",[...gt.INMUTABLE_BASE_PROPERTIES]),D(gt,"META_PROPERTIES",[...gt.MUTABLE_META_PROPERTIES,...gt.INMUTABLE_META_PROPERTIES]),D(gt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(gt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),D(gt,"UPSTREAM_PROPERTIES",[...gt.MUTABLE_UPSTREAM_PROPERTIES,...gt.INMUTABLE_UPSTREAM_PROPERTIES]),D(gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),D(gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(gt,"DOWNSTREAM_PROPERTIES",[...gt.MUTABLE_DOWNSTREAM_PROPERTIES,...gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(gt,"PROPERTIES",[...gt.META_PROPERTIES,...gt.UPSTREAM_PROPERTIES,...gt.DOWNSTREAM_PROPERTIES]);let Qs=gt;class Wye extends Qs{constructor(i,a){super(i,a);D(this,"declaration");D(this,"parent");D(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}class Yye extends Qs{constructor(i,a){super(i,a);D(this,"declaration");D(this,"parent");D(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}function HU(d){var p;const u=Ece(),i=d.toJSON();u.safeParse(i).success,(p=d.dataType)==null||p.validate();const l=[];if(d.id==="company-dto-func-declaration-argument-dcl-id"){const t=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(t.error)}if(d.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const t=nt({id:`${d.id}--${se.PropertyImplementsNonAbstact}`,message:`Property "${re(d,d.project)}" with id "${d.id}" implements a non-abstract property "${re(d,d.project)}" with id "${d.id}".`,issue:null,severity:Z.Error,code:se.PropertyImplementsNonAbstact,entity:d});l.push(t.error)}return zt(d.errors,l)}const Hye=Object.freeze(Object.defineProperty({__proto__:null,validate:HU},Symbol.toStringTag,{value:"Module"}));var zU=(d=>(d.DataTypeEntity="data-type-entity",d.Implements="implements",d))(zU||{});const Dt=class Dt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"index");D(this,"required");D(this,"constant",!0);D(this,"type",f.ArgumentDeclaration);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"writesValues",[]);D(this,"implements",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);D(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name,this.description=i.description,this.codeName=i.codeName,this.required=i.required,this.constant=!0}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ArgumentDeclaration,name:"",codeName:null,description:"",index:0,required:!1,constant:!0,implements:null,dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l),t={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ArgumentDeclaration,index:p.inputs.length,defaultValue:null,codeName:i.codeName||null,description:i.description||null,required:i.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:p},y=ee(t,a);return y.setParent(p,null),y}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.FunctionDeclaration,f.Search,f.Condition]}},a);l=t.modifiedData;const y=Eb(l,a);if(l.parent){const v=a.get(W(l.parent));if(v&&Wt.includes(v.type)){const T=v.implements;if(T){const w=T.inputs.find(q=>q.name===l.name),A=T.inputs.filter(q=>!v.inputs.find(ie=>ie.type===f.ArgumentDeclaration&&ie.name===q.name)),V=v.inputs.filter(q=>q.type===f.ArgumentDeclaration),N=V.find(q=>q.name===l.name),j=V.length?`The parent entity already implements the following arguments: ${qe(V.map(q=>`'${q.id}' (${q.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",k=A.length?`The parent entity is still missing the following arguments in the implementation: ${qe(A.map(q=>`'${q.id}' (${q.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";w?N&&p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ArgumentDeclaration}' with id '${l.id}' should not exist in a parent entity of type '${v.type}' with id '${v.id}' that implements a ${f.ActionDescriptor} with fixed arguments.
|
|
189
189
|
Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
|
|
190
190
|
${j}
|
|
191
191
|
${k}`,issue:null})):p.push(new Q({id:`${l.id}--${oe.NoOverlapWithImplementedSignature}`,code:oe.NoOverlapWithImplementedSignature,severity:Z.Error,message:`Entity of type '${f.ArgumentDeclaration}' with id '${l.id}' should not exist in a parent entity of type '${v.type}' with id '${v.id}' that implements a ${f.ActionDescriptor} with fixed arguments.
|
|
@@ -195,7 +195,7 @@ ${k}`,issue:null}))}}}return p.push(...t.errors,...y,...vr(l)),{errors:p,modifie
|
|
|
195
195
|
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return a==="implements"&&(this.setImplements(null,l),p.push(this)),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return a==="implements"&&(this.setImplements(i,l),p.push(this)),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,t;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,a,l,p,t;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Dt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.implements=this.implements,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.writesValues=[...this.writesValues],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Dt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.implements=y.implements,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.writesValues=y.writesValues,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=W(i.implements),p=this.project.get(l);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const t=W(this.initialData.implements),y=this.project.get(t);y&&(this.setImplements(y,null),i.push(y))}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent.addInputDeclaration(this,i),t.push(this.parent),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this)}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ee(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=ee(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),this.initialData.implements){const a=ee(this.initialData.implements,this.project);this.setImplements(a,null)}return Cp.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.required=i.required!==void 0?i.required:this.required,this.constant=!0,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Dt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Dt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Dt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Dt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Dt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Dt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.removeInputDeclaration(this,i),t.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.defaultValue){const{updated:v,removed:T}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...T)}if(this.writesValues.forEach(v=>{l.push(v),v.readsValue=null}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v.updated),p.push(...v.removed)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),t.push(this.parent),this.parent.addInputDeclaration(this,i),this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...this.writesValues.flatMap(t=>t.toFlat(i)),...((p=this.dataType)==null?void 0:p.toFlat(i))||[]])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...this.writesValues.flatMap(t=>t.toFlatIds(i)),...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,required:this.required,constant:!0,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,codeName:this.codeName,description:this.description,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,writesValues:this.writesValues.map(t=>t.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v,T,w,A;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,codeName:this.codeName,description:this.description,required:this.required,constant:!0,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null,writesValues:this.writesValues.map(V=>V.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),implements:((t=this.implements)==null?void 0:t.toReference(i))||null,dataType:((y=this.dataType)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...this.writesValues.flatMap(t=>t.toFlatJSON(i)),...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,codeName:this.codeName,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(t=>t.toFlatGenerationTarget(i)),...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){const i=HU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,N;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.dataType=null,y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const T=Kt(y,t);a?T.setParent(a,null):T.setParent(this.parent,null),p&&T.subscribe(),T.initChildren(i),i==null||i.add(T,K.Added);const w=(V=this.dataType)==null?void 0:V.clone(i,T,P.UUID.uuid(),p);T.setDataType(w||null,i);const A=(N=this.defaultValue)==null?void 0:N.clone(i,T,P.UUID.uuid(),p);return T.defaultValue=A||null,i==null||i.attemptAutoclose("clone-entity",this.id),T}getDataType(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}};D(Dt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Dt,"type",f.ArgumentDeclaration),D(Dt,"USER_MANAGED_PARENT_TYPES",[...Wt]),D(Dt,"PARENT_TYPES",[...Dt.USER_MANAGED_PARENT_TYPES]),D(Dt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","required","constant"]),D(Dt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Dt,"BASE_PROPERTIES",[...Dt.MUTABLE_BASE_PROPERTIES,...Dt.INMUTABLE_BASE_PROPERTIES]),D(Dt,"MUTABLE_META_PROPERTIES",[...Dt.MUTABLE_BASE_PROPERTIES,"index"]),D(Dt,"INMUTABLE_META_PROPERTIES",[...Dt.INMUTABLE_BASE_PROPERTIES]),D(Dt,"META_PROPERTIES",[...Dt.MUTABLE_META_PROPERTIES,...Dt.INMUTABLE_META_PROPERTIES]),D(Dt,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(Dt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),D(Dt,"UPSTREAM_PROPERTIES",[...Dt.MUTABLE_UPSTREAM_PROPERTIES,...Dt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Dt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),D(Dt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Dt,"DOWNSTREAM_PROPERTIES",[...Dt.MUTABLE_DOWNSTREAM_PROPERTIES,...Dt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Dt,"PROPERTIES",[...Dt.META_PROPERTIES,...Dt.UPSTREAM_PROPERTIES,...Dt.DOWNSTREAM_PROPERTIES]);let pa=Dt;function XU(d){var p;const u=Lde(),i=d.toJSON();u.safeParse(i).success,d.outputs.forEach(t=>t.validate()),(p=d.throws)==null||p.validate();const l=[];return zt(d.errors,l)}const zye=Object.freeze(Object.defineProperty({__proto__:null,validate:XU},Symbol.toStringTag,{value:"Module"}));var QU=(d=>(d.Parent="parent",d))(QU||{});const Bt=class Bt extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"x");D(this,"y");D(this,"type",f.BreakStatement);D(this,"outputs",[]);D(this,"calledBySuccess",[]);D(this,"calledByError",[]);D(this,"calledByEntry",[]);D(this,"throws",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(i,a){const l=W(i.parent),p=a.get(l),t=i.calledByEntry.map(A=>{const V=W(A);return a.get(V)}),y=i.calledBySuccess.map(A=>{const V=W(A);return a.get(V)}),v=i.calledByError.map(A=>{const V=W(A);return a.get(V)}),T={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:y,calledByError:v,calledByEntry:t,throws:null,parent:p},w=ee(T,a);return w.setParent(p,null),w}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.Loop]}},a);return l=t.modifiedData,p.push(...t.errors,...vr(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
196
196
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
197
197
|
You shouldn't have to manually update a 'parent' property.
|
|
198
|
-
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Bt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.outputs=[...this.outputs],i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Bt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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(t=>{const y=W(t),v=this.project.get(y);v&&(this.addEntryCaller(v,null),i.push(v))}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&(this.addSuccessCaller(v,null),i.push(v))}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&(this.addErrorCaller(v,null),i.push(v))}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.parent.syncTerminationStatements(i),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],p=[],t=[];return this.calledByEntry.forEach(T=>{T.addCall(this,i),a.push(T)}),this.calledBySuccess.forEach(T=>{T.addSuccessCall(this,i),a.push(T)}),this.calledByError.forEach(T=>{T.addErrorCall(this,i),a.push(T)}),this.parent.addBreakStatement(this),t.push(this.parent),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.breakStatements.forEach(T=>{T.id!==this.id&&(t.push(T),i==null||i.add(T,K.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(T=>{T.id!==this.id&&(t.push(T),i==null||i.add(T,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(l=>l.id===i.id)||(this.outputs.push(i),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(l=>l.id===i.id)&&(this.outputs=this.outputs.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-output-declaration",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=ee(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Bt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Bt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Bt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Bt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Bt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Bt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.removeBreakStatement(this),t.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v,T;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(w=>{const{updated:A,removed:V,added:N}=w.entity.onDetachedDependencyRemoved(this,w.field,a);l.push(...A),p.push(...V),t.push(...N)}),this.outputs.forEach(w=>{const{updated:A,removed:V}=w.remove({ignoreUpstream:!0},a);l.push(...A),p.push(...V)}),this.throws){const{updated:w,removed:A}=this.throws.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}if(!i){const w=this.removeFromParent(a);t.push(...w.added),l.push(...w.updated),p.push(...w.removed),y.push(...w.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(v=this.parent)==null||v.breakStatements.forEach(w=>{w.id!==this.id&&(y.push(w),a==null||a.add(w,K.Affected))}),(T=this.parent)==null||T.continueStatements.forEach(w=>{w.id!==this.id&&(y.push(w),a==null||a.add(w,K.Affected))}),a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[]])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),parent:((a=this.parent)==null?void 0:a.toReference())||null,throws:((l=this.throws)==null?void 0:l.toJSON(i))||null})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),parent:((T=this.parent)==null?void 0:T.toReference({seenEntityMaps:i.seenEntityMaps}))||null,throws:((w=this.throws)==null?void 0:w.toJSONClone({...i,newId:null}))||null})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),throws:((p=this.throws)==null?void 0:p.toReference(i))||null,parent:((t=this.parent)==null?void 0:t.toReference(i))||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.throws?this.throws.toFlatJSON(i):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],this.outputs.forEach(a=>a.clearErrors()),(i=this.throws)==null||i.clearErrors(),this}validate(){const i=XU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(a=>a.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var N;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.outputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(N=this.outputs)==null?void 0:N.map((j,k)=>j.clone(i,A,w+"-return-declaration-"+k+"-id",p));return A.outputs=V,this.throws&&(A.throws=this.throws.clone(i,A,w+"-throws-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}};D(Bt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Bt,"type",f.BreakStatement),D(Bt,"USER_MANAGED_PARENT_TYPES",[f.Loop]),D(Bt,"PARENT_TYPES",[...Bt.USER_MANAGED_PARENT_TYPES]),D(Bt,"MUTABLE_BASE_PROPERTIES",[]),D(Bt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Bt,"BASE_PROPERTIES",[...Bt.MUTABLE_BASE_PROPERTIES,...Bt.INMUTABLE_BASE_PROPERTIES]),D(Bt,"MUTABLE_META_PROPERTIES",["x","y"]),D(Bt,"INMUTABLE_META_PROPERTIES",[...Bt.INMUTABLE_BASE_PROPERTIES]),D(Bt,"META_PROPERTIES",[...Bt.MUTABLE_META_PROPERTIES,...Bt.INMUTABLE_META_PROPERTIES]),D(Bt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),D(Bt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),D(Bt,"UPSTREAM_PROPERTIES",[...Bt.MUTABLE_UPSTREAM_PROPERTIES,...Bt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Bt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),D(Bt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Bt,"DOWNSTREAM_PROPERTIES",[...Bt.MUTABLE_DOWNSTREAM_PROPERTIES,...Bt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Bt,"PROPERTIES",[...Bt.META_PROPERTIES,...Bt.UPSTREAM_PROPERTIES,...Bt.DOWNSTREAM_PROPERTIES]);let Ja=Bt;function ej(d){var p;const u=Xle(),i=d.toJSON();u.safeParse(i).success,(p=d.dataType)==null||p.validate();const l=[];return zt(d.errors,l)}const Xye=Object.freeze(Object.defineProperty({__proto__:null,validate:ej},Symbol.toStringTag,{value:"Module"}));var tj=(d=>(d.DataTypeEntity="data-type-entity",d))(tj||{});const Ot=class Ot extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"index");D(this,"required");D(this,"parentRelationType");D(this,"type",f.ValueDescriptor);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.index=i.index,this.required=i.required,this.parentRelationType=i.parentRelationType}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ValueDescriptor,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,parentRelationType:ue.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=i.parent?W(i.parent):null,p=l?a.get(l):null,t=i.parentRelationType===ue.FixedArguments?p==null?void 0:p.inputs.length:p==null?void 0:p.outputs.length,y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ValueDescriptor,index:t||0,codeName:i.codeName,description:i.description,required:i.required,defaultValue:null,parentRelationType:i.parentRelationType,dataType:null,parent:p},v=ee(y,a);return p&&v.setParent(p,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.ActionDescriptor]}},a);l=t.modifiedData,p.push(...t.errors,...vr(l));const y=l.parent&&a.get(l.parent),v=y&&Qa(y);return v&&v.type===f.ActionDescriptor&&p.push(new Q({id:`${i.id}--${S.BuiltInEntityParent}`,code:S.BuiltInEntityParent,severity:Z.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent that is a built-in entity "${v.name}" of type '${v.type}' with id '${v.id}'.
|
|
198
|
+
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Bt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.outputs=[...this.outputs],i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Bt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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(t=>{const y=W(t),v=this.project.get(y);v&&(this.addEntryCaller(v,null),i.push(v))}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&(this.addSuccessCaller(v,null),i.push(v))}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&(this.addErrorCaller(v,null),i.push(v))}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.parent.syncTerminationStatements(i),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],p=[],t=[];return this.calledByEntry.forEach(T=>{T.addCall(this,i),a.push(T)}),this.calledBySuccess.forEach(T=>{T.addSuccessCall(this,i),a.push(T)}),this.calledByError.forEach(T=>{T.addErrorCall(this,i),a.push(T)}),this.parent.addBreakStatement(this),t.push(this.parent),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.breakStatements.forEach(T=>{T.id!==this.id&&(t.push(T),i==null||i.add(T,K.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(T=>{T.id!==this.id&&(t.push(T),i==null||i.add(T,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(l=>l.id===i.id)||(this.outputs.push(i),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(l=>l.id===i.id)&&(this.outputs=this.outputs.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-output-declaration",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=ee(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Bt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Bt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Bt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Bt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Bt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Bt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.removeBreakStatement(this),t.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v,T;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(w=>{const{updated:A,removed:V,added:N}=w.entity.onDetachedDependencyRemoved(this,w.field,a);l.push(...A),p.push(...V),t.push(...N)}),this.outputs.forEach(w=>{const{updated:A,removed:V}=w.remove({ignoreUpstream:!0},a);l.push(...A),p.push(...V)}),this.throws){const{updated:w,removed:A}=this.throws.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}if(!i){const w=this.removeFromParent(a);t.push(...w.added),l.push(...w.updated),p.push(...w.removed),y.push(...w.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(v=this.parent)==null||v.breakStatements.forEach(w=>{w.id!==this.id&&(y.push(w),a==null||a.add(w,K.Affected))}),(T=this.parent)==null||T.continueStatements.forEach(w=>{w.id!==this.id&&(y.push(w),a==null||a.add(w,K.Affected))}),a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[]])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),parent:((a=this.parent)==null?void 0:a.toReference())||null,throws:((l=this.throws)==null?void 0:l.toJSON(i))||null})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),parent:((T=this.parent)==null?void 0:T.toReference({seenEntityMaps:i.seenEntityMaps}))||null,throws:((w=this.throws)==null?void 0:w.toJSONClone({...i,newId:null}))||null})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l,p,t;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),throws:((p=this.throws)==null?void 0:p.toReference(i))||null,parent:((t=this.parent)==null?void 0:t.toReference(i))||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.throws?this.throws.toFlatJSON(i):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],this.outputs.forEach(a=>a.clearErrors()),(i=this.throws)==null||i.clearErrors(),this}validate(){const i=XU(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(a=>a.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var N;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.outputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(N=this.outputs)==null?void 0:N.map((j,k)=>j.clone(i,A,w+"-return-declaration-"+k+"-id",p));return A.outputs=V,this.throws&&(A.throws=this.throws.clone(i,A,w+"-throws-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}};D(Bt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Bt,"type",f.BreakStatement),D(Bt,"USER_MANAGED_PARENT_TYPES",[f.Loop]),D(Bt,"PARENT_TYPES",[...Bt.USER_MANAGED_PARENT_TYPES]),D(Bt,"MUTABLE_BASE_PROPERTIES",[]),D(Bt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Bt,"BASE_PROPERTIES",[...Bt.MUTABLE_BASE_PROPERTIES,...Bt.INMUTABLE_BASE_PROPERTIES]),D(Bt,"MUTABLE_META_PROPERTIES",["x","y"]),D(Bt,"INMUTABLE_META_PROPERTIES",[...Bt.INMUTABLE_BASE_PROPERTIES]),D(Bt,"META_PROPERTIES",[...Bt.MUTABLE_META_PROPERTIES,...Bt.INMUTABLE_META_PROPERTIES]),D(Bt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),D(Bt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),D(Bt,"UPSTREAM_PROPERTIES",[...Bt.MUTABLE_UPSTREAM_PROPERTIES,...Bt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Bt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),D(Bt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Bt,"DOWNSTREAM_PROPERTIES",[...Bt.MUTABLE_DOWNSTREAM_PROPERTIES,...Bt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Bt,"PROPERTIES",[...Bt.META_PROPERTIES,...Bt.UPSTREAM_PROPERTIES,...Bt.DOWNSTREAM_PROPERTIES]);let Ja=Bt;function ej(d){var p;const u=Xle(),i=d.toJSON();u.safeParse(i).success,(p=d.dataType)==null||p.validate();const l=[];return zt(d.errors,l)}const Xye=Object.freeze(Object.defineProperty({__proto__:null,validate:ej},Symbol.toStringTag,{value:"Module"}));var tj=(d=>(d.DataTypeEntity="data-type-entity",d))(tj||{});const Ot=class Ot extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"index");D(this,"required");D(this,"parentRelationType");D(this,"type",f.ValueDescriptor);D(this,"defaultValue",null);D(this,"dataType",null);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.index=i.index,this.codeName=i.codeName,this.required=i.required,this.parentRelationType=i.parentRelationType}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ValueDescriptor,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,parentRelationType:ue.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=i.parent?W(i.parent):null,p=l?a.get(l):null,t=i.parentRelationType===ue.FixedArguments?p==null?void 0:p.inputs.length:p==null?void 0:p.outputs.length,y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.ValueDescriptor,index:t||0,codeName:i.codeName,description:i.description,required:i.required,defaultValue:null,parentRelationType:i.parentRelationType,dataType:null,parent:p},v=ee(y,a);return p&&v.setParent(p,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=Mr(l,{parent:{list:!1,types:[f.ActionDescriptor]}},a);l=t.modifiedData,p.push(...t.errors,...vr(l));const y=l.parent&&a.get(l.parent),v=y&&Qa(y);return v&&v.type===f.ActionDescriptor&&p.push(new Q({id:`${i.id}--${S.BuiltInEntityParent}`,code:S.BuiltInEntityParent,severity:Z.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent that is a built-in entity "${v.name}" of type '${v.type}' with id '${v.id}'.
|
|
199
199
|
You can't modify system entities that are built-in.`,issue:null})),y&&y.type===f.ActionDescriptor&&(!l.parentRelationType||!(l.parentRelationType===ue.FixedArguments||l.parentRelationType===ue.FixedReturns||l.parentRelationType===ue.ReturnedError||l.parentRelationType===ue.DynamicArgument||l.parentRelationType===ue.DynamicReturn)?p.push(new Q({id:`${i.id}--${S.InvalidParentRelationType}`,code:S.InvalidParentRelationType,severity:Z.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either '${ue.FixedArguments}', '${ue.FixedReturns}', or '${ue.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`,issue:null})):l.parentRelationType===ue.ReturnedError&&y.error&&p.push(new Q({id:`${i.id}--${S.NewEntityWouldOverriteExisting}`,code:S.NewEntityWouldOverriteExisting,severity:Z.Error,message:`The entity with id '${i.id}' and type '${i.type}', is being added as an error value-descriptor to an entity of type 'action-descriptor' with id '${y.id}', which already has an error value descriptor with id '${y.error.id}'.
|
|
200
200
|
An action descriptor can only have one error value descriptor child.
|
|
201
201
|
Either remove the existing error value descriptor or update it with the 'update' action.
|
|
@@ -397,7 +397,7 @@ All global 'function-declaration' entity ids are:
|
|
|
397
397
|
The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;p.push(new Q({id:`${l.id}--${S.InvalidReference}`,code:S.InvalidReference,severity:Z.Error,message:`Entity of type "${f.FunctionCall}" with id "${l.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
|
|
398
398
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${v}`,issue:null}))}return{errors:p,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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.
|
|
399
399
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
400
|
-
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Mt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.process=this.process,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Mt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:w,added:A,removed:V}=this.syncOutputs(i);return a.push(...y,...w),l.push(...v,...A),p.push(...T,...V),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=ee(this.initialData.declaration,this.project);this.declaration=a}else{const a=W(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.process&&(this.process=ee(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.initialData.error&&(this.error=ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Mt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Mt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Mt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Mt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Mt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Mt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.process){const{updated:T,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:T,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.process?this.process.toFlatJSON(i):[],...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.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(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=hj(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(j=this.inputs)==null?void 0:j.map((q,Y)=>q.clone(i,A,w+"-input-map-"+Y+"-id",p));A.inputs=V;const N=(k=this.outputs)==null?void 0:k.map((q,Y)=>q.clone(i,A,w+"-output-map-"+Y+"-id",p));return A.outputs=N,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],t=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,T)=>{const w=this.outputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>!this.inputs.find(V=>V.declaration.id===A.id));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i),l.push(N)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],t=[],y=[];this.outputs=this.initialData.outputs.reduce((V,N)=>{if(N.type===f.GenericReference){const k=_i(N,this.project);return k?[...V,k]:V}const j=ee(N,this.project);return y.push(j.index),j.setParent(this,null),j.initChildren(i),[...V,j]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter(V=>!this.outputs.find(N=>N.declaration.id===V.id));this.outputs.sort((V,N)=>V.index-N.index),v.forEach((V,N)=>{this.outputs.forEach(Y=>{Y.index>=V.index&&Y.index++});const j=y.includes(V.index)?this.outputs.length-1+N:V.index,k={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:V.toJSON(),defaultValue:null,writesValues:[],index:j,parent:this.toReference()},q=ee(k,this.project);q.setParent(this,i),q.initChildren(i),i==null||i.add(q,K.Added),q.addSelfToProject(i)}),this.outputs.sort((V,N)=>V.index-N.index);const{updated:T,added:w,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...w),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Mt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Mt,"type",f.FunctionCall),D(Mt,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(Mt,"PARENT_TYPES",[...Mt.USER_MANAGED_PARENT_TYPES]),D(Mt,"MUTABLE_BASE_PROPERTIES",[]),D(Mt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Mt,"BASE_PROPERTIES",[...Mt.MUTABLE_BASE_PROPERTIES,...Mt.INMUTABLE_BASE_PROPERTIES]),D(Mt,"MUTABLE_META_PROPERTIES",["x","y"]),D(Mt,"INMUTABLE_META_PROPERTIES",[...Mt.INMUTABLE_BASE_PROPERTIES]),D(Mt,"META_PROPERTIES",[...Mt.MUTABLE_META_PROPERTIES,...Mt.INMUTABLE_META_PROPERTIES]),D(Mt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),D(Mt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),D(Mt,"UPSTREAM_PROPERTIES",[...Mt.MUTABLE_UPSTREAM_PROPERTIES,...Mt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Mt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),D(Mt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Mt,"DOWNSTREAM_PROPERTIES",[...Mt.MUTABLE_DOWNSTREAM_PROPERTIES,...Mt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Mt,"PROPERTIES",[...Mt.META_PROPERTIES,...Mt.UPSTREAM_PROPERTIES,...Mt.DOWNSTREAM_PROPERTIES]);let za=Mt;function sA(d){return d&&typeof d.then=="function"}function pme(d){const u=new ha(d[0]),i=d.map(l=>l.id),a={};return d.forEach(l=>{a[l.id]=l}),u.order=i,u.flatRecord=a,u.orderEntities(),u.order.map(l=>u.flatRecord[l])}class ha{constructor(u){D(this,"order",[]);D(this,"flatRecord",{});D(this,"allBuiltInEntityIds",Ps());D(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Ps()),a=R(he(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const p of a)this.flatRecord[p.id]=p,l.add(p.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=Rd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),p=this.order.indexOf(u.id);if(l>p)return this.order.splice(p,1),this.order.splice(l,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let i=0;i<this.order.length;i++){const a=this.order[i],l=this.flatRecord[a];if(l||console.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(l)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,i){const{upstream:a}=Rd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([p,t])=>{Object.keys(a).includes(p)&&(l[p]=t)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(t=>Object.keys(Rd(this.flatRecord[t],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(l).forEach(t=>{t===u&&(p[t]=this.onGoingVisits[i][t])}),p}async settlePromises(u,i){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(l=>{delete this.onGoingVisits[i][l]})}visit(u){const i=this.order;for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const i=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const p=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const t=u(this.flatRecord[l],this.flatRecord);sA(t)&&(this.onGoingVisits[a][l]=t)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const i=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const p=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const t=u(this.flatRecord[l],this.flatRecord);sA(t)&&(this.onGoingVisits[a][l]=t)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function mj(d,u){switch(d.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(T=>T.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const T=v.properties.find(V=>V.implements&&V.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=T==null?void 0:T.getDefaultValue();return(w==null?void 0:w.value)===!0});if(!a&&i.length){const T=i[0].properties.find(A=>A.implements&&A.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=T==null?void 0:T.defaultValue;if(w)w.metaSync({value:!0},u);else if(T!=null&&T.dataType){const A={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:X.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},V=ee(A,d.project);return V.setParent(T,u),V.initChildren(u),u==null||u.add(V,K.Added),V.addSelfToProject(u),{newEntities:[V]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=Fy(l,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const t=p.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=t==null?void 0:t.defaultValue;if(y)y.metaSync({value:!0},u);else if(t!=null&&t.dataType){const v={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:X.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:t==null?void 0:t.toReference()},T=ee(v,d.project);T.setParent(t,u),T.initChildren(u),u==null||u.add(T,K.Added),T.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function vj(d,u){const i=[],a=[],l=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const T=d.project.entities.filter(N=>N.implements.find(j=>j.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let w=T.find(N=>!!N.properties.find(j=>{var k;return j.implements&&j.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((k=j.getDefaultValue())==null?void 0:k.value)===!0}));if(!w&&T.length)w=T[0];else if(!w&&!T.length){w=d.project.getBuiltIn(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const j=w.properties.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=j==null?void 0:j.defaultValue)==null||v.metaSync({value:!0},u),a.push(w)}const A=d.properties.find(N=>N.implements&&N.implements.id===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),V=A==null?void 0:A.defaultValue;if(A&&!V){const N={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:X.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(w==null?void 0:w.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},j=ee(N,d.project);j.hydrateAncestors(),j.setParent(A,u),j.addSelfToProject(u),j.initChildren(u),u==null||u.add(j,K.Added),a.push(j);return}else V&&!V.valueAsTypeSingle&&V.setValueAsTypeSingle(w||null,u);return}}}),{self:d,updated:R(i),added:R(a),removed:R(l),affected:R(p)}}function Fy(d,u,i,a){const l=a||P.UUID.uuid(),p=P.UUID.uuid(),t={id:l,version:p,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};mj(d,i);const y=ee(t,d.project);return y.hydrateAncestors(),i==null||i.add(y,K.Added),y.addSelfToProject(i),y.addImplementation(d),y.setParent(d.project,i),y.initChildren(i),vj(y,i),y}function nA(d,u){return u.entities.find(l=>{const p=l.properties,t=p.map(A=>A.name),y=d.every(A=>t.includes(A)),v=t.filter(A=>!d.includes(A)),T=p.every(A=>!v.includes(A.name)||!A.required);return y&&T})||null}function Ej(d,u,i,a=Zr.OrDataTypeGroup){const l=[],p=[],t=[],y=[],T={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},w=ee(T,d.project);return p.push(w),w.setParent(u,i),w.initChildren(i),i==null||i.add(w,K.Added),w.setEntity(d,i),w.addSelfToProject(i),{updated:R(l),added:R(p),removed:R(t),affected:R(y),self:w}}function aA(d,u,i,a,l){var T,w,A,V,N,j,k,q;const p=[],t=[],y=[],v=[];switch(typeof d){case"string":let Y=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(Y=!0),Y){const te=u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Date].id);u.setEntity(te,a);break}else{const te=u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.String].id);u.setEntity(te,a);break}case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const te=d.slice(0,5).filter(ne=>ne!==void 0);if(te.every(ne=>typeof ne==typeof te[0])&&(typeof te[0]!="object"||te[0]===null))switch(typeof te[0]){case"string":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Null].id),a);break}else{const ne=[];let me=!1;te.forEach(ae=>{var ce,H,de,ve;if(Array.isArray(ae)&&(me=!0),typeof ae=="object"&&!Array.isArray(ae)&&ae!==null){const Pe=Gy(ae,u.project,{...i,id:P.UUID.uuid()},a,l);Pe.hasCreated&&ne.push((ce=Pe.changeSet)==null?void 0:ce.self),p.push(...(H=Pe.changeSet)==null?void 0:H.updated),t.push(...(de=Pe.changeSet)==null?void 0:de.added),y.push(...(ve=Pe.changeSet)==null?void 0:ve.removed)}});const J=R(ne);if(!J.length&&!me){te.forEach(ae=>{const ce={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.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:Zr.OrDataTypeGroup,parent:u.toReference()},H=ee(ce,u.project);switch(H.setParent(u,a),H.initChildren(a),a==null||a.add(H,K.Added),H.addSelfToProject(a),typeof ae){case"string":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.String].id),a);break;case"number":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Number].id),a);break;case"boolean":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Boolean].id),a);break;case"object":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Null].id),a);break}});break}else J.length===1&&!me?u.setEntity(J[0],a):te.forEach(ae=>{if(typeof ae=="object"&&!Array.isArray(ae)&&ae!==null){const ce=nA(Object.keys(ae),u.project);if(ce){const H=Ej(ce||J[0],u,a,Zr.OrDataTypeGroup);p.push(...H.updated),t.push(...H.added),y.push(...H.removed)}}else{const ce={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(ae),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Zr.OrDataTypeGroup,parent:u.toReference()},H=ee(ce,u.project);H.setParent(u,a),H.initChildren(a),a==null||a.add(H,K.Added),H.addSelfToProject(a);const de=aA(ae,H,{...i,id:P.UUID.uuid()},a,l);p.push(...de.updated),t.push(...de.added),y.push(...de.removed)}})}}else{const te=Gy(d[0],u.project,{...i},a,l);u.setEntity((T=te.changeSet)==null?void 0:T.self,a),p.push(...(w=te.changeSet)==null?void 0:w.updated),t.push(...(A=te.changeSet)==null?void 0:A.added),y.push(...(V=te.changeSet)==null?void 0:V.removed);break}else{const te=Gy(d,u.project,{...i},a,l);u.setEntity((N=te.changeSet)==null?void 0:N.self,a),p.push(...(j=te.changeSet)==null?void 0:j.updated),t.push(...(k=te.changeSet)==null?void 0:k.added),y.push(...(q=te.changeSet)==null?void 0:q.removed);break}}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:u}}function Gy(d,u,i,a,l){const p=[],t=[],y=[],v=[],T=Object.keys(d),w=nA(T,u);if(w)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:w}};const A=l?i.name+" of "+l.name:i.name,N={id:i.id||P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:u.toReference()},j=ee(N,u);return j.setParent(u,a),j.initChildren(a),a==null||a.add(j,K.Added),j.addSelfToProject(a),t.push(j),T.forEach((k,q)=>{const ie={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:k,type:f.Property,codeName:k,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,extends:null,index:q,hidden:!1,private:!1,required:!0,parent:j.toReference()},te=ee(ie,u);te.setParent(j,a),te.initChildren(a),a==null||a.add(te,K.Added),te.addSelfToProject(a),t.push(te);const pe=d[k],me={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.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:te.toReference()},J=ee(me,u);J.setParent(te,a),J.initChildren(a),a==null||a.add(J,K.Added),J.addSelfToProject(a),t.push(J);const ae=aA(pe,J,{...i,name:k,id:P.UUID.uuid()},a,l||j);p.push(...ae.updated),t.push(...ae.added),y.push(...ae.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:j}}}function ya(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(p=>{const t=u.find(v=>v.name===p.name),y=u.find(v=>{var T,w;return!!p.implements&&((T=v.implements)==null?void 0:T.id)===((w=p.implements)==null?void 0:w.id)});if(t){const v=new qt({id:p.id+"--"+t.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${t.type} ${t.name} with id "${t.id}" that has the same name`,issue:null,severity:Z.Error,code:a,entity:p,firstRelationship:t});l.push(v)}if(y){const v=new qt({id:p.id+"--"+y.id+"--"+i,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,issue:null,severity:Z.Error,code:i,entity:p,firstRelationship:y});l.push(v)}}):u.forEach(p=>{var v;const t=d.find(T=>T.name===p.name),y=d.find(T=>{var w,A;return!!T.implements&&((w=T.implements)==null?void 0:w.id)===((A=p.implements)==null?void 0:A.id)});if(t){const T=new qt({id:t.id+"--"+p.id+"--"+a,message:`Entity of type ${t.type} named "${t.name}" with id "${t.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,issue:null,severity:Z.Error,code:a,entity:t,firstRelationship:p});l.push(T)}if(y){const T=new qt({id:y.id+"--"+p.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,issue:null,severity:Z.Error,code:i,entity:y,firstRelationship:p});l.push(T)}}),{errors:l,overlap:!!l.length})}function fme(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===gb.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function hme(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Qy.Implements||a.field===Qy.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function yme(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function mme(d,u){return d.static&&d.metaSync({static:!1},u),d}var Tj=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d))(Tj||{});function bj(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new qt({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces.`,issue:null,severity:Z.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function Aj(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new qt({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,issue:null,severity:Z.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}if(a.includes("-")){const l=new qt({id:d.id+"--string-value-must-not-have-dashes",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,issue:null,severity:Z.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function oA(d,u){var i;if(d.type===f.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${re(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof Hi||d.increaseVersion)return`${d.type}: ${d.id} (${yd(d)})`;try{const a=yd(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${re(d,u)})`}function wd(d,u){const i=Xa(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(p=>{if(p===u)return a=p,[p];const t=wd(p,u);return t.last&&(a=t.last),[p,...t.list]}),last:a}}function lA(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const p=Ri(l,d.project);return!p||p.type===f.Project?a:a.type===f.Project||wd(p,a).last?p:(wd(a,p).last,a)},d.project);return i.type===f.FunctionDeclaration&&i.parent.type===f.Loop?i.parent:i}function je(d,u){var l,p;let i=lA(d);if(d.type===f.InternalCall)(l=d.parent)==null||l.setParent(i,u),(p=d.parent)==null||p.addSelfToProject(u);else if((d.type===f.ContinueStatement||d.type===f.BreakStatement)&&i.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!br.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else d.setParent(i,u),d.addSelfToProject(u);if(rr.includes(d.type))return;ut(d).forEach(t=>{var v,T;const y=lA(t);if(t.type===f.InternalCall)(v=t.parent)==null||v.setParent(y,u),(T=t.parent)==null||T.addSelfToProject(u);else if((t.type===f.ContinueStatement||t.type===f.BreakStatement)&&y.type!==f.Loop){t.remove({ignoreUpstream:!1},u);return}else if(t.type===f.ReturnStatement&&!br.includes(y.type)){t.remove({ignoreUpstream:!1},u);return}else t.setParent(y,u),t.addSelfToProject(u)})}function Ky(d,u,i=new Set){const a=tn(d),l=tn(u),p=a.filter(v=>!l.includes(v)),t=a.filter(v=>l.includes(v)),y=p.reduce((v,T)=>i.has(T.id)?v:(i.add(T.id),R([...v,...Ky(T,u,i)])),[]);return R([...t,...y])}function Wo(d,u){const i=wd(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function dA(d,u){return!!wd(d,u).last}function vme(d){if(Wt.includes(d.type))return d;if([...ks,f.VariableDeclaration].includes(d.type)){const u=d.parent;return Wt.includes(u.type)?u:null}return null}function uA(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const i=d.parent;if(i){if(i===u)return u;if(i.type===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return uA(i,a)}function ur(d){if($f.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return ur(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType?ur(d.parent):d}else{const u=d.parent;return u?ur(u):null}}function ky(d,u){const i=Ap(d,u);if(!i)return null;if($f.includes(i.type)){if(i.type===f.FunctionDeclaration){const a=Ap(i.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}return i}else{const a=i.parent?Ap(i.parent,u):null;return a?ky(a,u):null}}function Ij(d){if(!d)return null;if(ks.includes(d.type))return d;const u=d.parent;return u?Ij(u):null}function wj(d){if(!d)return null;if(Xt.includes(d.type))return d;const u=d.parent;return u?wj(u):null}function Rj(d){if(!d)return null;if(qs.includes(d.type))return d;const u=d.parent;return u?Rj(u):null}function _j(d){return d.type===f.VariableDeclaration?[d]:Xt.includes(d.type)?[...d.inputs,...d.outputs||[]]:rr.includes(d.type)?d.outputs:Dl.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function Eme(d){const u=tn(d),i=[],a=[];lR.includes(d.type)&&i.push(...qy(d));const l=u.filter(p=>{const t=i.includes(p);return t?!1:ks.includes(p.type)&&!t?(a.push(p),!1):!0});return i.sort((p,t)=>Wo(t,p)?-1:0),a.sort((p,t)=>Wo(t,p)?-1:0),[...i,...a,...l]}function gj(d){return[...d].sort((u,i)=>Wo(i,u)?-1:0)}function cA(d){const u=gj(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const p=l[l.length-1];Wo(a,p)?i.push([a]):l.push(a)}else i.push([a])}),i}function zr(d){const u=d.map(i=>ur(i));return R(u)}function qy(d){return Xt.includes(d.type)?[...zr(d.successCalls),...zr(d.errorCalls)]:Wt.includes(d.type)?zr(d.calls):[]}function Tme(d,u){return qy(d).includes(u)}function pA(d){return d.writesValues||[]}function bme(d,u){return pA(d).includes(u)}function Dj(d){var u;return rt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function Ame(d){return d.writesValues}function Oj(d=[]){return d.map(Dj).filter(u=>!!u)}function Sy(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>rt.includes(u.type))}function Cj(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&rt.includes(u.type))}function $j(d){return rt.includes(d.type)?d:null}function Pj(d){return d.writesValues.map($j).filter(u=>!!u)}function Vj(d=[]){return d.reduce((u,i)=>i.type===f.OutputMap?[...u,...Pj(i)]:u,[])}function ut(d){return d.type===f.Loop?R([...$s(zr(d.successCalls)),...$s(zr(d.errorCalls)),...d.body?ut(d.body):[]]):Xt.includes(d.type)?R([...$s(zr(d.successCalls)),...$s(zr(d.errorCalls))]):Wt.includes(d.type)?R($s(zr(d.calls))):[]}function Ime(d){return Xt.includes(d.type)?[...$s(zr(d.successCalls)),...$s(zr(d.errorCalls))]:Wt.includes(d.type)?$s(zr(d.calls)):[]}function Nj(d,u=new Set){return d.writesValues.filter(a=>rt.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Ht(l,u)],[])}function Lj(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>rt.includes(l.type)&&!u.has(l.id)).reduce((l,p)=>u.has(p.id)?l:[...l,...Ht(p,u)],[])}function Ht(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return Cj(d.outputs).reduce((a,l)=>[...a,...Ht(l,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[...ut(d).reduce((p,t)=>{const y=ur(t);return[...p,...Ht(y||t,u)]},[]),...Oj(d.inputs),...Vj(d.outputs)].reduce((p,t)=>[...p,...Ht(t,u)],[]);if(Dl.includes(d.type)){const i=Sy(d.inputs),l=ut(d).reduce((p,t)=>{const y=ur(t);return[...p,...Ht(y||t,u)]},[]);return i.push(...l),i.reduce((p,t)=>[...p,...Ht(t,u)],[])}if(d.type===f.FunctionDeclaration){const i=[...Sy(d.inputs)],l=ut(d).reduce((p,t)=>{const y=ur(t);return[...p,...Ht(y||t,u)]},[]);return i.push(...l),i.reduce((p,t)=>[...p,...Ht(t)],[])}if(rt.includes(d.type)){u.add(d.id);const a=ut(d).reduce((l,p)=>{const t=ur(p);return[...l,...Ht(t||p,u)]},[]);return[d,...a,...Lj(d,u),...Nj(d,u)]}return[]}function Xi(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...tn(d).reduce((l,p)=>[...l,p,...Xi(p,u)],[])])}function $s(d){return d.reduce((u,i)=>i.type===f.ReturnStatement||i.type===f.ContinueStatement||i.type===f.BreakStatement?[...u,i]:[...u,i,...ut(i)],[])}function Bj(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,T)=>[...v,...T.properties],[]),l=u.reduce((v,T)=>[...v,...T.methods],[]),p=l.reduce((v,T)=>[...v,...Sy(T.inputs),...$s(zr(T.calls)),...T.returnStatements],[]),t=d.functions.reduce((v,T)=>[...v,...$s(zr(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...$s(zr(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...p,...t,...y]}function Mj(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(l=>l.id===d.id)!==void 0||a.outputs.find(l=>l.id===d.id)!==void 0;case f.Condition:return a.successCalls.find(l=>l.id===d.id)!==void 0||a.errorCalls.find(l=>l.id===d.id)!==void 0||a.inputs.find(l=>l.id===d.id)!==void 0;case f.Operation:return a.outputs.find(l=>l.id===d.id)!==void 0;case f.VariableDeclaration:return Xt.includes(d.type)?cx(d).find(p=>{var t;return((t=p.readsValue)==null?void 0:t.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(l=>l.id===d.id)!==void 0||a.methods.find(l=>l.id===d.id)!==void 0;case f.FunctionDeclaration:return a.inputs.find(l=>l.id===d.id)!==void 0||(a.returnStatements.map(l=>l.outputs).flat()||[]).find(l=>l.id===d.id)!==void 0;default:return!1}})}function wme(d){const u=Bj(d.project);return Mj(d,u)}function Ap(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function Uj(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,p=d[a];i[l]=p}),i}function Rd(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(ki.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const l=d,p=d,t=d,y=d,v=d,T=d,w=d,A=d,V=d,N=d,j=d,k=d,q=d,Y=[...q.readsValue?[q.readsValue]:[],...q.declaration?[q.declaration]:[],...(k.calledByEntry||[]).flatMap(ne=>ne),...(k.calledBySuccess||[]).flatMap(ne=>ne),...(k.calledByError||[]).flatMap(ne=>ne),...N.parent?[N.parent]:[]];Array.isArray(t.implements)?Y.push(...t.implements.flatMap(ne=>ne)):V.implements&&Y.push(V.implements),Array.isArray(t.extends)?Y.push(...t.extends.flatMap(ne=>ne)):V.extends&&Y.push(V.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&Y.push(...v.valueAsTypeList.flatMap(ne=>ne)),v.valueAsTypeSingle&&Y.push(v.valueAsTypeSingle);const ie=[...(l.inputs||[]).flatMap(ne=>ne),...(j.inputsDeclarations||[]).flatMap(ne=>ne),...(l.outputs||[]).flatMap(ne=>ne),...(j.outputsDeclarations||[]).flatMap(ne=>ne),...(q.internalCalls||[]).flatMap(ne=>ne),...q.writesValues||[],...k.dataType?[k.dataType]:[],...T.body?[T.body]:[],...k.defaultValue?[k.defaultValue]:[],...(k.successCalls||[]).flatMap(ne=>ne),...(k.errorCalls||[]).flatMap(ne=>ne),...(t.properties||[]).flatMap(ne=>ne),...(t.methods||[]).flatMap(ne=>ne),...(t.abstractMethods||[]).flatMap(ne=>ne),...w.error?[w.error]:[],...w.process?[w.process]:[],...N.throws?[N.throws]:[],...(p.andChildrenGroup||[]).flatMap(ne=>ne),...(p.orChildrenGroup||[]).flatMap(ne=>ne),...(A.entities||[]).flatMap(ne=>ne),...(A.functions||[]).flatMap(ne=>ne),...(A.functionCalls||[]).flatMap(ne=>ne),...(A.events||[]).flatMap(ne=>ne),...(A.conditions||[]).flatMap(ne=>ne),...(A.operations||[]).flatMap(ne=>ne),...(A.loops||[]).flatMap(ne=>ne),...(A.variableDeclarations||[]).flatMap(ne=>ne),...(A.variableInstances||[]).flatMap(ne=>ne),...(A.searches||[]).flatMap(ne=>ne),...(A.projects||[]).flatMap(ne=>ne),...(y.calls||[]).flatMap(ne=>ne)];d.type===f.DataType&&(p.entity&&u[W(p.entity)]&&u[W(p.entity)].parent&&W(u[W(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&Y.push(p.entity));const te={},pe={};return Y.forEach(ne=>{var ae;const me=W(ne);if(me&&a.ignoreBuiltInBaseEntities&&(ki.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(me)))return;const J=ne.version;if(me){const ce=((ae=a.entityMaps)==null?void 0:ae.get(me))||me;te[ce]=J}}),ie.forEach(ne=>{var ae;const me=W(ne);if(me&&a.ignoreBuiltInBaseEntities&&(ki.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(me)))return;const J=ne.version;if(me){const ce=((ae=a.entityMaps)==null?void 0:ae.get(me))||me;pe[ce]=J}}),{upstream:te,downstream:pe}}function Rme(d,u){const i=[];if(ks.includes(d.type)){ys(d).forEach(p=>{const t=ky(p,u);t&&i.push(t)});const l=[...d.inputs||[],...d.outputs||[]].map(p=>{const t=Ap(p,u);return t?fx(t,u):null}).filter(p=>p!==null);i.push(...R(l))}if(rt.includes(d.type)){const a=Zy(d);a&&i.push(a)}return R(i)}function Xa(d){const u=[];if(ks.includes(d.type)){d.calledBy.forEach(l=>{const p=ur(l);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>Zy(l)).filter(l=>l!==null);u.push(...R(a))}if(rt.includes(d.type)){const i=Zy(d);i&&u.push(i)}return R(u)}function ys(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function jj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>he(a,u,i)),...d.outputs.flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.parent?he(d.parent,u,i):[]]}function xj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?he(d.defaultValue,u):[],...d.writesValues.flatMap(a=>he(a,u,i)),...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Fj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>he(a,u,i)),...d.throws?he(d.throws,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function Gj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>he(a,u,i)),...(d.methods||[]).flatMap(a=>he(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>he(a,u,i)),...(d.extends||[]).flatMap(a=>he(a,u,i))]}function Kj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function kj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>he(a,u,i)),...d.throws?he(d.throws,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function qj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...(d.extends||[]).flatMap(a=>he(a,u,i)),...(d.implements||[]).flatMap(a=>he(a,u,i)),...(d.properties||[]).flatMap(a=>he(a,u,i)),...(d.methods||[]).flatMap(a=>he(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function Sj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>he(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>he(a,u,i)),...d.entity?he(d.entity,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Zj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function Jj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.calls||[]).flatMap(a=>he(a,u,i)),...d.implements?he(d.implements,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Wj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.calls||[]).flatMap(a=>he(a,u,i)),...d.implements?he(d.implements,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Yj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?he(d.readsValue,u,i):[],...d.declaration?he(d.declaration,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Hj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>he(a,u,i)),...(d.events||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function zj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Xj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?he(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>he(a,u,i)):[],...d.parent?he(d.parent,u,i):[]]}function Qj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...d.body?he(d.body,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function ex(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function tx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>he(a,u,i)),...d.declaration?he(d.declaration,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...d.parent?he(d.parent,u,i):[]]}function rx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>he(a,u,i)),...(d.methods||[]).flatMap(a=>he(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>he(a,u,i))]}function ix(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>he(a,u,i)),...(d.functions||[]).flatMap(a=>he(a,u,i)),...(d.events||[]).flatMap(a=>he(a,u,i)),...(d.projects||[]).flatMap(a=>he(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>he(a,u,i)),...(d.variableInstances||[]).flatMap(a=>he(a,u,i)),...(d.operations||[]).flatMap(a=>he(a,u,i)),...(d.conditions||[]).flatMap(a=>he(a,u,i)),...(d.functionCalls||[]).flatMap(a=>he(a,u,i)),...(d.projects||[]).flatMap(a=>he(a,u,i)),...(d.loops||[]).flatMap(a=>he(a,u,i)),...(d.searches||[]).flatMap(a=>he(a,u,i))]}function sx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?he(d.defaultValue,u,i):[],...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function nx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?he(d.readsValue,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function ax(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.throws?he(d.throws,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function ox(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputsDeclarations||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function lx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?he(d.defaultValue,u,i):[],...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function dx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(d.internalCalls||[]).flatMap(a=>he(a,u,i)),...(d.writesValues||[]).flatMap(a=>he(a,u,i)),...d.readsValue?he(d.readsValue,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function ux(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(d.internalCalls||[]).flatMap(a=>he(a,u,i)),...(d.writesValues||[]).flatMap(a=>he(a,u,i)),...d.readsValue?he(d.readsValue,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.declaration?he(d.declaration,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Ps(){const d=new Set,u=pV.flatMap(i=>he(i,d)).map(i=>i.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function he(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(ki.includes(d.type)||Ps().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return Zj(d,u,i);case f.Operation:return ex(d,u,i);case f.Condition:return Kj(d,u,i);case f.Loop:return Qj(d,u,i);case f.Search:return ox(d,u,i);case f.GlobalEvent:return Wj(d,u,i);case f.ReturnStatement:return ax(d,u,i);case f.ContinueStatement:return kj(d,u,i);case f.BreakStatement:return Fj(d,u,i);case f.VariableDeclaration:return dx(d,u,i);case f.DefinitionEntity:return qj(d,u,i);case f.FunctionDeclaration:return Jj(d,u,i);case f.Project:return ix(d,u,i);case f.ActionDescriptor:return jj(d,u,i);case f.ArgumentDeclaration:return xj(d,u,i);case f.ReturnDeclaration:return nx(d,u,i);case f.ValueDescriptor:return lx(d,u,i);case f.InputMap:return Yj(d,u,i);case f.OutputMap:return tx(d,u,i);case f.DataType:return Sj(d,u,i);case f.InstalledProject:return Hj(d,u,i);case f.InternalCall:return zj(d,u,i);case f.LiteralValue:return Xj(d,u,i);case f.Property:return sx(d,u,i);case f.VariableInstance:return ux(d,u,i);case f.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:Gj(d,u,i);case f.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:rx(d,u,i)}return[]}function fA(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||Dl.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function _me(d,u){return u.type===f.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function cx(d){return Xt.includes(d.type)?d.inputs:[]}function px(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:rr.includes(d.type)?d.outputs:[]}function gme(d,u){return u.type===f.Condition?null:u.type===f.FunctionCall||u.type===f.Operation?u.outputs.find(i=>i.declaration.id===d.id):null}function Dme(d){return d.type===f.Condition?[]:Xt.includes(d.type)?d.outputs:[]}function Zy(d){const u=d.readsValue;return u?ur(u):null}function fx(d,u){const i=d.readsValue;return i?ky(i,u):null}function hx(d){const u=d.internalCalls||[];return R(zr(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function _d(d){const u=pA(d),i=[];return u.forEach(a=>{if(rt.includes(a.type))i.push(a);else if(Jn.includes(a.type)){const l=a.parent;i.push(l)}}),i}function R(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function tn(d,u=!1){const i=[];if(d.type===f.Project&&i.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),br.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:tn(l));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>ur(p)),l=d.errorCalls.map(p=>ur(p));i.push(...a,...l)}if(Dl.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>_d(p)).flat(),l=d.calls.map(p=>ur(p));i.push(...R(a),...l)}if(Xt.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(t=>_d(t)).flat(),l=d.successCalls.map(t=>ur(t)),p=d.errorCalls.map(t=>ur(t));i.push(...R(a),...l,...p)}if(rt.includes(d.type)){const a=_d(d),l=hx(d);i.push(...a,...l)}if(d.type===f.Loop){const a=d.outputs.map(t=>_d(t)).flat();if(d.body){const t=tn(d.body,u);i.push(...t)}const l=d.errorCalls.map(t=>ur(t)),p=d.successCalls.map(t=>ur(t));i.push(...R(a),...p,...l)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>_d(p)).flat(),l=d.calls.map(p=>ur(p));i.push(...R(a),...l)}return R(i)}function Jy(d,u=!1){const i=tn(d,u),a=[...i,...i.reduce((l,p)=>[...l,...Jy(p,u)],[])];return R(a)}function yx(d){const u=Xa(d),i=[...u,...u.reduce((a,l)=>[...a,...yx(l)],[])];return R(i)}function Ip(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...Ip(i),...wp(i)]:[...u,i.name],[])}function wp(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...wp(i),...Ip(i)]:[...u,i.name],[])}function hA(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...hA(i),...yA(i)]:[...u,i],[])}function yA(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...yA(i),...hA(i)]:[...u,i],[])}function gd(d){return[...wp(d),...Ip(d)].filter((i,a,l)=>l.indexOf(i)===a)}function mA(d){return d.implements.length===0&&d.extends.length===0?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===$e.PERSISTED_ENTITY)?d:[...d.implements,...d.extends].reduce((a,l)=>{if(l.type===f.DefinitionEntity){const p=mA(l);if(p)return p}return a},null)}function Ome(d){const u=d.extends.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Cme(d){const u=d.implements.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Wy(d){const u=d.extends.find(i=>i.type===f.DefinitionEntity);return u&&u.type===f.DefinitionEntity?u:null}function wi(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends].reduce((i,a)=>a.type===f.BuiltInBaseEntity?[...i,a]:a.type===f.DefinitionEntity?[...i,...wi(a)]:i,[]);return R(u)}function Rp(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!wi(d).find(a=>!a.interactive)}function $me(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function vA(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function mx(d){if([...Wt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||vA(d))return!1;const u=Xa(d);return u.length===0?!0:u.some(i=>mx(i))}function EA(d){return[...Wt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||vA(d)?!1:Xa(d).length===0}function vx(d,u=0){if(EA(d)){const i=Xa(d);return i.length===0?d:i.map(l=>vx(l,u+1)).reduce((l,p)=>l?p&&p.x<l.x?p:l:p,null)}return null}function Ex(d){const u=[];if(EA(d))u.push(d);else return[];return Xa(d).forEach(a=>{u.push(...Ex(a))}),u}function TA(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function Pme(d,u){const i=new Map;return d.forEach(a=>{i.set(a.id,a)}),u.forEach(a=>{i.set(a.id,a)}),Array.from(i.values())}function _p(d){switch(d){case f.DefinitionEntity:return ma;case f.FunctionDeclaration:return Ua;case f.VariableDeclaration:return ka;case f.VariableInstance:return Ka;case f.FunctionCall:return za;case f.Operation:return ja;case f.Condition:return Ga;case f.ReturnStatement:return xa;case f.Loop:return Ai;case f.Search:return qa;case f.InputMap:return Cs;case f.OutputMap:return Qs;case f.ArgumentDeclaration:return pa;case f.ReturnDeclaration:return Ni;case f.Property:return ua;case f.InstalledProject:return Sa;case f.Project:return P;case f.DataType:return Hi;case f.GlobalEvent:return Fa;case f.InternalCall:return Za;case f.ValueDescriptor:return en;case f.BuiltInBaseEntity:return Cn;case f.PrimitiveEntity:return Li;case f.ActionDescriptor:return jt;case f.LiteralValue:return bi;case f.ContinueStatement:return li;case f.BreakStatement:return Ja;default:return null}}function Ri(d,u,i=null){const a=d!=null&&d.parent?W(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if(d.type===f.ReturnStatement)return $r(d,u,p);if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return l;if(Wt.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?l:d;if(ki.includes(d.type))return null;const t=d.parent;if(!t)return null;if(t.type===f.GenericReference){const y=W(t);if(!y)return null;const v=u.get(y);return v?Ri(v,u,p):null}else return t===u?u:Ri(t,u,p)}function $r(d,u,i=null){const a=d!=null&&d.parent?W(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return $r(l.parent,u,p);if(Wt.includes(d.type))return d;if(ki.includes(d.type))return null;const t=d.parent;if(!t)return null;if(t.type===f.GenericReference){const y=W(t);if(!y)return null;const v=u.get(y);return v?$r(v,u,p):null}else return t===u?u:$r(t,u,p)}function bA(d,u){if(ki.includes(d.type)||u.getBuiltIn(d.id))return null;const i=_i(d.parent,u);return i?i===u?br.includes(d.type)?d:null:i.type===f.DefinitionEntity?d:bA(i,u):null}function Yy(d,u,i){if(d===u||u===i||d===i)return!1;const a=Ri(u.parent,i);return a===d?!0:Yy(a,u,i)}var Hy=(d=>(d.SameBothLocal="same-both-local",d.AInB="a-in-b",d.BInA="b-in-a",d.ParallelInCommonParent="parallel-in-common-parent",d.ParallelInProject="parallel-in-project",d.AIsGlobalBIsNot="a-is-global-b-is-not",d.BIsGlobalAIsNot="b-is-global-a-is-not",d.SameBothGlobal="same-both-global",d))(Hy||{});function gp(d,u,i){const a=Ri(d,i),l=Ri(u,i);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!l)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===l&&a.type!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===l&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&l.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&l.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:l};if(Yy(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Yy(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=uA(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Ri(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function Tx(d,u,i){const a=gp(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=Ri(d.parent,i);if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;for(;l;){if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;l=Ri(l.parent,i)}let p=Ri(u.parent,i);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Ri(p.parent,i)}return null}function bx(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=Tx(i,a,a.project);return!l||l===a?i:a},d[0])}function _i(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===f.GenericReference?i=W(d):i=d.id,i===u.id?u:u.get(i)}function Qa(d){if(!d)return null;if(ki.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:Qa(u)}function Dp(d){const u=[];function i(p,t){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===t)}function a(p,t){i(p,t)||u.push({blockedByCaller:p,blockedByCalling:t})}const l=bA(d,d.project);return d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{rr.includes(v.type)&&v!==d&&(ut(d).find(A=>A===v)||a(p,v))});let y;if(Xt.includes(p.type)&&(y=p),y){const v=Dp(y);v.reachable||ut(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{rr.includes(v.type)&&v!==d&&(ut(d).find(A=>A===v)||a(p,v))});let y;if(Xt.includes(p.type)&&(y=p),y){const v=Dp(y);v.reachable||ut(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{rr.includes(v.type)&&v!==d&&(ut(d).find(A=>A===v)||a(p,v))}),p===l)return;let y;if(p.type===f.FunctionDeclaration){const v=ur(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=Dp(y);v.reachable||v.blocks.forEach(T=>{a(p,T.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}}function Vme(d){return $f.includes(d.type)?d.type===f.FunctionDeclaration?!TA(d):!0:!1}function Nme(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function zy(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!wp(d).includes(u)}function Lme(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!Ip(d).includes(u)}function Vs(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!gd(d).includes(u)}function Bme(d){const u=[];return d.entities.forEach(i=>{if(zy(i,$e.PERSISTED_ENTITY)){u.push(i);return}}),R(u)}function Mme(d){const u=[];return d.entities.forEach(i=>{if(zy(i,$e.RELATIONAL_DATABASE)){u.push(i);return}}),R(u)}function Ume(d){return d.type!==f.DefinitionEntity||d.abstract||!zy(d,$e.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>{var a;return((a=i.implements)==null?void 0:a.id)===Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.primaryKey.id&&!i.abstract}))||null}function Ax(d){var a;const u=mA(d);if(!u)return null;const i=u.properties.find(l=>{var p;return((p=l.implements)==null?void 0:p.id)===Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.database.id});return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function Dd(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!Vs(d,$e.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>{var l;return((l=a.implements)==null?void 0:l.id)!==Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...i),u}function jme(d){var i;if(!d||d.type!==f.DefinitionEntity||!Vs(d,$e.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var l;return((l=a.implements)==null?void 0:l.id)===Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.database.id});return(i=u==null?void 0:u.getDefaultValue())==null?void 0:i.valueAsTypeSingle}function Ir(d,u){var a;if(!cR.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===f.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function xme(d){switch(d){case f.Project:return P;case f.InstalledProject:return Sa;case f.DefinitionEntity:return ma;case f.FunctionDeclaration:return Ua;case f.GlobalEvent:return Fa;case f.VariableInstance:return Ka;case f.VariableDeclaration:return ka;case f.InputMap:return Cs;case f.OutputMap:return Qs;case f.Condition:return Ga;case f.Operation:return ja;case f.FunctionCall:return za;case f.ReturnDeclaration:return Ni;case f.ArgumentDeclaration:return pa;case f.PrimitiveEntity:return Li;case f.DataType:return Hi;case f.Property:return ua;case f.ActionDescriptor:return jt;case f.ReturnStatement:return xa;case f.ContinueStatement:return li;case f.BreakStatement:return Ja;case f.Loop:return Ai;case f.Search:return qa;case f.ValueDescriptor:return en;case f.InternalCall:return Za;case f.LiteralValue:return bi}return null}function Fme(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(i=>{u.added[i.id]=i}),d==null||d.updated.forEach(i=>{u.updated[i.id]=i}),d==null||d.removed.forEach(i=>{u.removed[i.id]=i}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(i=>i.id))),u}function Er(d,u){const i=_p(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const p=d[l],t=u[l];return t===void 0||p===t?!0:Array.isArray(p)&&Array.isArray(t)?p.length!==t.length?!1:p.every((y,v)=>y===t[v]):!1}):!1}function Xy(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const i=W(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...Xy(a,u)]:[]}function Gme(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=ur(a);!l||i.has(l.id)||(i.add(l.id),u.push(l))}),R(u)}function Kme(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(Ee["value-descriptor"][Ol.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function Ix(d){const u=d.entities.filter(l=>!!l.implements.find(p=>p.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const p=l.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),t=p==null?void 0:p.getDefaultValue();return(t==null?void 0:t.value)===!0});return i||u[0]||null}function AA(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Ps()]));return!!(i.includes(d.id)||!Xy(d,{...u.instances,...u.builtInInstances}).every(p=>!i.includes(p)))}function wx(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?wx(u):d.id}function Rx(d){const u=Vce(),i=d.toJSON();u.safeParse(i).success;const l=d.implements.flatMap(w=>kme(d,w)),p=d.extends.flatMap(w=>qme(d,w)),t=Zme(d),y=Sme(d);d.methods.flatMap(w=>w.validate());const v=[...l,...p,...t,...y];return zt(d.errors,v)}function _x(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let l=[...d.properties];return i.forEach(p=>{const t=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});t?l=l.filter(y=>y.id!==t.id):a.push(p)}),a}function gx(d,u){const i=u.abstractMethods,a=[];let l=[...d.methods];return i.forEach(p=>{const t=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});t?l=l.filter(y=>y.id!==t.id):a.push(p)}),a}function kme(d,u){const i=[];if(!u.abstract){const w=nt({id:d.id+"--"+se.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),l=[];let p=[...d.properties];a.forEach(w=>{const A=p.find(V=>{var N;return((N=V.implements)==null?void 0:N.id)===w.id});A?p=p.filter(V=>V.id!==A.id):l.push(w)}),l.length&&l.forEach(w=>{const A=nt({id:d.id+"--"+se.MissingPropertyImplementation+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:Z.Error,code:se.MissingPropertyImplementation,entity:d});i.push(A.error)});const t=[];let y=[...d.methods];u.abstractMethods.forEach(w=>{const A=y.find(V=>{var N;return((N=V.implements)==null?void 0:N.id)===w.id});A?y=y.filter(V=>V.id!==A.id):t.push(w)}),t.length&&t.forEach(w=>{const A=nt({id:d.id+"--"+se.MissingMethodImplementation+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:Z.Error,code:se.MissingMethodImplementation,entity:d});i.push(A.error)});const v=[];u.properties.forEach(w=>{const A=p.find(V=>V.name===w.name);A&&v.push([A,w])}),v.length&&v.forEach(([w])=>{const A=nt({id:d.id+"--"+oe.PropertyOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)});const T=[];return u.methods.forEach(w=>{const A=y.find(V=>V.name===w.name);A&&T.push([A,w])}),T.length&&T.forEach(([w])=>{const A=nt({id:d.id+"--"+oe.MethodOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function qme(d,u){const i=[],a=[];if(!d.abstract&&u.abstract){const p=nt({id:d.id+"--"+u.id+"--"+se.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=nt({id:d.id+"--"+u.id+"--"+se.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}d.properties.forEach(p=>{var y;const t=u.properties.find(v=>{var T;return v.name===p.name&&((T=p.extends)==null?void 0:T.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(t==null?void 0:t.id)&&t&&a.push(p)}),a.length&&a.forEach(p=>{const t=nt({id:d.id+"--"+oe.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(t.error)});const l=[];return d.methods.forEach(p=>{var y;const t=u.methods.find(v=>{var T;return v.name===p.name&&((T=p.extends)==null?void 0:T.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(t==null?void 0:t.id)&&t&&l.push(p)}),l.length&&l.forEach(p=>{const t=nt({id:d.id+"--"+oe.MethodOverwritesOtherSiblingWithSameName,message:`Method "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(t.error)}),i}function Sme(d){const u=[];if(!d.properties.length){const i=nt({id:d.id+"--"+se.NoProperties,message:"No properties implemented",issue:null,severity:Z.Warning,code:se.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function Zme(d){const u=[];if(d.abstract){if(d.methods.length){const i=nt({id:d.id+"--"+se.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:Z.Error,code:se.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=nt({id:d.id+"--"+se.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:Z.Error,code:se.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const l=nt({id:d.id+"--"+se.StaticEntityWithNonStaticProperties+"--"+a.id,message:`Property "${a.name}" with id "${a.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:Z.Error,code:se.StaticEntityWithNonStaticProperties,entity:d});u.push(l.error)}})}}else{if(d.abstractMethods.length){const i=nt({id:d.id+"--"+se.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,issue:null,severity:Z.Error,code:se.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=nt({id:d.id+"--"+se.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:Z.Error,code:se.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});u.push(a.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const a=nt({id:d.id+"--"+se.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,issue:null,severity:Z.Error,code:se.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function Jme(d,u){const i=[],a=wi(u);if(!u.abstract){const t=new qt({id:d.id+"--"+u.id+"--"+se.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(t)}const l=d.implements.filter(t=>t.id!==u.id);if(d.abstract){const t=new qt({id:d.id+"--"+u.id+"--"+se.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(t)}if(d.static&&!u.static){const t=new qt({id:d.id+"--"+u.id+"--"+se.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(t)}if(!d.static&&u.static){const t=new qt({id:d.id+"--"+u.id+"--"+se.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(t)}return l.length&&l.forEach(t=>{if(t.type===f.BuiltInBaseEntity){const y=a.filter(v=>v.id!==t.id);y.length&&y.forEach(v=>{if(v.id!==t.id){const T=new qt({id:d.id+"--"+v.id+"--"+t.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${t.name}" with id "${t.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:t});i.push(T)}})}else{wi(t).forEach(w=>{const A=a.filter(V=>V.id!==w.id);A.length&&A.forEach(V=>{if(V.id!==w.id){const N=new qt({id:d.id+"--"+V.id+"--"+w.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:w});i.push(N)}})});const v=ya(u.ownDeclaredProperties,t.ownDeclaredProperties,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const T=ya(u.abstractMethods,[...t.abstractMethods,...t.methods],oe.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,oe.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...T.errors)}}),R(d.extends.flatMap(t=>wi(t))).forEach(t=>{if(!a.find(y=>y.id===t.id)){const y=new qt({id:d.id+"--"+u.id+"--"+t.id+"--"+se.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${u.name}" with id "${u.id}" but also extends entity "${t.name}" with id "${t.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:t});i.push(y)}}),i}function Wme(d,u,i=!1){const a=[],l=wi(u);if(!d.abstract&&u.abstract){const w=nt({id:d.id+"--"+u.id+"--"+se.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.abstract&&!u.abstract){const w=nt({id:d.id+"--"+u.id+"--"+se.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!d.static&&u.static){const w=nt({id:d.id+"--"+u.id+"--"+se.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.static&&!u.static){const w=nt({id:d.id+"--"+u.id+"--"+se.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!Rp(u)){const w=nt({id:d.id+"--"+u.id+"--"+se.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(w.error)}const t=d.extends.filter(w=>w.id!==u.id);t.length&&t.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter(V=>V.id!==w.id);A.length&&A.forEach(V=>{if(V.id!==w.id){const N=nt({id:d.id+"--"+V.id+"--"+w.id+"--"+se.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${V.name}" with id "${V.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ExtendsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:w});a.push(N.error)}})}else{wi(w).forEach(Y=>{const ie=l.filter(te=>te.id!==Y.id);ie.length&&ie.forEach(te=>{if(te.id!==Y.id){const pe=new qt({id:d.id+"--"+te.id+"--"+Y.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${te.name}" with id "${te.id}" but also extends or implements entity "${Y.name}" with id "${Y.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:te,secondRelationship:Y});a.push(pe)}})});const V=!!wi(w).find(Y=>Y.id===u.id);let N=[...w.properties];V&&(N=N.filter(Y=>!u.properties.find(ie=>{var te;return ie.id===Y.id||ie.name===Y.name||ie.id===((te=Y.implements)==null?void 0:te.id)})));let j=[...w.methods];V&&(j=j.filter(Y=>!u.methods.find(ie=>{var te;return ie.id===Y.id||ie.name===Y.name||ie.id===((te=Y.implements)==null?void 0:te.id)})));const k=ya(u.ownDeclaredProperties,N,oe.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,oe.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...k.errors);const q=ya(u.abstractMethods,j,oe.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,oe.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...q.errors)}}),i&&console.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter(V=>V.id!==w.id);A.length&&A.forEach(V=>{if(V.id!==w.id){const N=new qt({id:d.id+"--"+V.id+"--"+w.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:w});a.push(N)}})}else{wi(w).forEach(j=>{const k=l.filter(q=>q.id!==j.id);k.length&&k.forEach(q=>{if(q.id!==j.id){const Y=new qt({id:d.id+"--"+q.id+"--"+j.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${q.name}" with id "${q.id}" but also implements entity "${j.name}" with id "${j.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:q,secondRelationship:j});a.push(Y)}})});const V=ya(u.ownDeclaredProperties,w.ownDeclaredProperties,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...V.errors);const N=ya(u.abstractMethods,[...w.abstractMethods,...w.methods],oe.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,oe.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...N.errors)}});const y=ya(d.ownDeclaredProperties,u.ownDeclaredProperties,oe.PropertyOverwritesOtherSiblingWithSameImplementation,oe.PropertyOverwritesOtherSiblingWithSameName);a.push(...y.errors);const v=ya(u.methods,u.abstractMethods,oe.MethodOverwritesOtherSiblingWithSameImplementation,oe.MethodOverwritesOtherSiblingWithSameName);return a.push(...v.errors),R(d.extends.flatMap(w=>wi(w))).forEach(w=>{if(!l.find(A=>A.id===w.id)){const A=new qt({id:d.id+"--"+u.id+"--"+w.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:w});a.push(A)}}),a}function Yme(d){const u=[];return d.implements.forEach(i=>{if(!i.static){const a=new qt({id:d.id+"--"+i.id+"--"+se.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:Z.Error,code:se.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends.forEach(i=>{if(!i.static){const a=new qt({id:d.id+"--"+i.id+"--"+se.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:Z.Error,code:se.StaticExtendingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function Hme(d){const u=[];if(d.implements.length){const i=new qt({id:d.id+"--"+se.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:Z.Error,code:se.AbstractEntityImplements,entity:d});u.push(i)}return d.extends.forEach(i=>{if(!i.abstract){const a=new qt({id:d.id+"--"+i.id+"--"+se.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${i.name}" with id "${i.id}" which is non-abstract`,issue:null,severity:Z.Error,code:se.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function zme(d){const u=[];return d.extends.forEach(i=>{if(i.static){const a=new qt({id:d.id+"--"+i.id+"--"+se.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${i.name}" with id "${i.id}" which is static`,issue:null,severity:Z.Error,code:se.NonStaticExtendingStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function Xme(d){const u=[];return d.extends.forEach(i=>{if(i.abstract){const a=new qt({id:d.id+"--"+i.id+"--"+se.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${i.name}" with id "${i.id}" which is abstract`,issue:null,severity:Z.Error,code:se.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}const Qme=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:gx,getBasePropertiesNotImplemented:_x,validate:Rx,validateCanBecomeAbstract:Hme,validateCanBecomeNonAbstract:Xme,validateCanBecomeNonStatic:zme,validateCanBecomeStatic:Yme,validateCanExtendEntity:Wme,validateCanImplementEntity:Jme},Symbol.toStringTag,{value:"Module"}));function e0e(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new Q({id:`${d.id}--${d.parent}--${S.SelfReference}`,code:S.SelfReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.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 a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new Q({id:`${d.id}--${d.parent}--${S.InvalidParentReference}`,code:S.InvalidParentReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):i.push(new Q({id:`${d.id}--${d.parent}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new Q({id:`${d.id}--${a}--${S.SelfReference}`,code:S.SelfReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.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 l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new Q({id:`${d.id}--${a}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new Q({id:`${d.id}--${a}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new Q({id:`${d.id}--${a}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):i.push(new Q({id:`${d.id}--${oe.InvalidObjectStructure}`,code:oe.InvalidObjectStructure,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`,issue:null})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new Q({id:`${d.id}--${a}--${S.InvalidExtendsReference}`,code:S.InvalidExtendsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.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})):i.push(new Q({id:`${d.id}--${a}--${S.InvalidExtendsReference}`,code:S.InvalidExtendsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new Q({id:`${d.id}--${a}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),i}var Qy=(d=>(d.Extends="extends",d.Implements="implements",d))(Qy||{});const Ct=class Ct extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"x");D(this,"y");D(this,"static");D(this,"abstract");D(this,"type",f.DefinitionEntity);D(this,"properties",[]);D(this,"methods",[]);D(this,"abstractMethods",[]);D(this,"extends",[]);D(this,"implements",[]);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestedProperties",[]);D(this,"suggestedMethods",[]);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DefinitionEntity,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const T=W(i.parent);l=a.get(T)}const p=[];i.implements&&i.implements.forEach(T=>{p.push(a.get(T)||a.getBuiltIn(T))});const t=[];i.extends&&i.extends.forEach(T=>{t.push(a.get(T)||a.getBuiltIn(T))});const y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,properties:[],methods:[],abstractMethods:[],extends:t,implements:p,x:0,y:0,parent:l},v=ee(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=e0e(l,a),y=hb(l,a);p.push(...t,...y,...vr(l));const v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DataType){const T=v;T.entity&&p.push(new Q({id:`${i.id}--${S.NewEntityWouldOverriteExisting}`,code:S.NewEntityWouldOverriteExisting,severity:Z.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${T.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
400
|
+
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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="parent"){const{updated:T,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}if(a==="parent"){const{updated:T,added:w,removed:A}=this.restore({},l);p.push(...T),t.push(...w),y.push(...A)}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Mt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.process=this.process,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Mt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=W(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(t=>W(t)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.declaration),y=this.project.get(t);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const y=W(t),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:w,added:A,removed:V}=this.syncOutputs(i);return a.push(...y,...w),l.push(...v,...A),p.push(...T,...V),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],t=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&je(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&je(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,K.Affected));const t=this.errorCalls.findIndex(y=>y.id===i.id);return t>-1&&(this.errorCalls.splice(t,1),a==null||a.add(this,K.Affected)),l&&je(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(p,K.Affected),!1)),l&&je(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=ee(this.initialData.declaration,this.project);this.declaration=a}else{const a=W(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=ee(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ee(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=$r(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.process&&(this.process=ee(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.initialData.error&&(this.error=ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Mt.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Mt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Mt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Mt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Mt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Mt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),t.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:w,removed:A,added:V}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...w),p.push(...A),t.push(...V)}),this.process){const{updated:T,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.inputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(T=>{const{updated:w,removed:A}=T.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:T,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);t.push(...T.added),l.push(...T.updated),p.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){var a,l;return i.has(this.id)?this.toReference():(i.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(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=Ne){var l,p,t,y,v,T,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.process?this.process.toFlatJSON(i):[],...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.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(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=hj(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var j,k;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.inputs=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(j=this.inputs)==null?void 0:j.map((q,Y)=>q.clone(i,A,w+"-input-map-"+Y+"-id",p));A.inputs=V;const N=(k=this.outputs)==null?void 0:k.map((q,Y)=>q.clone(i,A,w+"-output-map-"+Y+"-id",p));return A.outputs=N,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],t=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,T)=>{const w=this.inputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],t=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,T)=>{const w=this.outputs.findIndex(V=>V.declaration===v.declaration&&V!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?T>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);p.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],t=[],y=this.declaration.inputs.filter(A=>!this.inputs.find(V=>V.declaration.id===A.id));this.inputs.sort((A,V)=>A.index-V.index),y.forEach(A=>{this.inputs.forEach(j=>{j.index>=A.index&&j.metaSync({index:j.index+1},i)});const V={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},N=ee(V,this.project);N.setParent(this,i),N.initChildren(i),i==null||i.add(N,K.Added),N.addSelfToProject(i),l.push(N)}),this.inputs.sort((A,V)=>A.index-V.index);const{updated:v,added:T,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],t=[],y=[];this.outputs=this.initialData.outputs.reduce((V,N)=>{if(N.type===f.GenericReference){const k=_i(N,this.project);return k?[...V,k]:V}const j=ee(N,this.project);return y.push(j.index),j.setParent(this,null),j.initChildren(i),[...V,j]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter(V=>!this.outputs.find(N=>N.declaration.id===V.id));this.outputs.sort((V,N)=>V.index-N.index),v.forEach((V,N)=>{this.outputs.forEach(Y=>{Y.index>=V.index&&Y.index++});const j=y.includes(V.index)?this.outputs.length-1+N:V.index,k={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:V.toJSON(),defaultValue:null,writesValues:[],index:j,parent:this.toReference()},q=ee(k,this.project);q.setParent(this,i),q.initChildren(i),i==null||i.add(q,K.Added),q.addSelfToProject(i)}),this.outputs.sort((V,N)=>V.index-N.index);const{updated:T,added:w,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...w),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}};D(Mt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Mt,"type",f.FunctionCall),D(Mt,"USER_MANAGED_PARENT_TYPES",[...br,f.Project]),D(Mt,"PARENT_TYPES",[...Mt.USER_MANAGED_PARENT_TYPES]),D(Mt,"MUTABLE_BASE_PROPERTIES",[]),D(Mt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Mt,"BASE_PROPERTIES",[...Mt.MUTABLE_BASE_PROPERTIES,...Mt.INMUTABLE_BASE_PROPERTIES]),D(Mt,"MUTABLE_META_PROPERTIES",["x","y"]),D(Mt,"INMUTABLE_META_PROPERTIES",[...Mt.INMUTABLE_BASE_PROPERTIES]),D(Mt,"META_PROPERTIES",[...Mt.MUTABLE_META_PROPERTIES,...Mt.INMUTABLE_META_PROPERTIES]),D(Mt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),D(Mt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),D(Mt,"UPSTREAM_PROPERTIES",[...Mt.MUTABLE_UPSTREAM_PROPERTIES,...Mt.INMUTABLE_UPSTREAM_PROPERTIES]),D(Mt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),D(Mt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Mt,"DOWNSTREAM_PROPERTIES",[...Mt.MUTABLE_DOWNSTREAM_PROPERTIES,...Mt.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Mt,"PROPERTIES",[...Mt.META_PROPERTIES,...Mt.UPSTREAM_PROPERTIES,...Mt.DOWNSTREAM_PROPERTIES]);let za=Mt;function sA(d){return d&&typeof d.then=="function"}function pme(d){const u=new ha(d[0]),i=d.map(l=>l.id),a={};return d.forEach(l=>{a[l.id]=l}),u.order=i,u.flatRecord=a,u.orderEntities(),u.order.map(l=>u.flatRecord[l])}class ha{constructor(u){D(this,"order",[]);D(this,"flatRecord",{});D(this,"allBuiltInEntityIds",Ps());D(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Ps()),a=R(he(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const p of a)this.flatRecord[p.id]=p,l.add(p.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=Rd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),p=this.order.indexOf(u.id);if(l>p)return this.order.splice(p,1),this.order.splice(l,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let i=0;i<this.order.length;i++){const a=this.order[i],l=this.flatRecord[a];if(l||console.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(l)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,i){const{upstream:a}=Rd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([p,t])=>{Object.keys(a).includes(p)&&(l[p]=t)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(t=>Object.keys(Rd(this.flatRecord[t],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(l).forEach(t=>{t===u&&(p[t]=this.onGoingVisits[i][t])}),p}async settlePromises(u,i){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(l=>{delete this.onGoingVisits[i][l]})}visit(u){const i=this.order;for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const i=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const p=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const t=u(this.flatRecord[l],this.flatRecord);sA(t)&&(this.onGoingVisits[a][l]=t)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const i=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const p=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const t=u(this.flatRecord[l],this.flatRecord);sA(t)&&(this.onGoingVisits[a][l]=t)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function mj(d,u){switch(d.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(T=>T.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const T=v.properties.find(V=>V.implements&&V.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=T==null?void 0:T.getDefaultValue();return(w==null?void 0:w.value)===!0});if(!a&&i.length){const T=i[0].properties.find(A=>A.implements&&A.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=T==null?void 0:T.defaultValue;if(w)w.metaSync({value:!0},u);else if(T!=null&&T.dataType){const A={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:X.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},V=ee(A,d.project);return V.setParent(T,u),V.initChildren(u),u==null||u.add(V,K.Added),V.addSelfToProject(u),{newEntities:[V]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=Fy(l,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const t=p.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=t==null?void 0:t.defaultValue;if(y)y.metaSync({value:!0},u);else if(t!=null&&t.dataType){const v={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:X.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:t==null?void 0:t.toReference()},T=ee(v,d.project);T.setParent(t,u),T.initChildren(u),u==null||u.add(T,K.Added),T.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function vj(d,u){const i=[],a=[],l=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const T=d.project.entities.filter(N=>N.implements.find(j=>j.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let w=T.find(N=>!!N.properties.find(j=>{var k;return j.implements&&j.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((k=j.getDefaultValue())==null?void 0:k.value)===!0}));if(!w&&T.length)w=T[0];else if(!w&&!T.length){w=d.project.getBuiltIn(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const j=w.properties.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=j==null?void 0:j.defaultValue)==null||v.metaSync({value:!0},u),a.push(w)}const A=d.properties.find(N=>N.implements&&N.implements.id===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),V=A==null?void 0:A.defaultValue;if(A&&!V){const N={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:X.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(w==null?void 0:w.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},j=ee(N,d.project);j.hydrateAncestors(),j.setParent(A,u),j.addSelfToProject(u),j.initChildren(u),u==null||u.add(j,K.Added),a.push(j);return}else V&&!V.valueAsTypeSingle&&V.setValueAsTypeSingle(w||null,u);return}}}),{self:d,updated:R(i),added:R(a),removed:R(l),affected:R(p)}}function Fy(d,u,i,a){const l=a||P.UUID.uuid(),p=P.UUID.uuid(),t={id:l,version:p,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};mj(d,i);const y=ee(t,d.project);return y.hydrateAncestors(),i==null||i.add(y,K.Added),y.addSelfToProject(i),y.addImplementation(d),y.setParent(d.project,i),y.initChildren(i),vj(y,i),y}function nA(d,u){return u.entities.find(l=>{const p=l.properties,t=p.map(A=>A.name),y=d.every(A=>t.includes(A)),v=t.filter(A=>!d.includes(A)),T=p.every(A=>!v.includes(A.name)||!A.required);return y&&T})||null}function Ej(d,u,i,a=Zr.OrDataTypeGroup){const l=[],p=[],t=[],y=[],T={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},w=ee(T,d.project);return p.push(w),w.setParent(u,i),w.initChildren(i),i==null||i.add(w,K.Added),w.setEntity(d,i),w.addSelfToProject(i),{updated:R(l),added:R(p),removed:R(t),affected:R(y),self:w}}function aA(d,u,i,a,l){var T,w,A,V,N,j,k,q;const p=[],t=[],y=[],v=[];switch(typeof d){case"string":let Y=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(Y=!0),Y){const te=u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Date].id);u.setEntity(te,a);break}else{const te=u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.String].id);u.setEntity(te,a);break}case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const te=d.slice(0,5).filter(ne=>ne!==void 0);if(te.every(ne=>typeof ne==typeof te[0])&&(typeof te[0]!="object"||te[0]===null))switch(typeof te[0]){case"string":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Null].id),a);break}else{const ne=[];let me=!1;te.forEach(ae=>{var ce,H,de,ve;if(Array.isArray(ae)&&(me=!0),typeof ae=="object"&&!Array.isArray(ae)&&ae!==null){const Pe=Gy(ae,u.project,{...i,id:P.UUID.uuid()},a,l);Pe.hasCreated&&ne.push((ce=Pe.changeSet)==null?void 0:ce.self),p.push(...(H=Pe.changeSet)==null?void 0:H.updated),t.push(...(de=Pe.changeSet)==null?void 0:de.added),y.push(...(ve=Pe.changeSet)==null?void 0:ve.removed)}});const J=R(ne);if(!J.length&&!me){te.forEach(ae=>{const ce={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.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:Zr.OrDataTypeGroup,parent:u.toReference()},H=ee(ce,u.project);switch(H.setParent(u,a),H.initChildren(a),a==null||a.add(H,K.Added),H.addSelfToProject(a),typeof ae){case"string":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.String].id),a);break;case"number":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Number].id),a);break;case"boolean":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Boolean].id),a);break;case"object":H.setEntity(H.project.getBuiltIn(Ee[f.PrimitiveEntity][X.Null].id),a);break}});break}else J.length===1&&!me?u.setEntity(J[0],a):te.forEach(ae=>{if(typeof ae=="object"&&!Array.isArray(ae)&&ae!==null){const ce=nA(Object.keys(ae),u.project);if(ce){const H=Ej(ce||J[0],u,a,Zr.OrDataTypeGroup);p.push(...H.updated),t.push(...H.added),y.push(...H.removed)}}else{const ce={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(ae),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Zr.OrDataTypeGroup,parent:u.toReference()},H=ee(ce,u.project);H.setParent(u,a),H.initChildren(a),a==null||a.add(H,K.Added),H.addSelfToProject(a);const de=aA(ae,H,{...i,id:P.UUID.uuid()},a,l);p.push(...de.updated),t.push(...de.added),y.push(...de.removed)}})}}else{const te=Gy(d[0],u.project,{...i},a,l);u.setEntity((T=te.changeSet)==null?void 0:T.self,a),p.push(...(w=te.changeSet)==null?void 0:w.updated),t.push(...(A=te.changeSet)==null?void 0:A.added),y.push(...(V=te.changeSet)==null?void 0:V.removed);break}else{const te=Gy(d,u.project,{...i},a,l);u.setEntity((N=te.changeSet)==null?void 0:N.self,a),p.push(...(j=te.changeSet)==null?void 0:j.updated),t.push(...(k=te.changeSet)==null?void 0:k.added),y.push(...(q=te.changeSet)==null?void 0:q.removed);break}}return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:u}}function Gy(d,u,i,a,l){const p=[],t=[],y=[],v=[],T=Object.keys(d),w=nA(T,u);if(w)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:w}};const A=l?i.name+" of "+l.name:i.name,N={id:i.id||P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:u.toReference()},j=ee(N,u);return j.setParent(u,a),j.initChildren(a),a==null||a.add(j,K.Added),j.addSelfToProject(a),t.push(j),T.forEach((k,q)=>{const ie={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:k,type:f.Property,codeName:k,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,extends:null,index:q,hidden:!1,private:!1,required:!0,parent:j.toReference()},te=ee(ie,u);te.setParent(j,a),te.initChildren(a),a==null||a.add(te,K.Added),te.addSelfToProject(a),t.push(te);const pe=d[k],me={id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.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:te.toReference()},J=ee(me,u);J.setParent(te,a),J.initChildren(a),a==null||a.add(J,K.Added),J.addSelfToProject(a),t.push(J);const ae=aA(pe,J,{...i,name:k,id:P.UUID.uuid()},a,l||j);p.push(...ae.updated),t.push(...ae.added),y.push(...ae.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:j}}}function ya(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(p=>{const t=u.find(v=>v.name===p.name),y=u.find(v=>{var T,w;return!!p.implements&&((T=v.implements)==null?void 0:T.id)===((w=p.implements)==null?void 0:w.id)});if(t){const v=new qt({id:p.id+"--"+t.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${t.type} ${t.name} with id "${t.id}" that has the same name`,issue:null,severity:Z.Error,code:a,entity:p,firstRelationship:t});l.push(v)}if(y){const v=new qt({id:p.id+"--"+y.id+"--"+i,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,issue:null,severity:Z.Error,code:i,entity:p,firstRelationship:y});l.push(v)}}):u.forEach(p=>{var v;const t=d.find(T=>T.name===p.name),y=d.find(T=>{var w,A;return!!T.implements&&((w=T.implements)==null?void 0:w.id)===((A=p.implements)==null?void 0:A.id)});if(t){const T=new qt({id:t.id+"--"+p.id+"--"+a,message:`Entity of type ${t.type} named "${t.name}" with id "${t.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,issue:null,severity:Z.Error,code:a,entity:t,firstRelationship:p});l.push(T)}if(y){const T=new qt({id:y.id+"--"+p.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,issue:null,severity:Z.Error,code:i,entity:y,firstRelationship:p});l.push(T)}}),{errors:l,overlap:!!l.length})}function fme(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===gb.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function hme(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Qy.Implements||a.field===Qy.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function yme(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function mme(d,u){return d.static&&d.metaSync({static:!1},u),d}var Tj=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d))(Tj||{});function bj(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new qt({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces.`,issue:null,severity:Z.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function Aj(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new qt({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,issue:null,severity:Z.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}if(a.includes("-")){const l=new qt({id:d.id+"--string-value-must-not-have-dashes",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,issue:null,severity:Z.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function oA(d,u){var i;if(d.type===f.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${re(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof Hi||d.increaseVersion)return`${d.type}: ${d.id} (${yd(d)})`;try{const a=yd(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${re(d,u)})`}function wd(d,u){const i=Xa(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(p=>{if(p===u)return a=p,[p];const t=wd(p,u);return t.last&&(a=t.last),[p,...t.list]}),last:a}}function lA(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const p=Ri(l,d.project);return!p||p.type===f.Project?a:a.type===f.Project||wd(p,a).last?p:(wd(a,p).last,a)},d.project);return i.type===f.FunctionDeclaration&&i.parent.type===f.Loop?i.parent:i}function je(d,u){var l,p;let i=lA(d);if(d.type===f.InternalCall)(l=d.parent)==null||l.setParent(i,u),(p=d.parent)==null||p.addSelfToProject(u);else if((d.type===f.ContinueStatement||d.type===f.BreakStatement)&&i.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!br.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else d.setParent(i,u),d.addSelfToProject(u);if(rr.includes(d.type))return;ut(d).forEach(t=>{var v,T;const y=lA(t);if(t.type===f.InternalCall)(v=t.parent)==null||v.setParent(y,u),(T=t.parent)==null||T.addSelfToProject(u);else if((t.type===f.ContinueStatement||t.type===f.BreakStatement)&&y.type!==f.Loop){t.remove({ignoreUpstream:!1},u);return}else if(t.type===f.ReturnStatement&&!br.includes(y.type)){t.remove({ignoreUpstream:!1},u);return}else t.setParent(y,u),t.addSelfToProject(u)})}function Ky(d,u,i=new Set){const a=tn(d),l=tn(u),p=a.filter(v=>!l.includes(v)),t=a.filter(v=>l.includes(v)),y=p.reduce((v,T)=>i.has(T.id)?v:(i.add(T.id),R([...v,...Ky(T,u,i)])),[]);return R([...t,...y])}function Wo(d,u){const i=wd(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function dA(d,u){return!!wd(d,u).last}function vme(d){if(Wt.includes(d.type))return d;if([...ks,f.VariableDeclaration].includes(d.type)){const u=d.parent;return Wt.includes(u.type)?u:null}return null}function uA(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const i=d.parent;if(i){if(i===u)return u;if(i.type===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return uA(i,a)}function ur(d){if($f.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return ur(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType?ur(d.parent):d}else{const u=d.parent;return u?ur(u):null}}function ky(d,u){const i=Ap(d,u);if(!i)return null;if($f.includes(i.type)){if(i.type===f.FunctionDeclaration){const a=Ap(i.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}return i}else{const a=i.parent?Ap(i.parent,u):null;return a?ky(a,u):null}}function Ij(d){if(!d)return null;if(ks.includes(d.type))return d;const u=d.parent;return u?Ij(u):null}function wj(d){if(!d)return null;if(Xt.includes(d.type))return d;const u=d.parent;return u?wj(u):null}function Rj(d){if(!d)return null;if(qs.includes(d.type))return d;const u=d.parent;return u?Rj(u):null}function _j(d){return d.type===f.VariableDeclaration?[d]:Xt.includes(d.type)?[...d.inputs,...d.outputs||[]]:rr.includes(d.type)?d.outputs:Dl.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function Eme(d){const u=tn(d),i=[],a=[];lR.includes(d.type)&&i.push(...qy(d));const l=u.filter(p=>{const t=i.includes(p);return t?!1:ks.includes(p.type)&&!t?(a.push(p),!1):!0});return i.sort((p,t)=>Wo(t,p)?-1:0),a.sort((p,t)=>Wo(t,p)?-1:0),[...i,...a,...l]}function gj(d){return[...d].sort((u,i)=>Wo(i,u)?-1:0)}function cA(d){const u=gj(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const p=l[l.length-1];Wo(a,p)?i.push([a]):l.push(a)}else i.push([a])}),i}function zr(d){const u=d.map(i=>ur(i));return R(u)}function qy(d){return Xt.includes(d.type)?[...zr(d.successCalls),...zr(d.errorCalls)]:Wt.includes(d.type)?zr(d.calls):[]}function Tme(d,u){return qy(d).includes(u)}function pA(d){return d.writesValues||[]}function bme(d,u){return pA(d).includes(u)}function Dj(d){var u;return rt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function Ame(d){return d.writesValues}function Oj(d=[]){return d.map(Dj).filter(u=>!!u)}function Sy(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>rt.includes(u.type))}function Cj(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&rt.includes(u.type))}function $j(d){return rt.includes(d.type)?d:null}function Pj(d){return d.writesValues.map($j).filter(u=>!!u)}function Vj(d=[]){return d.reduce((u,i)=>i.type===f.OutputMap?[...u,...Pj(i)]:u,[])}function ut(d){return d.type===f.Loop?R([...$s(zr(d.successCalls)),...$s(zr(d.errorCalls)),...d.body?ut(d.body):[]]):Xt.includes(d.type)?R([...$s(zr(d.successCalls)),...$s(zr(d.errorCalls))]):Wt.includes(d.type)?R($s(zr(d.calls))):[]}function Ime(d){return Xt.includes(d.type)?[...$s(zr(d.successCalls)),...$s(zr(d.errorCalls))]:Wt.includes(d.type)?$s(zr(d.calls)):[]}function Nj(d,u=new Set){return d.writesValues.filter(a=>rt.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Ht(l,u)],[])}function Lj(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>rt.includes(l.type)&&!u.has(l.id)).reduce((l,p)=>u.has(p.id)?l:[...l,...Ht(p,u)],[])}function Ht(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return Cj(d.outputs).reduce((a,l)=>[...a,...Ht(l,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[...ut(d).reduce((p,t)=>{const y=ur(t);return[...p,...Ht(y||t,u)]},[]),...Oj(d.inputs),...Vj(d.outputs)].reduce((p,t)=>[...p,...Ht(t,u)],[]);if(Dl.includes(d.type)){const i=Sy(d.inputs),l=ut(d).reduce((p,t)=>{const y=ur(t);return[...p,...Ht(y||t,u)]},[]);return i.push(...l),i.reduce((p,t)=>[...p,...Ht(t,u)],[])}if(d.type===f.FunctionDeclaration){const i=[...Sy(d.inputs)],l=ut(d).reduce((p,t)=>{const y=ur(t);return[...p,...Ht(y||t,u)]},[]);return i.push(...l),i.reduce((p,t)=>[...p,...Ht(t)],[])}if(rt.includes(d.type)){u.add(d.id);const a=ut(d).reduce((l,p)=>{const t=ur(p);return[...l,...Ht(t||p,u)]},[]);return[d,...a,...Lj(d,u),...Nj(d,u)]}return[]}function Xi(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...tn(d).reduce((l,p)=>[...l,p,...Xi(p,u)],[])])}function $s(d){return d.reduce((u,i)=>i.type===f.ReturnStatement||i.type===f.ContinueStatement||i.type===f.BreakStatement?[...u,i]:[...u,i,...ut(i)],[])}function Bj(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,T)=>[...v,...T.properties],[]),l=u.reduce((v,T)=>[...v,...T.methods],[]),p=l.reduce((v,T)=>[...v,...Sy(T.inputs),...$s(zr(T.calls)),...T.returnStatements],[]),t=d.functions.reduce((v,T)=>[...v,...$s(zr(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...$s(zr(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...p,...t,...y]}function Mj(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(l=>l.id===d.id)!==void 0||a.outputs.find(l=>l.id===d.id)!==void 0;case f.Condition:return a.successCalls.find(l=>l.id===d.id)!==void 0||a.errorCalls.find(l=>l.id===d.id)!==void 0||a.inputs.find(l=>l.id===d.id)!==void 0;case f.Operation:return a.outputs.find(l=>l.id===d.id)!==void 0;case f.VariableDeclaration:return Xt.includes(d.type)?cx(d).find(p=>{var t;return((t=p.readsValue)==null?void 0:t.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(l=>l.id===d.id)!==void 0||a.methods.find(l=>l.id===d.id)!==void 0;case f.FunctionDeclaration:return a.inputs.find(l=>l.id===d.id)!==void 0||(a.returnStatements.map(l=>l.outputs).flat()||[]).find(l=>l.id===d.id)!==void 0;default:return!1}})}function wme(d){const u=Bj(d.project);return Mj(d,u)}function Ap(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function Uj(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,p=d[a];i[l]=p}),i}function Rd(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(ki.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const l=d,p=d,t=d,y=d,v=d,T=d,w=d,A=d,V=d,N=d,j=d,k=d,q=d,Y=[...q.readsValue?[q.readsValue]:[],...q.declaration?[q.declaration]:[],...(k.calledByEntry||[]).flatMap(ne=>ne),...(k.calledBySuccess||[]).flatMap(ne=>ne),...(k.calledByError||[]).flatMap(ne=>ne),...N.parent?[N.parent]:[]];Array.isArray(t.implements)?Y.push(...t.implements.flatMap(ne=>ne)):V.implements&&Y.push(V.implements),Array.isArray(t.extends)?Y.push(...t.extends.flatMap(ne=>ne)):V.extends&&Y.push(V.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&Y.push(...v.valueAsTypeList.flatMap(ne=>ne)),v.valueAsTypeSingle&&Y.push(v.valueAsTypeSingle);const ie=[...(l.inputs||[]).flatMap(ne=>ne),...(j.inputsDeclarations||[]).flatMap(ne=>ne),...(l.outputs||[]).flatMap(ne=>ne),...(j.outputsDeclarations||[]).flatMap(ne=>ne),...(q.internalCalls||[]).flatMap(ne=>ne),...q.writesValues||[],...k.dataType?[k.dataType]:[],...T.body?[T.body]:[],...k.defaultValue?[k.defaultValue]:[],...(k.successCalls||[]).flatMap(ne=>ne),...(k.errorCalls||[]).flatMap(ne=>ne),...(t.properties||[]).flatMap(ne=>ne),...(t.methods||[]).flatMap(ne=>ne),...(t.abstractMethods||[]).flatMap(ne=>ne),...w.error?[w.error]:[],...w.process?[w.process]:[],...N.throws?[N.throws]:[],...(p.andChildrenGroup||[]).flatMap(ne=>ne),...(p.orChildrenGroup||[]).flatMap(ne=>ne),...(A.entities||[]).flatMap(ne=>ne),...(A.functions||[]).flatMap(ne=>ne),...(A.functionCalls||[]).flatMap(ne=>ne),...(A.events||[]).flatMap(ne=>ne),...(A.conditions||[]).flatMap(ne=>ne),...(A.operations||[]).flatMap(ne=>ne),...(A.loops||[]).flatMap(ne=>ne),...(A.variableDeclarations||[]).flatMap(ne=>ne),...(A.variableInstances||[]).flatMap(ne=>ne),...(A.searches||[]).flatMap(ne=>ne),...(A.projects||[]).flatMap(ne=>ne),...(y.calls||[]).flatMap(ne=>ne)];d.type===f.DataType&&(p.entity&&u[W(p.entity)]&&u[W(p.entity)].parent&&W(u[W(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&Y.push(p.entity));const te={},pe={};return Y.forEach(ne=>{var ae;const me=W(ne);if(me&&a.ignoreBuiltInBaseEntities&&(ki.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(me)))return;const J=ne.version;if(me){const ce=((ae=a.entityMaps)==null?void 0:ae.get(me))||me;te[ce]=J}}),ie.forEach(ne=>{var ae;const me=W(ne);if(me&&a.ignoreBuiltInBaseEntities&&(ki.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(me)))return;const J=ne.version;if(me){const ce=((ae=a.entityMaps)==null?void 0:ae.get(me))||me;pe[ce]=J}}),{upstream:te,downstream:pe}}function Rme(d,u){const i=[];if(ks.includes(d.type)){ys(d).forEach(p=>{const t=ky(p,u);t&&i.push(t)});const l=[...d.inputs||[],...d.outputs||[]].map(p=>{const t=Ap(p,u);return t?fx(t,u):null}).filter(p=>p!==null);i.push(...R(l))}if(rt.includes(d.type)){const a=Zy(d);a&&i.push(a)}return R(i)}function Xa(d){const u=[];if(ks.includes(d.type)){d.calledBy.forEach(l=>{const p=ur(l);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>Zy(l)).filter(l=>l!==null);u.push(...R(a))}if(rt.includes(d.type)){const i=Zy(d);i&&u.push(i)}return R(u)}function ys(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function jj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>he(a,u,i)),...d.outputs.flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.parent?he(d.parent,u,i):[]]}function xj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?he(d.defaultValue,u):[],...d.writesValues.flatMap(a=>he(a,u,i)),...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Fj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>he(a,u,i)),...d.throws?he(d.throws,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function Gj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>he(a,u,i)),...(d.methods||[]).flatMap(a=>he(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>he(a,u,i)),...(d.extends||[]).flatMap(a=>he(a,u,i))]}function Kj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function kj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>he(a,u,i)),...d.throws?he(d.throws,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function qj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...(d.extends||[]).flatMap(a=>he(a,u,i)),...(d.implements||[]).flatMap(a=>he(a,u,i)),...(d.properties||[]).flatMap(a=>he(a,u,i)),...(d.methods||[]).flatMap(a=>he(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function Sj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>he(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>he(a,u,i)),...d.entity?he(d.entity,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Zj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function Jj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.calls||[]).flatMap(a=>he(a,u,i)),...d.implements?he(d.implements,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Wj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.calls||[]).flatMap(a=>he(a,u,i)),...d.implements?he(d.implements,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Yj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?he(d.readsValue,u,i):[],...d.declaration?he(d.declaration,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Hj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>he(a,u,i)),...(d.events||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function zj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Xj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?he(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>he(a,u,i)):[],...d.parent?he(d.parent,u,i):[]]}function Qj(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...d.body?he(d.body,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function ex(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...d.process?he(d.process,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function tx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>he(a,u,i)),...d.declaration?he(d.declaration,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...d.parent?he(d.parent,u,i):[]]}function rx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>he(a,u,i)),...(d.methods||[]).flatMap(a=>he(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>he(a,u,i))]}function ix(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>he(a,u,i)),...(d.functions||[]).flatMap(a=>he(a,u,i)),...(d.events||[]).flatMap(a=>he(a,u,i)),...(d.projects||[]).flatMap(a=>he(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>he(a,u,i)),...(d.variableInstances||[]).flatMap(a=>he(a,u,i)),...(d.operations||[]).flatMap(a=>he(a,u,i)),...(d.conditions||[]).flatMap(a=>he(a,u,i)),...(d.functionCalls||[]).flatMap(a=>he(a,u,i)),...(d.projects||[]).flatMap(a=>he(a,u,i)),...(d.loops||[]).flatMap(a=>he(a,u,i)),...(d.searches||[]).flatMap(a=>he(a,u,i))]}function sx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?he(d.defaultValue,u,i):[],...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function nx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?he(d.readsValue,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function ax(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.throws?he(d.throws,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function ox(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputsDeclarations||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...d.error?he(d.error,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.parent?he(d.parent,u,i):[]]}function lx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?he(d.defaultValue,u,i):[],...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function dx(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(d.internalCalls||[]).flatMap(a=>he(a,u,i)),...(d.writesValues||[]).flatMap(a=>he(a,u,i)),...d.readsValue?he(d.readsValue,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.dataType?he(d.dataType,u,i):[],...d.parent?he(d.parent,u,i):[]]}function ux(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>he(a,u,i)),...(d.errorCalls||[]).flatMap(a=>he(a,u,i)),...(d.inputs||[]).flatMap(a=>he(a,u,i)),...(d.outputs||[]).flatMap(a=>he(a,u,i)),...(d.internalCalls||[]).flatMap(a=>he(a,u,i)),...(d.writesValues||[]).flatMap(a=>he(a,u,i)),...d.readsValue?he(d.readsValue,u,i):[],...d.defaultValue?he(d.defaultValue,u,i):[],...(ys(d)||[]).flatMap(a=>he(a,u,i)),...d.declaration?he(d.declaration,u,i):[],...d.parent?he(d.parent,u,i):[]]}function Ps(){const d=new Set,u=pV.flatMap(i=>he(i,d)).map(i=>i.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function he(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(ki.includes(d.type)||Ps().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return Zj(d,u,i);case f.Operation:return ex(d,u,i);case f.Condition:return Kj(d,u,i);case f.Loop:return Qj(d,u,i);case f.Search:return ox(d,u,i);case f.GlobalEvent:return Wj(d,u,i);case f.ReturnStatement:return ax(d,u,i);case f.ContinueStatement:return kj(d,u,i);case f.BreakStatement:return Fj(d,u,i);case f.VariableDeclaration:return dx(d,u,i);case f.DefinitionEntity:return qj(d,u,i);case f.FunctionDeclaration:return Jj(d,u,i);case f.Project:return ix(d,u,i);case f.ActionDescriptor:return jj(d,u,i);case f.ArgumentDeclaration:return xj(d,u,i);case f.ReturnDeclaration:return nx(d,u,i);case f.ValueDescriptor:return lx(d,u,i);case f.InputMap:return Yj(d,u,i);case f.OutputMap:return tx(d,u,i);case f.DataType:return Sj(d,u,i);case f.InstalledProject:return Hj(d,u,i);case f.InternalCall:return zj(d,u,i);case f.LiteralValue:return Xj(d,u,i);case f.Property:return sx(d,u,i);case f.VariableInstance:return ux(d,u,i);case f.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:Gj(d,u,i);case f.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:rx(d,u,i)}return[]}function fA(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||Dl.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function _me(d,u){return u.type===f.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function cx(d){return Xt.includes(d.type)?d.inputs:[]}function px(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:rr.includes(d.type)?d.outputs:[]}function gme(d,u){return u.type===f.Condition?null:u.type===f.FunctionCall||u.type===f.Operation?u.outputs.find(i=>i.declaration.id===d.id):null}function Dme(d){return d.type===f.Condition?[]:Xt.includes(d.type)?d.outputs:[]}function Zy(d){const u=d.readsValue;return u?ur(u):null}function fx(d,u){const i=d.readsValue;return i?ky(i,u):null}function hx(d){const u=d.internalCalls||[];return R(zr(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function _d(d){const u=pA(d),i=[];return u.forEach(a=>{if(rt.includes(a.type))i.push(a);else if(Jn.includes(a.type)){const l=a.parent;i.push(l)}}),i}function R(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function tn(d,u=!1){const i=[];if(d.type===f.Project&&i.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),br.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:tn(l));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>ur(p)),l=d.errorCalls.map(p=>ur(p));i.push(...a,...l)}if(Dl.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>_d(p)).flat(),l=d.calls.map(p=>ur(p));i.push(...R(a),...l)}if(Xt.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(t=>_d(t)).flat(),l=d.successCalls.map(t=>ur(t)),p=d.errorCalls.map(t=>ur(t));i.push(...R(a),...l,...p)}if(rt.includes(d.type)){const a=_d(d),l=hx(d);i.push(...a,...l)}if(d.type===f.Loop){const a=d.outputs.map(t=>_d(t)).flat();if(d.body){const t=tn(d.body,u);i.push(...t)}const l=d.errorCalls.map(t=>ur(t)),p=d.successCalls.map(t=>ur(t));i.push(...R(a),...p,...l)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>_d(p)).flat(),l=d.calls.map(p=>ur(p));i.push(...R(a),...l)}return R(i)}function Jy(d,u=!1){const i=tn(d,u),a=[...i,...i.reduce((l,p)=>[...l,...Jy(p,u)],[])];return R(a)}function yx(d){const u=Xa(d),i=[...u,...u.reduce((a,l)=>[...a,...yx(l)],[])];return R(i)}function Ip(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...Ip(i),...wp(i)]:[...u,i.name],[])}function wp(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...wp(i),...Ip(i)]:[...u,i.name],[])}function hA(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...hA(i),...yA(i)]:[...u,i],[])}function yA(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...yA(i),...hA(i)]:[...u,i],[])}function gd(d){return[...wp(d),...Ip(d)].filter((i,a,l)=>l.indexOf(i)===a)}function mA(d){return d.implements.length===0&&d.extends.length===0?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===$e.PERSISTED_ENTITY)?d:[...d.implements,...d.extends].reduce((a,l)=>{if(l.type===f.DefinitionEntity){const p=mA(l);if(p)return p}return a},null)}function Ome(d){const u=d.extends.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Cme(d){const u=d.implements.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Wy(d){const u=d.extends.find(i=>i.type===f.DefinitionEntity);return u&&u.type===f.DefinitionEntity?u:null}function wi(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends].reduce((i,a)=>a.type===f.BuiltInBaseEntity?[...i,a]:a.type===f.DefinitionEntity?[...i,...wi(a)]:i,[]);return R(u)}function Rp(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!wi(d).find(a=>!a.interactive)}function $me(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function vA(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function mx(d){if([...Wt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||vA(d))return!1;const u=Xa(d);return u.length===0?!0:u.some(i=>mx(i))}function EA(d){return[...Wt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||vA(d)?!1:Xa(d).length===0}function vx(d,u=0){if(EA(d)){const i=Xa(d);return i.length===0?d:i.map(l=>vx(l,u+1)).reduce((l,p)=>l?p&&p.x<l.x?p:l:p,null)}return null}function Ex(d){const u=[];if(EA(d))u.push(d);else return[];return Xa(d).forEach(a=>{u.push(...Ex(a))}),u}function TA(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function Pme(d,u){const i=new Map;return d.forEach(a=>{i.set(a.id,a)}),u.forEach(a=>{i.set(a.id,a)}),Array.from(i.values())}function _p(d){switch(d){case f.DefinitionEntity:return ma;case f.FunctionDeclaration:return Ua;case f.VariableDeclaration:return ka;case f.VariableInstance:return Ka;case f.FunctionCall:return za;case f.Operation:return ja;case f.Condition:return Ga;case f.ReturnStatement:return xa;case f.Loop:return Ai;case f.Search:return qa;case f.InputMap:return Cs;case f.OutputMap:return Qs;case f.ArgumentDeclaration:return pa;case f.ReturnDeclaration:return Ni;case f.Property:return ua;case f.InstalledProject:return Sa;case f.Project:return P;case f.DataType:return Hi;case f.GlobalEvent:return Fa;case f.InternalCall:return Za;case f.ValueDescriptor:return en;case f.BuiltInBaseEntity:return Cn;case f.PrimitiveEntity:return Li;case f.ActionDescriptor:return jt;case f.LiteralValue:return bi;case f.ContinueStatement:return li;case f.BreakStatement:return Ja;default:return null}}function Ri(d,u,i=null){const a=d!=null&&d.parent?W(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if(d.type===f.ReturnStatement)return $r(d,u,p);if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return l;if(Wt.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?l:d;if(ki.includes(d.type))return null;const t=d.parent;if(!t)return null;if(t.type===f.GenericReference){const y=W(t);if(!y)return null;const v=u.get(y);return v?Ri(v,u,p):null}else return t===u?u:Ri(t,u,p)}function $r(d,u,i=null){const a=d!=null&&d.parent?W(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return $r(l.parent,u,p);if(Wt.includes(d.type))return d;if(ki.includes(d.type))return null;const t=d.parent;if(!t)return null;if(t.type===f.GenericReference){const y=W(t);if(!y)return null;const v=u.get(y);return v?$r(v,u,p):null}else return t===u?u:$r(t,u,p)}function bA(d,u){if(ki.includes(d.type)||u.getBuiltIn(d.id))return null;const i=_i(d.parent,u);return i?i===u?br.includes(d.type)?d:null:i.type===f.DefinitionEntity?d:bA(i,u):null}function Yy(d,u,i){if(d===u||u===i||d===i)return!1;const a=Ri(u.parent,i);return a===d?!0:Yy(a,u,i)}var Hy=(d=>(d.SameBothLocal="same-both-local",d.AInB="a-in-b",d.BInA="b-in-a",d.ParallelInCommonParent="parallel-in-common-parent",d.ParallelInProject="parallel-in-project",d.AIsGlobalBIsNot="a-is-global-b-is-not",d.BIsGlobalAIsNot="b-is-global-a-is-not",d.SameBothGlobal="same-both-global",d))(Hy||{});function gp(d,u,i){const a=Ri(d,i),l=Ri(u,i);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!l)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===l&&a.type!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===l&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&l.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&l.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:l};if(Yy(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Yy(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=uA(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Ri(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function Tx(d,u,i){const a=gp(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=Ri(d.parent,i);if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;for(;l;){if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;l=Ri(l.parent,i)}let p=Ri(u.parent,i);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Ri(p.parent,i)}return null}function bx(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=Tx(i,a,a.project);return!l||l===a?i:a},d[0])}function _i(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===f.GenericReference?i=W(d):i=d.id,i===u.id?u:u.get(i)}function Qa(d){if(!d)return null;if(ki.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:Qa(u)}function Dp(d){const u=[];function i(p,t){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===t)}function a(p,t){i(p,t)||u.push({blockedByCaller:p,blockedByCalling:t})}const l=bA(d,d.project);return d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{rr.includes(v.type)&&v!==d&&(ut(d).find(A=>A===v)||a(p,v))});let y;if(Xt.includes(p.type)&&(y=p),y){const v=Dp(y);v.reachable||ut(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{rr.includes(v.type)&&v!==d&&(ut(d).find(A=>A===v)||a(p,v))});let y;if(Xt.includes(p.type)&&(y=p),y){const v=Dp(y);v.reachable||ut(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{rr.includes(v.type)&&v!==d&&(ut(d).find(A=>A===v)||a(p,v))}),p===l)return;let y;if(p.type===f.FunctionDeclaration){const v=ur(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=Dp(y);v.reachable||v.blocks.forEach(T=>{a(p,T.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}}function Vme(d){return $f.includes(d.type)?d.type===f.FunctionDeclaration?!TA(d):!0:!1}function Nme(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function zy(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!wp(d).includes(u)}function Lme(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!Ip(d).includes(u)}function Vs(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!gd(d).includes(u)}function Bme(d){const u=[];return d.entities.forEach(i=>{if(zy(i,$e.PERSISTED_ENTITY)){u.push(i);return}}),R(u)}function Mme(d){const u=[];return d.entities.forEach(i=>{if(zy(i,$e.RELATIONAL_DATABASE)){u.push(i);return}}),R(u)}function Ume(d){return d.type!==f.DefinitionEntity||d.abstract||!zy(d,$e.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>{var a;return((a=i.implements)==null?void 0:a.id)===Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.primaryKey.id&&!i.abstract}))||null}function Ax(d){var a;const u=mA(d);if(!u)return null;const i=u.properties.find(l=>{var p;return((p=l.implements)==null?void 0:p.id)===Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.database.id});return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function Dd(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!Vs(d,$e.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>{var l;return((l=a.implements)==null?void 0:l.id)!==Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...i),u}function jme(d){var i;if(!d||d.type!==f.DefinitionEntity||!Vs(d,$e.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var l;return((l=a.implements)==null?void 0:l.id)===Ee[f.BuiltInBaseEntity][$e.PERSISTED_ENTITY].properties.database.id});return(i=u==null?void 0:u.getDefaultValue())==null?void 0:i.valueAsTypeSingle}function Ir(d,u){var a;if(!cR.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===f.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function xme(d){switch(d){case f.Project:return P;case f.InstalledProject:return Sa;case f.DefinitionEntity:return ma;case f.FunctionDeclaration:return Ua;case f.GlobalEvent:return Fa;case f.VariableInstance:return Ka;case f.VariableDeclaration:return ka;case f.InputMap:return Cs;case f.OutputMap:return Qs;case f.Condition:return Ga;case f.Operation:return ja;case f.FunctionCall:return za;case f.ReturnDeclaration:return Ni;case f.ArgumentDeclaration:return pa;case f.PrimitiveEntity:return Li;case f.DataType:return Hi;case f.Property:return ua;case f.ActionDescriptor:return jt;case f.ReturnStatement:return xa;case f.ContinueStatement:return li;case f.BreakStatement:return Ja;case f.Loop:return Ai;case f.Search:return qa;case f.ValueDescriptor:return en;case f.InternalCall:return Za;case f.LiteralValue:return bi}return null}function Fme(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(i=>{u.added[i.id]=i}),d==null||d.updated.forEach(i=>{u.updated[i.id]=i}),d==null||d.removed.forEach(i=>{u.removed[i.id]=i}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(i=>i.id))),u}function Er(d,u){const i=_p(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const p=d[l],t=u[l];return t===void 0||p===t?!0:Array.isArray(p)&&Array.isArray(t)?p.length!==t.length?!1:p.every((y,v)=>y===t[v]):!1}):!1}function Xy(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const i=W(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...Xy(a,u)]:[]}function Gme(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=ur(a);!l||i.has(l.id)||(i.add(l.id),u.push(l))}),R(u)}function Kme(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(Ee["value-descriptor"][Ol.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function Ix(d){const u=d.entities.filter(l=>!!l.implements.find(p=>p.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const p=l.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),t=p==null?void 0:p.getDefaultValue();return(t==null?void 0:t.value)===!0});return i||u[0]||null}function AA(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Ps()]));return!!(i.includes(d.id)||!Xy(d,{...u.instances,...u.builtInInstances}).every(p=>!i.includes(p)))}function wx(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?wx(u):d.id}function Rx(d){const u=Vce(),i=d.toJSON();u.safeParse(i).success;const l=d.implements.flatMap(w=>kme(d,w)),p=d.extends.flatMap(w=>qme(d,w)),t=Zme(d),y=Sme(d);d.methods.flatMap(w=>w.validate());const v=[...l,...p,...t,...y];return zt(d.errors,v)}function _x(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let l=[...d.properties];return i.forEach(p=>{const t=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});t?l=l.filter(y=>y.id!==t.id):a.push(p)}),a}function gx(d,u){const i=u.abstractMethods,a=[];let l=[...d.methods];return i.forEach(p=>{const t=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});t?l=l.filter(y=>y.id!==t.id):a.push(p)}),a}function kme(d,u){const i=[];if(!u.abstract){const w=nt({id:d.id+"--"+se.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),l=[];let p=[...d.properties];a.forEach(w=>{const A=p.find(V=>{var N;return((N=V.implements)==null?void 0:N.id)===w.id});A?p=p.filter(V=>V.id!==A.id):l.push(w)}),l.length&&l.forEach(w=>{const A=nt({id:d.id+"--"+se.MissingPropertyImplementation+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:Z.Error,code:se.MissingPropertyImplementation,entity:d});i.push(A.error)});const t=[];let y=[...d.methods];u.abstractMethods.forEach(w=>{const A=y.find(V=>{var N;return((N=V.implements)==null?void 0:N.id)===w.id});A?y=y.filter(V=>V.id!==A.id):t.push(w)}),t.length&&t.forEach(w=>{const A=nt({id:d.id+"--"+se.MissingMethodImplementation+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:Z.Error,code:se.MissingMethodImplementation,entity:d});i.push(A.error)});const v=[];u.properties.forEach(w=>{const A=p.find(V=>V.name===w.name);A&&v.push([A,w])}),v.length&&v.forEach(([w])=>{const A=nt({id:d.id+"--"+oe.PropertyOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)});const T=[];return u.methods.forEach(w=>{const A=y.find(V=>V.name===w.name);A&&T.push([A,w])}),T.length&&T.forEach(([w])=>{const A=nt({id:d.id+"--"+oe.MethodOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function qme(d,u){const i=[],a=[];if(!d.abstract&&u.abstract){const p=nt({id:d.id+"--"+u.id+"--"+se.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=nt({id:d.id+"--"+u.id+"--"+se.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}d.properties.forEach(p=>{var y;const t=u.properties.find(v=>{var T;return v.name===p.name&&((T=p.extends)==null?void 0:T.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(t==null?void 0:t.id)&&t&&a.push(p)}),a.length&&a.forEach(p=>{const t=nt({id:d.id+"--"+oe.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(t.error)});const l=[];return d.methods.forEach(p=>{var y;const t=u.methods.find(v=>{var T;return v.name===p.name&&((T=p.extends)==null?void 0:T.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(t==null?void 0:t.id)&&t&&l.push(p)}),l.length&&l.forEach(p=>{const t=nt({id:d.id+"--"+oe.MethodOverwritesOtherSiblingWithSameName,message:`Method "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:oe.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(t.error)}),i}function Sme(d){const u=[];if(!d.properties.length){const i=nt({id:d.id+"--"+se.NoProperties,message:"No properties implemented",issue:null,severity:Z.Warning,code:se.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function Zme(d){const u=[];if(d.abstract){if(d.methods.length){const i=nt({id:d.id+"--"+se.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:Z.Error,code:se.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=nt({id:d.id+"--"+se.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:Z.Error,code:se.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const l=nt({id:d.id+"--"+se.StaticEntityWithNonStaticProperties+"--"+a.id,message:`Property "${a.name}" with id "${a.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:Z.Error,code:se.StaticEntityWithNonStaticProperties,entity:d});u.push(l.error)}})}}else{if(d.abstractMethods.length){const i=nt({id:d.id+"--"+se.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,issue:null,severity:Z.Error,code:se.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=nt({id:d.id+"--"+se.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:Z.Error,code:se.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});u.push(a.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const a=nt({id:d.id+"--"+se.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,issue:null,severity:Z.Error,code:se.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function Jme(d,u){const i=[],a=wi(u);if(!u.abstract){const t=new qt({id:d.id+"--"+u.id+"--"+se.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(t)}const l=d.implements.filter(t=>t.id!==u.id);if(d.abstract){const t=new qt({id:d.id+"--"+u.id+"--"+se.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(t)}if(d.static&&!u.static){const t=new qt({id:d.id+"--"+u.id+"--"+se.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(t)}if(!d.static&&u.static){const t=new qt({id:d.id+"--"+u.id+"--"+se.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(t)}return l.length&&l.forEach(t=>{if(t.type===f.BuiltInBaseEntity){const y=a.filter(v=>v.id!==t.id);y.length&&y.forEach(v=>{if(v.id!==t.id){const T=new qt({id:d.id+"--"+v.id+"--"+t.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${t.name}" with id "${t.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:t});i.push(T)}})}else{wi(t).forEach(w=>{const A=a.filter(V=>V.id!==w.id);A.length&&A.forEach(V=>{if(V.id!==w.id){const N=new qt({id:d.id+"--"+V.id+"--"+w.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:w});i.push(N)}})});const v=ya(u.ownDeclaredProperties,t.ownDeclaredProperties,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const T=ya(u.abstractMethods,[...t.abstractMethods,...t.methods],oe.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,oe.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...T.errors)}}),R(d.extends.flatMap(t=>wi(t))).forEach(t=>{if(!a.find(y=>y.id===t.id)){const y=new qt({id:d.id+"--"+u.id+"--"+t.id+"--"+se.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${u.name}" with id "${u.id}" but also extends entity "${t.name}" with id "${t.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:t});i.push(y)}}),i}function Wme(d,u,i=!1){const a=[],l=wi(u);if(!d.abstract&&u.abstract){const w=nt({id:d.id+"--"+u.id+"--"+se.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.abstract&&!u.abstract){const w=nt({id:d.id+"--"+u.id+"--"+se.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!d.static&&u.static){const w=nt({id:d.id+"--"+u.id+"--"+se.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.static&&!u.static){const w=nt({id:d.id+"--"+u.id+"--"+se.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!Rp(u)){const w=nt({id:d.id+"--"+u.id+"--"+se.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,issue:null,severity:Z.Error,code:se.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(w.error)}const t=d.extends.filter(w=>w.id!==u.id);t.length&&t.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter(V=>V.id!==w.id);A.length&&A.forEach(V=>{if(V.id!==w.id){const N=nt({id:d.id+"--"+V.id+"--"+w.id+"--"+se.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${V.name}" with id "${V.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ExtendsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:w});a.push(N.error)}})}else{wi(w).forEach(Y=>{const ie=l.filter(te=>te.id!==Y.id);ie.length&&ie.forEach(te=>{if(te.id!==Y.id){const pe=new qt({id:d.id+"--"+te.id+"--"+Y.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${te.name}" with id "${te.id}" but also extends or implements entity "${Y.name}" with id "${Y.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:te,secondRelationship:Y});a.push(pe)}})});const V=!!wi(w).find(Y=>Y.id===u.id);let N=[...w.properties];V&&(N=N.filter(Y=>!u.properties.find(ie=>{var te;return ie.id===Y.id||ie.name===Y.name||ie.id===((te=Y.implements)==null?void 0:te.id)})));let j=[...w.methods];V&&(j=j.filter(Y=>!u.methods.find(ie=>{var te;return ie.id===Y.id||ie.name===Y.name||ie.id===((te=Y.implements)==null?void 0:te.id)})));const k=ya(u.ownDeclaredProperties,N,oe.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,oe.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...k.errors);const q=ya(u.abstractMethods,j,oe.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,oe.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...q.errors)}}),i&&console.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter(V=>V.id!==w.id);A.length&&A.forEach(V=>{if(V.id!==w.id){const N=new qt({id:d.id+"--"+V.id+"--"+w.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:w});a.push(N)}})}else{wi(w).forEach(j=>{const k=l.filter(q=>q.id!==j.id);k.length&&k.forEach(q=>{if(q.id!==j.id){const Y=new qt({id:d.id+"--"+q.id+"--"+j.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${q.name}" with id "${q.id}" but also implements entity "${j.name}" with id "${j.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:q,secondRelationship:j});a.push(Y)}})});const V=ya(u.ownDeclaredProperties,w.ownDeclaredProperties,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,oe.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...V.errors);const N=ya(u.abstractMethods,[...w.abstractMethods,...w.methods],oe.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,oe.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...N.errors)}});const y=ya(d.ownDeclaredProperties,u.ownDeclaredProperties,oe.PropertyOverwritesOtherSiblingWithSameImplementation,oe.PropertyOverwritesOtherSiblingWithSameName);a.push(...y.errors);const v=ya(u.methods,u.abstractMethods,oe.MethodOverwritesOtherSiblingWithSameImplementation,oe.MethodOverwritesOtherSiblingWithSameName);return a.push(...v.errors),R(d.extends.flatMap(w=>wi(w))).forEach(w=>{if(!l.find(A=>A.id===w.id)){const A=new qt({id:d.id+"--"+u.id+"--"+w.id+"--"+se.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:Z.Error,code:se.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:w});a.push(A)}}),a}function Yme(d){const u=[];return d.implements.forEach(i=>{if(!i.static){const a=new qt({id:d.id+"--"+i.id+"--"+se.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:Z.Error,code:se.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends.forEach(i=>{if(!i.static){const a=new qt({id:d.id+"--"+i.id+"--"+se.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:Z.Error,code:se.StaticExtendingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function Hme(d){const u=[];if(d.implements.length){const i=new qt({id:d.id+"--"+se.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:Z.Error,code:se.AbstractEntityImplements,entity:d});u.push(i)}return d.extends.forEach(i=>{if(!i.abstract){const a=new qt({id:d.id+"--"+i.id+"--"+se.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${i.name}" with id "${i.id}" which is non-abstract`,issue:null,severity:Z.Error,code:se.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function zme(d){const u=[];return d.extends.forEach(i=>{if(i.static){const a=new qt({id:d.id+"--"+i.id+"--"+se.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${i.name}" with id "${i.id}" which is static`,issue:null,severity:Z.Error,code:se.NonStaticExtendingStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function Xme(d){const u=[];return d.extends.forEach(i=>{if(i.abstract){const a=new qt({id:d.id+"--"+i.id+"--"+se.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${i.name}" with id "${i.id}" which is abstract`,issue:null,severity:Z.Error,code:se.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}const Qme=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:gx,getBasePropertiesNotImplemented:_x,validate:Rx,validateCanBecomeAbstract:Hme,validateCanBecomeNonAbstract:Xme,validateCanBecomeNonStatic:zme,validateCanBecomeStatic:Yme,validateCanExtendEntity:Wme,validateCanImplementEntity:Jme},Symbol.toStringTag,{value:"Module"}));function e0e(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new Q({id:`${d.id}--${d.parent}--${S.SelfReference}`,code:S.SelfReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.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 a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new Q({id:`${d.id}--${d.parent}--${S.InvalidParentReference}`,code:S.InvalidParentReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):i.push(new Q({id:`${d.id}--${d.parent}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new Q({id:`${d.id}--${a}--${S.SelfReference}`,code:S.SelfReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.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 l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new Q({id:`${d.id}--${a}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new Q({id:`${d.id}--${a}--${S.InvalidImplementsReference}`,code:S.InvalidImplementsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new Q({id:`${d.id}--${a}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):i.push(new Q({id:`${d.id}--${oe.InvalidObjectStructure}`,code:oe.InvalidObjectStructure,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`,issue:null})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new Q({id:`${d.id}--${a}--${S.InvalidExtendsReference}`,code:S.InvalidExtendsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.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})):i.push(new Q({id:`${d.id}--${a}--${S.InvalidExtendsReference}`,code:S.InvalidExtendsReference,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new Q({id:`${d.id}--${a}--${S.ReferencedEntityNotFound}`,code:S.ReferencedEntityNotFound,severity:Z.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),i}var Qy=(d=>(d.Extends="extends",d.Implements="implements",d))(Qy||{});const Ct=class Ct extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"codeName",null);D(this,"description",null);D(this,"x");D(this,"y");D(this,"static");D(this,"abstract");D(this,"type",f.DefinitionEntity);D(this,"properties",[]);D(this,"methods",[]);D(this,"abstractMethods",[]);D(this,"extends",[]);D(this,"implements",[]);D(this,"project");D(this,"errors",[]);D(this,"parent");D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"suggestedProperties",[]);D(this,"suggestedMethods",[]);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DefinitionEntity,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const T=W(i.parent);l=a.get(T)}const p=[];i.implements&&i.implements.forEach(T=>{p.push(a.get(T)||a.getBuiltIn(T))});const t=[];i.extends&&i.extends.forEach(T=>{t.push(a.get(T)||a.getBuiltIn(T))});const y={id:i.id,version:P.UUID.uuid(),createdAt:L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,properties:[],methods:[],abstractMethods:[],extends:t,implements:p,x:0,y:0,parent:l},v=ee(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],t=e0e(l,a),y=hb(l,a);p.push(...t,...y,...vr(l));const v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DataType){const T=v;T.entity&&p.push(new Q({id:`${i.id}--${S.NewEntityWouldOverriteExisting}`,code:S.NewEntityWouldOverriteExisting,severity:Z.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${T.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
401
401
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
402
402
|
${On({describe_entity:T.entity.id})}
|
|
403
403
|
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:p,modifiedData:l}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[]),...this.implements.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[]),...this.implements.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R([...this.extends.reduce((i,a)=>[...[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract),...i],[]),...this.implements.reduce((i,a)=>[...[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract),...i],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return R([...this.extends.reduce((i,a)=>a.type!==f.DefinitionEntity?[]:[...[...a.ownDeclaredMethods,...a.allBaseMethodsFromExtendedAndImplementedEntities].filter(p=>p.type!==f.ActionDescriptor),...i],[]),...this.implements.reduce((i,a)=>a.type!==f.DefinitionEntity?a.abstractMethods:[...[...a.ownDeclaredMethods,...a.allBaseMethodsFromExtendedAndImplementedEntities].filter(p=>p.type!==f.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(t=>!!t.abstract&&!l.find(y=>y.name===t.name));return[...l,...p,...i]},[]),...this.implements.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(t=>!!t.abstract&&!l.find(y=>y.name===t.name));return[...l,...p,...i]},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return R(this.extends.reduce((i,a)=>{if(a.type!==f.DefinitionEntity)return[];const l=[...a.ownDeclaredMethods,...a.extendedMethodsFromOriginalParents].filter(p=>p.type!==f.ActionDescriptor);return[...i,...l]},[]))}get implementedMethodsFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.type===f.DefinitionEntity?a.methods:[],p=[...a.abstractMethods].filter(t=>!l.find(y=>y.name===t.name));return[...l,...p,...i]},[]),...this.implements.reduce((i,a)=>[...a.abstractMethods,...i],[])].filter(i=>i.type===f.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new Q({id:`${this.id}--${S.InvalidParentUpdate}`,code:S.InvalidParentUpdate,severity:Z.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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return a==="implements"&&this.removeImplementation(i),a==="extends"&&this.removeExtension(i),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return a==="implements"&&this.addImplementation(i),a==="extends"&&this.addExtension(i),{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{ki.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(i=>{ki.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(i=>{ki.includes(i.type)||i.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ct(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=[...this.extends],i.implements=[...this.implements],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ct(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.properties=y.properties,this.methods=y.methods,this.abstractMethods=y.abstractMethods,this.extends=y.extends,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=W(i.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.extends.forEach(l=>{const p=W(l),t=this.project.get(p);t&&this.addExtension(t)}),i.implements.forEach(l=>{const p=W(l),t=this.project.get(p);t&&this.addImplementation(t)}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),y=this.project.get(t);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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(t=>{const y=W(t),v=this.project.get(y);v&&(this.addExtension(v),v.type!==f.BuiltInBaseEntity&&i.push(v))}),this.initialData.implements.forEach(t=>{const y=W(t),v=this.project.get(y);v&&(this.addImplementation(v),v.type!==f.BuiltInBaseEntity&&i.push(v))}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];this.initialized=!0;const{updated:y,added:v,removed:T,affected:w}=this.syncImplementationProperties(i);a.push(...y),l.push(...v),p.push(...T),t.push(...w);const{updated:A,added:V,removed:N,affected:j}=this.addExtendedProperties(i);a.push(...A),l.push(...V),p.push(...N),t.push(...j);const{updated:k,added:q,removed:Y}=this.removeUnrecognizedProperties(i);a.push(...k),l.push(...q),p.push(...Y);const{updated:ie,added:te,removed:pe,affected:ne}=this.syncImplementationMethods(i);a.push(...ie),l.push(...te),p.push(...pe),t.push(...ne);const{updated:me,added:J,removed:ae,affected:ce}=this.addExtendedMethods(i);a.push(...me),l.push(...J),p.push(...ae),t.push(...ce);const{updated:H,added:de,removed:ve}=this.removeUnrecognizedMethods(i);return a.push(...H),l.push(...de),p.push(...ve),this.addSuggestions(),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];if(this.parent.type===f.DataType){const y=this.parent;y.entity=this,a.push(y)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}addExtension(i){return this.extends.includes(i)||this.extends.push(i),this}removeExtension(i){return this.extends=this.extends.filter(a=>a.id!==i.id),this}addImplementation(i){return this.implements.includes(i)||this.implements.push(i),this}removeImplementation(i){return this.implements=this.implements.filter(a=>a.id!==i.id),this}removeProperty(i){return this.properties=this.properties.filter(a=>a.id!==i.id),this}addMethod(i){return this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name)),this}removeMethod(i){return this.methods=this.methods.filter(a=>a.id!==i.id),this}addProperty(i){return this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name)),this}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(a=>a.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(a=>a.id!==i.id),this}addAbstractMethod(i){return this.abstractMethods.includes(i)||this.abstractMethods.push(i),this}removeAbstractMethod(i){return this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.methods=this.initialData.methods.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const l=ee(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.extends=this.initialData.extends.map(a=>ee(a,this.project)),this.implements=this.initialData.implements.map(a=>ee(a,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-properties"))){const a=[],l=[],p=[],t=[];let y=[...this.properties];y=y.filter(T=>T.parent.id===this.id),y=y.filter(T=>!T.isExtendedProperty);const v=this.implementedPropertiesFromOriginalParents;return y=y.filter(T=>this.interactive&&!T.implements?!1:!v.find(w=>{var A;return w.id===((A=T.implements)==null?void 0:A.id)})),y.forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-methods"))){const a=[],l=[],p=[],t=[];let y=[...this.methods];y=y.filter(T=>T.parent.id===this.id),y=y.filter(T=>!T.isExtendedMethod);const v=this.implementedMethodsFromOriginalParents;return y=y.filter(T=>this.interactive&&!T.implements?!1:!v.find(w=>{var A;return w.id===((A=T.implements)==null?void 0:A.id)})),y.forEach(T=>{const w=T.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-methods"))){const a=[],l=[],p=[],t=[],y=this.methods,v=this.implementedMethodsFromOriginalParents,T=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return v.filter(A=>!T.find(N=>{var j;return((j=N.implements)==null?void 0:j.id)===A.id})).forEach(A=>{if(this.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===A.id}))return;const N=this.methods.find(k=>{var pe,ne;if(k.name===A.name&&!k.implements)return!0;const q=Vs(this,$e.CRON_JOB),Y=Vs(this,$e.HTTP_ENDPOINT),ie=((pe=k.implements)==null?void 0:pe.id)===Ee["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,te=((ne=k.implements)==null?void 0:ne.id)===Ee["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(q&&!te&&!Y&&ie||Y&&!ie&&!q&&te)});if(N&&N.type===f.FunctionDeclaration){N.setImplements(A),N.metaSync({name:A.name},i),i==null||i.add(N,K.Updated),i==null||i.add(this,K.Updated);return}const j=A.implementAsFunctionDeclaration(i,this);l.push(j),i==null||i.add(j,K.Added),this.addMethod(j)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-properties"))){const a=[],l=[],p=[],t=[],y=this.properties,v=this.implementedPropertiesFromOriginalParents,T=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return v.filter(A=>!T.find(N=>{var j;return((j=N.implements)==null?void 0:j.id)===A.id})).forEach(A=>{if(this.properties.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===A.id}))return;const N=this.properties.find(k=>k.name===A.name&&!!k.abstract&&!k.implements);if(N){N.setImplements(A,i),N.metaSync({abstract:!1},i),N.afterAllChildrenInitialized(i);return}const j=A.implement(this,i,P.UUID.uuid());l.push(j),i==null||i.add(j,K.Added)}),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addExtendedMethods(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-extended-methods"))){const a=[],l=[],p=[],t=[],y=this.methods,T=this.extendedMethodsFromOriginalParents.filter(A=>A.type===f.FunctionDeclaration),w=new Set(y.filter(A=>{var V;return!!((V=A.extends)!=null&&V.id)}).map(A=>A.extends.id));return T.forEach(A=>{if(w.has(A.id))return;w.add(A.id);const V=A.clone(i,this,P.UUID.uuid());V.setExtends(A,i),V.initChildren(i),l.push(V),i==null||i.add(V,K.Added),this.addMethod(V)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addExtendedProperties(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"add-extended-properties"))){const a=[],l=[],p=[],t=[],y=this.properties,v=this.extendedPropertiesFromOriginalParents,T=v.filter(A=>v.find(N=>{var j;return((j=N.implements)==null?void 0:j.id)===A.id})?!1:!A.abstract),w=new Set(y.filter(A=>{var V;return!!((V=A.extends)!=null&&V.id)}).map(A=>A.extends.id));return T.forEach(A=>{if(w.has(A.id))return;w.add(A.id);const V=A.clone(i,this,P.UUID.uuid());V.setExtends(A,i),V.initChildren(i),l.push(V),i==null||i.add(V,K.Added),this.addProperty(V)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSuggestions(){return this.implements.forEach(i=>{_x(this,i).forEach(p=>{const t=p.toJSON();t.id=`_suggestion--parent--${this.id}--${p.id}`;const y=ee(t,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),gx(this,i).forEach(p=>{const t=`_suggestion--parent--${this.id}--${p.id}`,y=p.implementAsFunctionDeclaration(null,this,t),v=ee(y,this.project);if(v.suggestion=!0,v.setParent(this,null),v.initChildren(null),this.methods=this.methods.filter(T=>T.id!==t),v.inputs.forEach(T=>{T.suggestion=!0}),v.returnStatements.length){const T=v.returnStatements[0];T.suggestion=!0,T.outputs.forEach(w=>{w.suggestion=!0})}this.addSuggestedMethod(v)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,this.static=i.static!==void 0?i.static:this.static,this.abstract=i.abstract!==void 0?i.abstract:this.abstract,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Ct.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Ct.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Ct.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Ct.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Ct.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Ct.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];if(this.parent.type===f.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===f.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const y=this.parent.setEntity(null,i);a.push(y)}return i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(t),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:T,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),p.push(...w),t.push(...A)}),this.properties.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.methods.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.abstractMethods.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.suggestedProperties.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),this.suggestedMethods.forEach(v=>{const{updated:T,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...T),p.push(...w)}),!i){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(t),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...T),a.push(...w)}),this.properties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.methods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.abstractMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedProperties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(t),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.extends.flatMap(l=>l.toFlat(i)),...this.implements.flatMap(l=>l.toFlat(i)),...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.extends.flatMap(l=>l.toFlatIds(i)),...this.implements.flatMap(l=>l.toFlatIds(i)),...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),implements:this.implements.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Ne){var l,p,t,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Ar(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(t=i.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(T=>T.toJSONClone({...i,newId:null})),methods:this.methods.map(T=>T.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(T=>T.toJSONClone({...i,newId:null})),implements:this.implements.map(T=>T.type===f.BuiltInBaseEntity?T.toJSON():T.toJSONClone({...i,newId:null})),extends:this.extends.map(T=>T.type===f.BuiltInBaseEntity?T.toJSON():T.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(p=>p.toReference(i)),methods:this.methods.map(p=>p.toReference(i)),abstractMethods:this.abstractMethods.map(p=>p.toReference(i)),implements:this.implements.map(p=>p.toReference(i)),extends:this.extends.map(p=>p.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i)),...this.implements.flatMap(l=>l.toFlatJSON(i)),...this.extends.flatMap(l=>l.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){const i=this.parent.type===f.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(a=>a.id),implements:this.implements.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.implements.filter(l=>l.type===f.DefinitionEntity).flatMap(l=>l.toFlatGenerationTarget(i)),...this.implements.filter(l=>l.type===f.DefinitionEntity).flatMap(l=>l.toFlatGenerationTarget(i)),...this.parent.toFlatGenerationTarget(i)])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=Rx(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var k,q,Y;let t=Ir(a,this);const y=this.toJSON(),v=l||P.UUID.uuid();y.properties=[],y.methods=[],y.abstractMethods=[];const T=v.split("-id"),w=T[T.length-1||0]||v;y.id=v,y.version=P.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=Kt(y,t);a&&A.setParent(a,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,K.Added);const V=(k=this.properties)==null?void 0:k.map(ie=>ie.clone(i,A,P.UUID.uuid(),p));A.properties=V;const N=(q=this.methods)==null?void 0:q.map((ie,te)=>ie.clone(i,A,w+"-method-"+te+"-id",p));A.methods=N;const j=(Y=this.abstractMethods)==null?void 0:Y.map((ie,te)=>ie.clone(i,A,w+"-abstract-method-"+te+"-id",p));return A.abstractMethods=j,i==null||i.attemptAutoclose("clone-entity",this.id),A}getFunctionDeclaration(i){return this.methods.find(a=>a.id===i)}implement(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"implement-definition-entity")),l){const p=Fy(this,i,a,l);return a==null||a.attemptAutoclose("implement-definition-entity",this.id),p}getAllInteractiveMethods(){const i=this.implements.filter(l=>l.type===f.DefinitionEntity||l.type===f.BuiltInBaseEntity&&l.interactive);return R([...this.methods,...this.extends.flatMap(l=>l.getAllInteractiveMethods()),...i.flatMap(l=>l.getAllInteractiveMethods())])}inferFromInputs(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const l=[],p=[],t=[],y=[];if(this.parent.type!==f.DataType||!this.parent.inferred)return a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const v=[];i.forEach(A=>{v.find(N=>re(N,this.project)===re(A,this.project))||v.push(A)});const T=this.properties.filter(A=>!A.dataType);v.forEach(A=>{var Y,ie;const V=T.find(te=>re(te,this.project)===re(A,this.project));if(!V)return;const j=oi(A.parent).getMasterInputWithValueWritterFromAllInstances(A),k=zs(j,a),q=k==null?void 0:k.clone(a,V,P.UUID.uuid(),!0);q&&((Y=V.dataType)==null||Y.merge(q,a),q.id!==((ie=V.dataType)==null?void 0:ie.id)&&q.remove({ignoreUpstream:!1},a),V.dataType&&(V.dataType.metaSync({inferred:!0,like:!0},a),V.setDataType(V.dataType,a),a==null||a.add(V,K.Affected))),A.setDeclaration(V),a==null||a.add(A,K.Updated)});const w=[];return v.forEach(A=>{if(!A.declaration){w.push(A);return}}),w.length===0?(a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(w.forEach(A=>{var te,pe,ne,me;const V=this.properties.find(J=>re(J,this.project)===re(A,this.project));if(V){if(A.setDeclaration(V),!V.getDataType(a)){const ae=oi(A.parent).getMasterInputWithValueWritterFromAllInstances(A),ce=zs(ae),H=ce==null?void 0:ce.clone(a,V,P.UUID.uuid(),!0);H&&((te=V.dataType)==null||te.merge(H,a),H.id!==((pe=V.dataType)==null?void 0:pe.id)&&H.remove({ignoreUpstream:!1},a),V.dataType&&(V.dataType.metaSync({inferred:!0,like:!0},a),V.setDataType(V.dataType,a),a==null||a.add(V,K.Affected)))}return}const N={id:P.UUID.uuid(),type:f.Property,version:P.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||L().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,name:re(A,this.project),codeName:A.codeName,description:A.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:A.index,implements:null,extends:null,dataType:null,parent:this.toReference()},j=ee(N,this.project);j.setParent(this,a),j.initChildren(a),a==null||a.add(j,K.Added);const q=oi(A.parent).getMasterInputWithValueWritterFromAllInstances(A),Y=zs(q),ie=Y==null?void 0:Y.clone(a,j,P.UUID.uuid(),!0);return ie&&((ne=j.dataType)==null||ne.merge(ie,a),ie.id!==((me=j.dataType)==null?void 0:me.id)&&ie.remove({ignoreUpstream:!1},a),j.dataType&&(j.dataType.metaSync({inferred:!0,like:!0},a),j.setDataType(j.dataType,a),a==null||a.add(j,K.Affected))),this.addProperty(j),A.setDeclaration(j),a==null||a.add(A,K.Updated),j}),a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:R(l),updated:R(p),removed:R(t),affected:R(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(a=>{var p;const l=kr(a.name);i[l]=((p=a.getDefaultValue())==null?void 0:p.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(a=>{const l=kr(a.name),p=this.project.requestActiveValue(a);i[l]=(p==null?void 0:p.value)||null}),i}};D(Ct,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),D(Ct,"type",f.DefinitionEntity),D(Ct,"USER_MANAGED_PARENT_TYPES",[f.Project,f.DataType]),D(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES]),D(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract"]),D(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),D(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"x","y"]),D(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),D(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),D(Ct,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),D(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),D(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),D(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),D(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let ma=Ct;function t0e(d){const u=cde(),i=d.toJSON();u.safeParse(i).success;const l=[];return zt(d.errors,l)}const jp=class jp extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"version");D(this,"name");D(this,"description",null);D(this,"type",f.BuiltInBaseEntity);D(this,"abstract",!1);D(this,"static");D(this,"properties",[]);D(this,"methods",[]);D(this,"abstractMethods",[]);D(this,"extends",[]);D(this,"interactive",!1);D(this,"errors",[]);D(this,"project");this.initialData=this.initialData||i,this.project=this.project||a,this.id=this.id||i.id,this.version=this.version||i.version,this.name=this.name||i.name,this.static=this.static||i.static,this.interactive=this.interactive||i.interactive,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const p=ee(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(l=>{const p=ee(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const p=ee(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.extends=this.initialData.extends.map(l=>ee(l,this.project))}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...l]},[]))}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(t=>!!t.abstract&&!l.find(y=>y.name===t.name));return[...l,...p,...i]},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ye,...a){return await jp.repository.APILoad(this.id,...a),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i)),...this.extends.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i)),...this.extends.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i))})}toReference(i=Ne){return{id:this.id+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){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(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:this.extends.map(a=>a.toReference())}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}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(i=>i.id)}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=t0e(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new G(this.project,P.sessionAuthor,L().toISOString(),null,!0,"implement-built-in-base-entity")),l){const p=Fy(this,i,a,l);return a==null||a.attemptAutoclose("implement-built-in-base-entity",this.id),p}getAllInteractiveMethods(){const i=[];return this.interactive&&(i.push(...this.methods),this.extends.filter(l=>l.type===f.BuiltInBaseEntity&&l.interactive||l.type===f.PrimitiveEntity).forEach(l=>{l instanceof jp&&i.push(...l.getAllInteractiveMethods())})),R(i)}};D(jp,"repository",{APILoad:async(i,...a)=>null});let Cn=jp;function r0e(d){const u=rde(),i=d.toJSON();u.safeParse(i).success;const l=[];return zt(d.errors,l)}const cm=class cm extends hr{constructor(i,a){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"description",null);D(this,"type",f.PrimitiveEntity);D(this,"static");D(this,"abstract");D(this,"properties",[]);D(this,"methods",[]);D(this,"abstractMethods",[]);D(this,"extends",[]);D(this,"errors",[]);D(this,"project");this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const p=ee(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(l=>{const p=ee(l,this.project);return p.parent=this,p}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const p=ee(l,this.project);return p.parent=this,p})}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...l]},[]))}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(t=>!!t.abstract&&!l.find(y=>y.name===t.name));return[...l,...p,...i]},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ye,...a){return await cm.repository.APILoad(this.id,...a),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i))})}toReference(i=Ne){return{id:this.id+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){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(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:this.extends.map(a=>a.toReference())}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(i=>i.id)}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=r0e(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),this.extends.filter(l=>l.type===f.BuiltInBaseEntity&&l.interactive||l.type===f.PrimitiveEntity).forEach(l=>{l instanceof Cn&&i.push(...l.getAllInteractiveMethods())}),R(i)}};D(cm,"repository",{APILoad:async(i,...a)=>null});let Li=cm;function Kt(d,u){if(!d)throw new Error("Entity is null");const i=u.get(d.id);switch(d.type){case f.LiteralValue:return i||new bi(d,u);case f.DefinitionEntity:return i||new ma(d,u);case f.PrimitiveEntity:return i||new Li(d,u);case f.FunctionDeclaration:return i||new Ua(d,u);case f.GlobalEvent:return i||new Fa(d,u);case f.DataType:return i||new Hi(d,u);case f.Property:return i||new ua(d,u);case f.FunctionCall:return i||new za(d,u);case f.Condition:return i||new Ga(d,u);case f.Operation:return i||new ja(d,u);case f.VariableDeclaration:return i||new ka(d,u);case f.VariableInstance:return i||new Ka(d,u);case f.OutputMap:return i||new Qs(d,u);case f.ReturnDeclaration:return i||new Ni(d,u);case f.ArgumentDeclaration:return i||new pa(d,u);case f.InputMap:return i||new Cs(d,u);case f.Project:return i||new P(d);case f.InstalledProject:return i||new Sa(d,u);case f.ActionDescriptor:return i||new jt(d,u);case f.ReturnStatement:return i||new xa(d,u);case f.Loop:return i||new Ai(d,u);case f.Search:return i||new qa(d,u);case f.ValueDescriptor:return i||new en(d,u);case f.BuiltInBaseEntity:return i||new Cn(d,u);case f.InternalCall:return i||new Za(d,u);case f.ContinueStatement:return i||new li(d,u);case f.BreakStatement:return i||new Ja(d,u);case f.GenericReference:return u.get(d.entityId);default:throw new Error("Invalid entity type: "+d.type)}}function ee(d,u){if(!d)throw new Error("Entity is null");const i=Kt(d,u);return i.subscribe(),i}function i0e(d,u){if(!d)throw new Error("Entity is null");switch(d.type){case f.LiteralValue:return bi.fromGenerationTarget(d,u);case f.DefinitionEntity:return ma.fromGenerationTarget(d,u);case f.FunctionDeclaration:return Ua.fromGenerationTarget(d,u);case f.GlobalEvent:return Fa.fromGenerationTarget(d,u);case f.DataType:return Hi.fromGenerationTarget(d,u);case f.Property:return ua.fromGenerationTarget(d,u);case f.FunctionCall:return za.fromGenerationTarget(d,u);case f.Condition:return Ga.fromGenerationTarget(d,u);case f.Operation:return ja.fromGenerationTarget(d,u);case f.VariableDeclaration:return ka.fromGenerationTarget(d,u);case f.VariableInstance:return Ka.fromGenerationTarget(d,u);case f.OutputMap:return Qs.fromGenerationTarget(d,u);case f.ReturnDeclaration:return Ni.fromGenerationTarget(d,u);case f.ArgumentDeclaration:return pa.fromGenerationTarget(d,u);case f.InputMap:return Cs.fromGenerationTarget(d,u);case f.InstalledProject:return Sa.fromGenerationTarget(d,u);case f.ReturnStatement:return xa.fromGenerationTarget(d,u);case f.Loop:return Ai.fromGenerationTarget(d,u);case f.Search:return qa.fromGenerationTarget(d,u);case f.ActionDescriptor:return jt.fromGenerationTarget(d,u);case f.ValueDescriptor:return en.fromGenerationTarget(d,u);case f.InternalCall:return Za.fromGenerationTarget(d,u);case f.ContinueStatement:return li.fromGenerationTarget(d,u);case f.BreakStatement:return Ja.fromGenerationTarget(d,u);default:throw new Error("Invalid entity type: "+d.type)}}const Ne={seenEntityMaps:new Map,seenEntities:new Set,timestamp:L().toISOString()};class Dx{constructor(){D(this,"initialData")}}const ye={cascade:!1},Ox={APILoad:async(d,...u)=>null},s0e={APICreate:async(d,...u)=>d,APIUpdate:async(d,...u)=>d,APIDelete:async(d,...u)=>d,APIClone:async(d,...u)=>{},APILoadVersion:async(d,u,...i)=>null,...Ox};class n0e{}class a0e extends Dx{}class o0e{}class l0e{}class d0e{}class IA{}class u0e extends IA{}class c0e extends IA{}class p0e{}class Op{static initReadsValue(u){if(u.initialData.readsValue&&u.initialData.readsValue.type!==f.GenericReference)u.readsValue=ee(u.initialData.readsValue,u.project);else if(u.initialData.readsValue&&u.initialData.readsValue.type===f.GenericReference){const i=_i(u.initialData.readsValue,u.project);i&&(u.readsValue=i)}if(u.readsValue){if(rt.includes(u.readsValue.type)){let i=u.parent;br.includes(i.type)||(i=i.parent);const a=u.type===f.InputMap&&u.parent.type===f.Loop;a&&(i=u.parent.parent),u.readsValue.setParent(i,null),u.readsValue.initChildren(null),i&&i.type!==f.Project&&!a&&i.detachedChildren.includes(u)?i.replaceDetachedChild(u,u.readsValue):i&&i.type!==f.Project&&!a&&i.subscribeDetachedChild(u.readsValue)}u.readsValue.addValueReader(u,null)}return u.readsValue}}class Cp{static initWritesValues(u,i){const a=u.initialData.writesValues.reduce((p,t)=>{if(t.type===f.GenericReference||u.writesValues.some(v=>v.id===t.id))return p;const y=ee(t,u.project);return y.setValueWriter(u,null),rt.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...p,y]},[]),l=[...u.writesValues];return u.writesValues=R([...l,...a]),u.writesValues}}class f0e{}var h0e=Object.defineProperty,y0e=(d,u,i)=>u in d?h0e(d,u,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[u]=i,Yo=(d,u,i)=>(y0e(d,typeof u!="symbol"?u+"":u,i),i);class m0e{constructor(u){Yo(this,"eventName"),Yo(this,"callbacks",[]),this.eventName=u,this.on=this.on.bind(this),this.off=this.off.bind(this),this.destroy=this.destroy.bind(this)}on(u){if(typeof u!="function")throw new Error("Event callback must be a function");this.callbacks.includes(u)||this.callbacks.push(u)}off(u){if(typeof u!="function")throw new Error("Event callback must be a function");this.callbacks=this.callbacks.filter(i=>i!==u)}destroy(){this.callbacks=[]}}class wA{constructor(){Yo(this,"subscribedEvents",{}),Yo(this,"on",this._on),Yo(this,"emit",this._emit),Yo(this,"off",this._off),Yo(this,"destroy",this._destroy),this.getEvent=this.getEvent.bind(this),this._on=this._on.bind(this),this._emit=this._emit.bind(this),this._off=this._off.bind(this),this._destroy=this._destroy.bind(this),this.on=this.on.bind(this),this.emit=this.emit.bind(this),this.off=this.off.bind(this),this.destroy=this.destroy.bind(this)}getEvent(u){return this.subscribedEvents[u]||(this.subscribedEvents[u]=new m0e(u)),this.subscribedEvents[u]}_on(u,i){this.getEvent(u).on(i)}_emit(u,...i){const a=this.getEvent(u);a&&a.callbacks.forEach(l=>{l.apply(null,i)})}_off(u,i){const a=this.getEvent(u);a&&(i?a.off(i):(a.destroy(),delete this.subscribedEvents[u]))}_destroy(){Object.keys(this.subscribedEvents).forEach(u=>{this._off(u)}),this.subscribedEvents={}}}var yr=(d=>(d.PROJECT_INITIALIZED="project-initialized",d.CHANGE_SET_CLOSED="change-set-closed",d.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",d.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",d.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",d.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",d.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",d.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",d))(yr||{});const Ke=class Ke extends hr{constructor(i){super(i);D(this,"initialData");D(this,"id");D(this,"type",f.Project);D(this,"name",null);D(this,"description",null);D(this,"x");D(this,"y");D(this,"entities",[]);D(this,"projects",[]);D(this,"functions",[]);D(this,"events",[]);D(this,"variableDeclarations",[]);D(this,"variableInstances",[]);D(this,"conditions",[]);D(this,"operations",[]);D(this,"functionCalls",[]);D(this,"loops",[]);D(this,"searches",[]);D(this,"primitives",[]);D(this,"builtInBaseEntities",[]);D(this,"operationDeclarations",[]);D(this,"globalEventActionDescriptors",[]);D(this,"loopDeclarations",[]);D(this,"loopDeclarationsBodies",[]);D(this,"conditionDeclarations",[]);D(this,"valueDescriptors",[]);D(this,"dataTypes",[]);D(this,"project");D(this,"instances",{});D(this,"builtInInstances",{});D(this,"deletedInstances",{});D(this,"errors",[]);D(this,"references",[]);D(this,"history",[]);D(this,"undoableStackValueIndex",-1);D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"_eventsHub",new wA);D(this,"onCloseChangeSetCallback",null);D(this,"onAddChangeSetCallback",null);D(this,"onDiscardChangeSetCallback",null);D(this,"onRequestActiveValueCallback",null);this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!Ke.UUID||Ke.UUID.isBackup)&&(Ke.UUID=_h==null?void 0:_h()),Ke.UUID||(Ke.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:a=>a})}catch(a){console.error("Error initializing UUID module",a),Ke.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:l=>l}}}static injectUUIDModule(i){Ke.UUID=i}static new(i=null){return{id:Ke.UUID.uuid(),version:Ke.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||Ke.sessionAuthor,previousVersion:null,deleted:!1,type:f.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[];return p.push(...vr(l)),{errors:p,modifiedData:l}}get off(){return this._eventsHub.off}get on(){return this._eventsHub.on}get emit(){return this._eventsHub.emit}async closePendingChangeSets(){const i=this.history.find(a=>a.dirty&&!a.open);i&&await this.closeChangeSet(i)}onRequestActiveValue(i){this.onRequestActiveValueCallback=i}async onCloseChangeSet(i){this.onCloseChangeSetCallback=i,await this.closePendingChangeSets()}onAddChangeSet(i){this.onAddChangeSetCallback=i}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}async closeChangeSet(i){const a=this.history.findIndex(t=>t.id===i.id),l=this.history.slice(0,a),p=l[l.length-1];if(!(p!=null&&p.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(i)).success&&(i.dirty=!1,this.emit("change-set-closed",i),this.closePendingChangeSets());return}}toLatestChangeSet(i,a,l,p=!1,t="here-this"){if(!this.history.length)return new G(this,i,a,l,p,t);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new G(this,i,a,l,p,t))}addChangeSet(i){var p,t;if(!this.history.length)return this.undoableStackValueIndex=_b(this.undoableStackValueIndex,this.history,i),(p=this.onAddChangeSetCallback)==null||p.call(this,i,this.undoableStackValueIndex),i;const a=this.history.find(y=>y.id===(i==null?void 0:i.id));if(a)return a;const l=this.history.find(y=>y.open);if(l)throw console.warn("Previous still open: ",l),console.warn("New change set: ",i),new Error(`There is already an open change-set with id '${l.id}'.`);return this.undoableStackValueIndex=_b(this.undoableStackValueIndex,this.history,i),(t=this.onAddChangeSetCallback)==null||t.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var l;const a=this.history.findIndex(p=>p.id===(i==null?void 0:i.id));return a!==-1&&(this.history.splice(a,1),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(l=this.onDiscardChangeSetCallback)==null||l.call(this,i)),this}async inject(...i){return await Promise.all(i.map(a=>new Promise(async l=>{await a.init(this),l(null)}))),this}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,Ke.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],t=[],y=[],v=[];return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],t=[],y=[],v=[];return{updated:R(p),added:R(t),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=Ke.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ke(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],t=[];return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],t=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this};if(!this.knownVersions){const T=new Map;for(const[w,A]of this.knownVersions||new Map){if(T.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[V,N]of A.knownVersions)T.set(V,N);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ke(T)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entities=y.entities,this.projects=y.projects,this.functions=y.functions,this.events=y.events,this.variableDeclarations=y.variableDeclarations,this.variableInstances=y.variableInstances,this.conditions=y.conditions,this.operations=y.operations,this.functionCalls=y.functionCalls,this.loops=y.loops,this.searches=y.searches,{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,Ke.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){return this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=null){const a=[],l=[],p=[],t=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}addSelfToProject(i){const a=[],l=[],p=[],t=[];return this.subscribe(),this.subscribeToDependencies(),{updated:R(a),added:R(l),removed:R(p),affected:R(t),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new G(this.project,Ke.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.projects=this.initialData.projects.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableDeclarations=this.initialData.variableDeclarations.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableInstances=this.initialData.variableInstances.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.conditions=this.initialData.conditions.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.operations=this.initialData.operations.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.functions=this.initialData.functions.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.events=this.initialData.events.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.functionCalls=this.initialData.functionCalls.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.loops=this.initialData.loops.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.searches=this.initialData.searches.map(a=>{const l=ee(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,a=this.project.addChangeSet(new G(this.project,Ke.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Er(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):l&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ye,...a){return await Ke.repository.APILoad(this.id,...a),this}async APICreate(i=ye,...a){return await Ke.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ye,...a){return await Ke.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ye,...a){return await Ke.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ye,...a){return await Ke.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ye,a,...l){return await Ke.repository.APILoadVersion(this.id,a,...l)}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,Ke.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,Ke.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(a=>a.toFlatIds(i)),...this.builtInBaseEntities.flatMap(a=>a.toFlatIds(i)),...this.operationDeclarations.flatMap(a=>a.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(a=>a.toFlatIds(i)),...this.loopDeclarations.flatMap(a=>a.toFlatIds(i)),...this.conditionDeclarations.flatMap(a=>a.toFlatIds(i)),...this.valueDescriptors.flatMap(a=>a.toFlatIds(i)),...this.dataTypes.flatMap(a=>a.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(a=>a.toFlat(i)),...this.builtInBaseEntities.flatMap(a=>a.toFlat(i)),...this.operationDeclarations.flatMap(a=>a.toFlat(i)),...this.globalEventActionDescriptors.flatMap(a=>a.toFlat(i)),...this.loopDeclarations.flatMap(a=>a.toFlat(i)),...this.conditionDeclarations.flatMap(a=>a.toFlat(i)),...this.valueDescriptors.flatMap(a=>a.toFlat(i)),...this.dataTypes.flatMap(a=>a.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(l=>l.toFlat(i)),...this.functions.flatMap(l=>l.toFlat(i)),...this.events.flatMap(l=>l.toFlat(i)),...this.projects.flatMap(l=>l.toFlat(i)),...this.variableDeclarations.flatMap(l=>l.toFlat(i)),...this.variableInstances.flatMap(l=>l.toFlat(i)),...this.conditions.flatMap(l=>l.toFlat(i)),...this.operations.flatMap(l=>l.toFlat(i)),...this.functionCalls.flatMap(l=>l.toFlat(i)),...this.loops.flatMap(l=>l.toFlat(i)),...this.searches.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(l=>l.toFlatIds(i)),...this.functions.flatMap(l=>l.toFlatIds(i)),...this.events.flatMap(l=>l.toFlatIds(i)),...this.projects.flatMap(l=>l.toFlatIds(i)),...this.variableDeclarations.flatMap(l=>l.toFlatIds(i)),...this.variableInstances.flatMap(l=>l.toFlatIds(i)),...this.conditions.flatMap(l=>l.toFlatIds(i)),...this.operations.flatMap(l=>l.toFlatIds(i)),...this.functionCalls.flatMap(l=>l.toFlatIds(i)),...this.loops.flatMap(l=>l.toFlatIds(i)),...this.searches.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(a=>a.toJSON(i)),variableDeclarations:this.variableDeclarations.map(a=>a.toJSON(i)),variableInstances:this.variableInstances.map(a=>a.toJSON(i)),conditions:this.conditions.map(a=>a.toJSON(i)),operations:this.operations.map(a=>a.toJSON(i)),loops:this.loops.map(a=>a.toJSON(i)),searches:this.searches.map(a=>a.toJSON(i)),functions:this.functions.map(a=>a.toJSON(i)),events:this.events.map(a=>a.toJSON(i)),projects:this.projects.map(a=>a.toJSON(i)),functionCalls:this.functionCalls.map(a=>a.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const a=new Map,l=new Set,p=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(t=>{if(p.includes(t)){a.set(t,t);return}a.set(t,Ke.UUID.uuid())}),l.add(this.id),{id:a.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(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),projects:this.projects.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),variableDeclarations:this.variableDeclarations.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),variableInstances:this.variableInstances.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),conditions:this.conditions.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),operations:this.operations.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),functions:this.functions.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),events:this.events.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),functionCalls:this.functionCalls.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),loops:this.loops.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),searches:this.searches.map(t=>t.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null}))}}toReference(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+Ke.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Ne){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(p=>p.toReference(i)),functions:this.functions.map(p=>p.toReference(i)),events:this.events.map(p=>p.toReference(i)),projects:this.projects.map(p=>p.toReference(i)),variableDeclarations:this.variableDeclarations.map(p=>p.toReference(i)),variableInstances:this.variableInstances.map(p=>p.toReference(i)),conditions:this.conditions.map(p=>p.toReference(i)),operations:this.operations.map(p=>p.toReference(i)),functionCalls:this.functionCalls.map(p=>p.toReference(i)),loops:this.loops.map(p=>p.toReference(i)),searches:this.searches.map(p=>p.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(l=>l.toFlatJSON(i)),...this.functions.flatMap(l=>l.toFlatJSON(i)),...this.events.flatMap(l=>l.toFlatJSON(i)),...this.projects.flatMap(l=>l.toFlatJSON(i)),...this.variableDeclarations.flatMap(l=>l.toFlatJSON(i)),...this.variableInstances.flatMap(l=>l.toFlatJSON(i)),...this.conditions.flatMap(l=>l.toFlatJSON(i)),...this.operations.flatMap(l=>l.toFlatJSON(i)),...this.functionCalls.flatMap(l=>l.toFlatJSON(i)),...this.loops.flatMap(l=>l.toFlatJSON(i)),...this.searches.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.events.flatMap(l=>l.toFlatGenerationTarget(i)),...this.projects.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(l=>l.toFlatGenerationTarget(i)),...this.conditions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.operations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.loops.flatMap(l=>l.toFlatGenerationTarget(i)),...this.searches.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){const i=Dce(),a=this.toJSON();return i.safeParse(a),this.validateChildren(),{success:!0,error:null,data:a}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(a=>a.getErrors()),...this.projects.flatMap(a=>a.getErrors()),...this.functions.flatMap(a=>a.getErrors()),...this.events.flatMap(a=>a.getErrors()),...this.variableDeclarations.flatMap(a=>a.getErrors()),...this.variableInstances.flatMap(a=>a.getErrors()),...this.conditions.flatMap(a=>a.getErrors()),...this.operations.flatMap(a=>a.getErrors()),...this.functionCalls.flatMap(a=>a.getErrors()),...this.loops.flatMap(a=>a.getErrors()),...this.searches.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(i){return this.entities.find(a=>a.id===i)||null}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const a=this.entities.findIndex(l=>l.id===i.id);if(a>-1){const l=this.entities[a];return this.entities.splice(a,1),l}return null}removeCondition(i){const a=this.conditions.findIndex(l=>l.id===i.id);if(a>-1){const l=this.conditions[a];return this.conditions.splice(a,1),l}return null}removeOperation(i){const a=this.operations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.operations[a];return this.operations.splice(a,1),l}return null}removeLoop(i){const a=this.loops.findIndex(l=>l.id===i.id);if(a>-1){const l=this.loops[a];return this.loops.splice(a,1),l}return null}removeSearch(i){const a=this.searches.findIndex(l=>l.id===i.id);if(a>-1){const l=this.searches[a];return this.searches.splice(a,1),l}return null}removeFunctionCall(i){const a=this.functionCalls.findIndex(l=>l.id===i.id);if(a>-1){const l=this.functionCalls[a];return this.functionCalls.splice(a,1),l}return null}removeVariableInstance(i){const a=this.variableInstances.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableInstances[a];return this.variableInstances.splice(a,1),l}return null}removeVariableDeclaration(i){const a=this.variableDeclarations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),l}return null}removeFunctionDeclaration(i){const a=this.functions.findIndex(l=>l.id===i.id);if(a>-1){const l=this.functions[a];return this.functions.splice(a,1),l}return null}removeInstalledProject(i){const a=this.projects.findIndex(l=>l.id===i.id);if(a>-1){const l=this.projects[a];return this.projects.splice(a,1),l}return null}removeGlobalEvent(i){const a=this.events.findIndex(l=>l.id===i.id);if(a>-1){const l=this.events[a];return this.events.splice(a,1),l}return null}removeTopLevelVariableDeclaration(i){if(i.type!==f.VariableDeclaration)return null;const a=this.variableDeclarations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),l}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(a=>a.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.ReturnStatement||t.type===f.ContinueStatement||t.type===f.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(a=>a.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Condition)]},[]),...this.functionCalls.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Condition)]},[]),...this.operations.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Condition)]},[]),...this.loops.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Condition)]},[]),...this.searches.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Operation)]},[]),...this.functionCalls.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Operation)]},[]),...this.conditions.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Operation)]},[]),...this.loops.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Operation)]},[]),...this.searches.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.FunctionCall)]},[]),...this.conditions.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.FunctionCall)]},[]),...this.operations.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.FunctionCall)]},[]),...this.loops.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.FunctionCall)]},[]),...this.searches.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((a,l)=>{const p=Ht(l);return[...a,...p]},[]),...this.functionCalls.reduce((a,l)=>{const p=Ht(l);return[...a,...p]},[]),...this.conditions.reduce((a,l)=>{const p=Ht(l);return[...a,...p]},[]),...this.operations.reduce((a,l)=>{const p=Ht(l);return[...a,...p]},[]),...this.loops.reduce((a,l)=>{const p=Ht(l);return[...a,...p]},[]),...this.searches.reduce((a,l)=>{const p=Ht(l);return[...a,...p]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableInstance);return[...a,...t]},[]),...this.functionCalls.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableInstance);return[...a,...t]},[]),...this.conditions.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableInstance);return[...a,...t]},[]),...this.operations.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableInstance);return[...a,...t]},[]),...this.loops.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableInstance);return[...a,...t]},[]),...this.searches.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableInstance);return[...a,...t]},[])]}getVariableDeclarations(){return R([...this.variableDeclarations,...this.getEntryPoints().reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...t]},[]),...this.functionCalls.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...t]},[]),...this.conditions.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...t]},[]),...this.operations.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...t]},[]),...this.loops.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...t]},[]),...this.searches.reduce((a,l)=>{const t=Ht(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...t]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Loop)]},[]),...this.functionCalls.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Loop)]},[]),...this.conditions.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Loop)]},[]),...this.operations.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Loop)]},[]),...this.searches.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Search)]},[]),...this.functionCalls.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Search)]},[]),...this.conditions.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Search)]},[]),...this.operations.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Search)]},[]),...this.loops.reduce((a,l)=>{const p=ut(l);return[...a,...p.filter(t=>t.type===f.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),a=this.getVariableDeclarations();return i.forEach(l=>{if(!l.declaration){const p=l.initialData,t=p.declaration.entityId||p.declaration.id,y=a.find(v=>v.id===t);y&&l.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===$e.PERSISTED_ENTITY)||null}requestActiveValue(i){var l;const a=(l=this.onRequestActiveValueCallback)==null?void 0:l.call(this,i);return a?a||null:i.getDefaultValue()}undo(){console.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,console.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],a=this.history[this.undoableStackValueIndex];return console.log("Current change set: ",i),console.log("Change set to restore: ",a),wb(i||"initial",a||"initial",this)}redo(){console.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,console.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],a=this.history[this.undoableStackValueIndex];return console.log("Current change set: ",i),console.log("Change set to restore: ",a),wb(i||"initial",a||"initial",this)}applyExternalChangeSet(i){const a=i.payload,l=this.addChangeSet(new G(this,i.author,i.timestamp,this)),p=a.updated[this.id];if(!p)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const t={...a.added,...a.updated,...a.removed},y=[...Object.keys(a.added),...Object.keys(a.updated),...Object.keys(a.removed)];y.forEach(T=>{var w;if(!t[T]){console.warn(`Entity '${T}' not found in change set transfer. Cannot apply changes.`);const A=(w=this.get(T))==null?void 0:w.toShallowJSON();throw A?console.warn("Entity in project: ",A):console.warn("Entity not in project"),new Error(`Entity '${T}' not found in change set transfer. Cannot apply changes.`)}});const v=new ha(p);return v.flatRecord=t,v.order=y,v.orderEntities(),console.log("All entities: ",v.order.map((T,w)=>`${w+1}: ${t[T].type} - ${T}`).join(`,
|