@elyx-code/project-logic-tree 0.0.6613 → 0.0.6614
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.d.ts +0 -2
- package/dist/index.js +3 -5
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13543,8 +13543,6 @@ export declare function getReferencedEntityStateOrErrors(data: ElementGeneration
|
|
|
13543
13543
|
|
|
13544
13544
|
export declare interface IDataTypeGenerationTarget extends IDataType_base, IChildEntityGenerationTarget {
|
|
13545
13545
|
entity: EntityId | null;
|
|
13546
|
-
andChildrenGroup: EntityId[] | null;
|
|
13547
|
-
orChildrenGroup: EntityId[] | null;
|
|
13548
13546
|
foreignKeyRef: EntityId | null;
|
|
13549
13547
|
parent: EntityId;
|
|
13550
13548
|
}
|
package/dist/index.js
CHANGED
|
@@ -51175,7 +51175,7 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
|
|
|
51175
51175
|
]);
|
|
51176
51176
|
}
|
|
51177
51177
|
toGenerationTarget() {
|
|
51178
|
-
var i, a
|
|
51178
|
+
var i, a;
|
|
51179
51179
|
return {
|
|
51180
51180
|
id: this.id,
|
|
51181
51181
|
type: this.type,
|
|
@@ -51183,11 +51183,9 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
|
|
|
51183
51183
|
isList: this.isList,
|
|
51184
51184
|
like: this.like,
|
|
51185
51185
|
parentRelationType: this.parentRelationType || void 0,
|
|
51186
|
-
|
|
51187
|
-
orChildrenGroup: ((a = this.orChildrenGroup) == null ? void 0 : a.map((e) => e.id)) || null,
|
|
51188
|
-
foreignKeyRef: ((l = this.foreignKeyRef) == null ? void 0 : l.id) || null,
|
|
51186
|
+
foreignKeyRef: ((i = this.foreignKeyRef) == null ? void 0 : i.id) || null,
|
|
51189
51187
|
asType: this.asType,
|
|
51190
|
-
entity: ((
|
|
51188
|
+
entity: ((a = this.entity) == null ? void 0 : a.id) || null,
|
|
51191
51189
|
parent: this.parent.id
|
|
51192
51190
|
};
|
|
51193
51191
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -23,7 +23,7 @@ ${Ao}`}))}}}const y=l.parent&&a.get(l.parent)||a.getBuiltIn(l.parent),v=y?_o(y):
|
|
|
23
23
|
The entitities of type '${yt(E,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`})),y.dataType)){const D=(T=y.dataType)==null?void 0:T.id;c.push(new fe({id:`${i.id}--${J.NewEntityWouldOverriteExisting}`,code:J.NewEntityWouldOverriteExisting,severity:te.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot be added as a child to the entity with id '${l.parent}' and type '${I}', because it already has a 'data-type' child with id '${D}'.
|
|
24
24
|
The entitities of type '${yt(E,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
|
|
25
25
|
${Da({describe_entity:D})}
|
|
26
|
-
Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}I===p.DataType&&(!l.parentRelationType||!(l.parentRelationType===ir.AndDataTypeGroup||l.parentRelationType===ir.OrDataTypeGroup))&&c.push(new fe({id:`${i.id}--${J.InvalidParentRelationType}`,code:J.InvalidParentRelationType,severity:te.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`}))}return{errors:c,modifiedData:l}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let a=0;for(const l of i)if(l.isResolved&&(a++,a>1))return!0}return!1}get isResolved(){return[p.BuiltInBaseEntity,p.ActionDescriptor].includes(this.parent.type)||_o(this.parent)?!0:!(!this.entity&&!this.isGroup)}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 k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const c=[],e=[],y=[],v=[];return a==="entity-field"&&this.setEntity(null,l),a==="foreign-key-ref-field"&&this.setForeignKeyRef(null,l),{updated:g(c),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const c=[],e=[],y=[],v=[];return a==="entity-field"&&this.setEntity(i,l),a==="foreign-key-ref-field"&&this.setForeignKeyRef(i,l),{updated:g(c),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,c;return(a=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.unsubscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,a,l,c;return(a=(i=this.entity)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.subscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ht(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.entity=this.entity,i.foreignKeyRef=this.foreignKeyRef,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],c=[],e=[];if(this.parent&&this.parent.type!==p.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],c=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[I,E]of this.knownVersions||new Map){if(T.set(I,E),E.activeVersion=!1,E.knownVersions)for(const[D,$]of E.knownVersions)T.set(D,$);E.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 Ht(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.entity=y.entity,this.foreignKeyRef=y.foreignKeyRef,this.andChildrenGroup=y.andChildrenGroup?[...y.andChildrenGroup]:null,this.orChildrenGroup=y.orChildrenGroup?[...y.orChildrenGroup]:null,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.UpdateWithShallowTransfer))){var l,c;if(!this.checkCanEdit(this,a))return S.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;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 e=ie(i.parent),y=this.project.get(e),v=this.parent;if(v&&v.id!==(y==null?void 0:y.id)&&this.removeFromParent(a),y)this.setParent(y,a),this.addSelfToProject(a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=ie(i.entity),y=this.project.get(e);y&&(y.type===p.DefinitionEntity&&y.parent===this||this.setEntity(y,null))}if(i.foreignKeyRef){const e=ie(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return(l=i.andChildrenGroup)==null||l.forEach(e=>{const y=ie(e),v=this.project.get(y);v&&(this.addToAndGroup(v,a),v.setParent(this,a))}),[...this.andChildrenGroup||[]].forEach(e=>{var v;((v=i.andChildrenGroup)==null?void 0:v.find(T=>ie(T)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=ie(e),v=this.project.get(y);v&&(this.addToOrGroup(v,a),v.setParent(this,a))}),[...this.orChildrenGroup||[]].forEach(e=>{var v;((v=i.orChildrenGroup)==null?void 0:v.find(T=>ie(T)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],c=[];if(this.initialData.parent){const e=ie(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=ie(this.initialData.entity),y=this.project.get(e);y&&(y.type===p.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==p.BuiltInBaseEntity&&y.type!==p.PrimitiveEntity&&i.push(y)))}if(this.initialData.foreignKeyRef){const e=ie(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:g(i),added:g(a),removed:g(l),affected:g(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.AfterAllChildrenInitialized))){var y,v,T;if(!this.checkCanEdit(this,i))return S.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===p.DataType){let I=this.index||0;const E=(this.parentRelationType===ir.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter($=>!$.deleted&&$.id!==this.id);E.length&&(I>E.length+1?I=E.length:I<0&&(I=0)),E.find($=>($.index||0)===I&&!$.deleted)&&E.filter($=>($.index||0)>=I&&!$.deleted).forEach($=>{$.metaSync({index:($.index||0)+1},i),i==null||i.add($,F.Updated),a.push($)}),this.metaSync({index:I},i)}return(v=this.andChildrenGroup)!=null&&v.length&&this.andChildrenGroup.sort((I,E)=>(I.index||0)-(E.index||0)),(T=this.orChildrenGroup)!=null&&T.length&&this.orChildrenGroup.sort((I,E)=>(I.index||0)-(E.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],c=[],e=[];return this.parent.type===p.DataType?(this.parentRelationType===ir.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===ir.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===p.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==p.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}setParent(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,F.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}removeChildGroup(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RemoveChildGroup))){if(!this.checkCanEdit(this,a))return S.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const l=this.andChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.andChildrenGroup.splice(l,1),a==null||a.add(this,F.Updated))}if(this.orChildrenGroup){const l=this.orChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.orChildrenGroup.splice(l,1),a==null||a.add(this,F.Updated))}return a==null||a.attemptAutoclose(P.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"init-children"))){var a,l,c,e,y,v,T,I,E,D;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===p.GenericReference){const $=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=$}else this.entity=ae(this.initialData.entity,this.project),(((l=(a=this.initialData.entity)==null?void 0:a.parent)==null?void 0:l.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===p.GenericReference&&((v=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:v.entityId)==this.id)&&this.entity.setParent(this,null),(I=(T=this.entity).initChildren)==null||I.call(T,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===p.GenericReference){const $=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=$}else this.foreignKeyRef=ae(this.initialData.foreignKeyRef,this.project),(D=(E=this.foreignKeyRef).initChildren)==null||D.call(E,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map($=>{const B=ae($,this.project);return B.setParent(this,null),B.initChildren(i),B})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map($=>{const B=ae($,this.project);return B.setParent(this,null),B.initChildren(i),B})),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 k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const l=ur(this,i,a),c=dr(this,l),e=this.toMeta();return this.options=l.options||e.options,this.parentRelationType=l.parentRelationType||e.parentRelationType,this.isList=l.isList!==void 0?l.isList:e.isList,this.inferred=l.inferred!==void 0?l.inferred:e.inferred,this.like=l.like!==void 0?l.like:e.like,this.asType=l.asType!==void 0?l.asType:e.asType,this.index=l.index!==void 0?l.index:e.index,this.implementationChooseOne=l.implementationChooseOne!==void 0?l.implementationChooseOne:e.implementationChooseOne,this.staticEntities=l.staticEntities!==void 0?l.staticEntities:e.staticEntities,this.interactiveEntities=l.interactiveEntities!==void 0?l.interactiveEntities:e.interactiveEntities,this.actionEntities=l.actionEntities!==void 0?l.actionEntities:e.actionEntities,super.baseMetaSync(l,this,a),l.deleted===!0&&!e.deleted?a==null||a.add(this,F.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,F.Added):c&&(a==null||a.add(this,F.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=we,...a){return await Ht.repository.APILoad(this.id,...a),this}async APICreate(i=we,...a){return await Ht.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=we,...a){return await Ht.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=we,...a){return await Ht.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=we,...a){return await Ht.repository.APIClone(this.id,...a),this}async APILoadVersion(i=we,a,...l){return await Ht.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RemoveFromParent))){var y,v;if(!this.checkCanEdit(this,i))return S.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===p.DataType)this.parent.removeChildGroup(this,i);else if(((v=this.parent)==null?void 0:v.type)===p.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const T=this.parent;T==null||T.removeDataType(i)}return this.parent&&this.parent.type!==p.BuiltInBaseEntity&&a.push(this.parent),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(c),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RemoveEntity))){const l=[],c=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.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:I,added:E}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),c.push(...I),e.push(...E)}),this.entity&&this.entity.type===p.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:T}=this.entity.remove({ignoreUpstream:!0},a);l.push(...v),c.push(...T)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:T,updated:I}=v.remove({ignoreUpstream:!0},a);c.push(...T),l.push(...I)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:T,updated:I}=v.remove({ignoreUpstream:!0},a);c.push(...T),l.push(...I)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(c),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return S.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:I}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...T),a.push(...I)}),this.entity&&this.entity.type===p.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);l.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:T}=y.restore({},i);l.push(...v),a.push(...T)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:T}=y.restore({},i);l.push(...v),a.push(...T)}),this.parent.type===p.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===p.DataType){const y=this.parent;this.parentRelationType===ir.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===ir.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===p.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),l.push(y)}else{const y=this.parent;y.setDataType(this,i),l.push(y)}return i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(c),affected:g(e),self:this}}toFlat(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlat(i))||[]])}toFlatIds(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,c,e,y;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,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((a=this.foreignKeyRef)==null?void 0:a.toJSON(i))||null,andChildrenGroup:((l=this.andChildrenGroup)==null?void 0:l.map(v=>v.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(v=>v.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((y=this.entity)==null?void 0:y.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=He){var l,c,e,y,v,T,I,E,D,$;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||vr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(c=i.seenEntities)!=null&&c.has(a)||(e=i.seenEntities)!=null&&e.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:L.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((T=this.foreignKeyRef)==null?void 0:T.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((I=this.andChildrenGroup)==null?void 0:I.map(B=>B.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((E=this.orChildrenGroup)==null?void 0:E.map(B=>B.toJSONClone({...i,newId:null})))||null,entity:((D=this.entity)==null?void 0:D.parent)===this?this.entity.toJSONClone({...i,newId:null}):(($=this.entity)==null?void 0:$.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+L.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=He){var l,c,e,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,type:this.type,editable:this.editable,deletable:this.deletable,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.toReference(i))||null,andChildrenGroup:((e=this.andChildrenGroup)==null?void 0:e.map(T=>T.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(T=>T.toReference(i)))||null,entity:((v=this.entity)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(y=>y.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i,a,l,c;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,andChildrenGroup:((i=this.andChildrenGroup)==null?void 0:i.map(e=>e.id))||null,orChildrenGroup:((a=this.orChildrenGroup)==null?void 0:a.map(e=>e.id))||null,foreignKeyRef:((l=this.foreignKeyRef)==null?void 0:l.id)||null,asType:this.asType,entity:((c=this.entity)==null?void 0:c.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==p.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,a,l,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===p.DefinitionEntity&&((l=this.entity)==null?void 0:l.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){const i=N6(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,c=!0){var B,x,G,W;const e=or(a,this),y=a||this.parent,v=l||L.UUID.uuid(),T=new Set([...this.project.getAllBuiltInIds(),...Qi()]),I={id:v,version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,foreignKeyRef:((B=this.foreignKeyRef)==null?void 0:B.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ci(I,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,F.Added);const D=(x=this.andChildrenGroup)==null?void 0:x.map(Z=>T.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c)),$=(G=this.orChildrenGroup)==null?void 0:G.map(Z=>T.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c));if(E.andChildrenGroup=D||null,E.orChildrenGroup=$||null,this.entity&&this.entity.type===p.DefinitionEntity&&((W=this.entity)==null?void 0:W.parent)===this)if(T.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const Z=this.entity.clone(i,E,L.UUID.uuid(),c);E.setEntity(Z,i)}else if(this.entity){const Z=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(Z,i)}return i==null||i.attemptAutoclose(P.CloneEntity,this.id),E}merge(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.MergeDataTypes))){var v,T,I;const l=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,a))return S.warn(`[${P.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},a),a==null||a.add(this,F.Updated),l.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},a),a==null||a.add(this,F.Updated),l.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},a),a==null||a.add(this,F.Updated),l.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},a),a==null||a.add(this,F.Updated),l.push(this)),((v=i==null?void 0:i.foreignKeyRef)==null?void 0:v.id)!==((T=this.foreignKeyRef)==null?void 0:T.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,a),a==null||a.add(this,F.Updated),l.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===p.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((I=this.entity)==null?void 0:I.type)===p.DefinitionEntity&&this.entity.parent===this)Tw(this.entity,i.entity)||FZ(this.entity,i.entity,a);else{const E=i.entity.clone(a,this,L.UUID.uuid(),!0);this.setEntity(E,a),c.push(E)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,a),a==null||a.add(this,F.Updated),l.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},a),a==null||a.attemptAutoclose(P.MergeDataTypes,this.id),{updated:g(l),added:g(c),removed:g(e),affected:g(y),self:this}}addToAndGroup(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.AddToAndGroup))){return this.checkCanEdit(this,a)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),a==null||a.add(i,F.Affected)),a==null||a.attemptAutoclose(P.AddToAndGroup,this.id),this):(S.warn(`[${P.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddToAndGroup,this.id),this)}addToOrGroup(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.AddToOrGroup))){return this.checkCanEdit(this,a)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),a==null||a.add(i,F.Affected)),a==null||a.attemptAutoclose(P.AddToOrGroup,this.id),this):(S.warn(`[${P.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddToOrGroup,this.id),this)}setForeignKeyRef(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,a))return S.warn(`[${P.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataTypeForeignKeyRef,this.id),this;const l=this.foreignKeyRef;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose(P.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,a))return S.warn(`[${P.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataTypeEntityValue,this.id),this;const l=this.entity;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.entity=i,a==null||a.add(this,F.Affected),l&&l.type===p.DefinitionEntity&&((c=l.parent)==null?void 0:c.id)===this.id&&(l==null||l.remove({ignoreUpstream:!0},a))),a==null||a.attemptAutoclose(P.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===p.DefinitionEntity||this.entity.type===p.BuiltInBaseEntity||this.entity.name===ne.KeyValue)&&!this.isList}canBeObject(){var a;let i=!1;if(this.parent.type!==p.DataType&&this.parent.type!==p.ActionDescriptor&&this.parent.type!==p.BuiltInBaseEntity&&this.parent.type!==p.DefinitionEntity&&this.parent.type!==p.FunctionDeclaration){const l=(a=this.project.requestActiveDynamicValue(this.parent))==null?void 0:a.value;l?!l.valueAsType&&(l.value===""||l.value===null||bi(l))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===ne.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===p.DefinitionEntity}isInlineDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===p.DefinitionEntity&&((a=this.entity.parent)==null?void 0:a.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===p.DefinitionEntity&&((a=this.entity)==null?void 0:a.parent)!==this}canModifyObjectStructure(){var a;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((a=this.entity)==null?void 0:a.name)===ne.KeyValue)&&!i}inferFromInputs(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"infer-data-type-from-inputs"))){var v;const l=[],c=[],e=[],y=[];if(!this.inferred)return a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const T=X(this.parent,this.project)+" data type definition",I={id:L.UUID.uuid(),deletable:!0,editable:!0,type:p.DefinitionEntity,version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||M().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:T,description:((v=this.parent)==null?void 0:v.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:null,implements:[],abstractMethods:[],allPropertiesImplement:null,additionalPropertiesDataType:null,additionalProperties:!0,x:0,y:0,parent:this.toReference()},E=ae(I,this.project);E.hydrateAncestors(),E.setParent(this,a),E.initChildren(a),a==null||a.add(E,F.Added),E.metaSync(I,a),this.setEntity(E,a),a==null||a.add(this,F.Updated)}if(this.entity){const{updated:T,added:I,removed:E,affected:D}=this.entity.inferFromInputs(i,a);c.push(...T),l.push(...I),e.push(...E),y.push(...D)}return this.like||this.metaSync({like:!0},a),a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:g(c),added:g(l),removed:g(e),affected:g(y),self:this}}};_(Ht,"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}),_(Ht,"type",p.DataType),_(Ht,"USER_MANAGED_PARENT_TYPES",[p.Property,p.ArgumentDeclaration,p.ReturnStatement,p.BreakStatement,p.ContinueStatement,p.VariableDeclaration,p.ValueDescriptor,p.InputMap,p.OutputMap,p.DataType,p.FunctionDeclaration,p.ActionDescriptor,p.Loop,p.Search,p.DefinitionEntity]),_(Ht,"PARENT_TYPES",[...Ht.USER_MANAGED_PARENT_TYPES,p.BuiltInBaseEntity]),_(Ht,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),_(Ht,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),_(Ht,"BASE_PROPERTIES",[...Ht.MUTABLE_BASE_PROPERTIES,...Ht.INMUTABLE_BASE_PROPERTIES]),_(Ht,"MUTABLE_META_PROPERTIES",[...Ht.MUTABLE_BASE_PROPERTIES,"inferred"]),_(Ht,"INMUTABLE_META_PROPERTIES",[...Ht.INMUTABLE_BASE_PROPERTIES]),_(Ht,"META_PROPERTIES",[...Ht.MUTABLE_META_PROPERTIES,...Ht.INMUTABLE_META_PROPERTIES]),_(Ht,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),_(Ht,"INMUTABLE_UPSTREAM_PROPERTIES",[]),_(Ht,"UPSTREAM_PROPERTIES",[...Ht.MUTABLE_UPSTREAM_PROPERTIES,...Ht.INMUTABLE_UPSTREAM_PROPERTIES]),_(Ht,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Ht,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),_(Ht,"DOWNSTREAM_PROPERTIES",[...Ht.MUTABLE_DOWNSTREAM_PROPERTIES,...Ht.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Ht,"PROPERTIES",[...Ht.META_PROPERTIES,...Ht.UPSTREAM_PROPERTIES,...Ht.DOWNSTREAM_PROPERTIES]);let zi=Ht;function lCe(d,u){var $,B,x;const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.SyncInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.SyncInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[],y=((($=d.implements)==null?void 0:$.inputs)||[]).filter(G=>G.parentRelationType===me.FixedArguments&&!d.inputs.find(W=>W.implements.find(Z=>Z.id===G.id)));d.inputs.sort((G,W)=>G.index-W.index);const v=((B=d.implements)==null?void 0:B.id)===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id;let T=!0;if(v){const G=d.parent.properties.find(Z=>Z.implements.find(z=>z.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.method.id)),W=(((x=G==null?void 0:G.defaultValue)==null?void 0:x.value)||"").toString().toLowerCase();T=!(W==="get"||W==="head"||W==="options")}y.forEach(G=>{if(G.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.inputs.body.id&&!T)return;d.inputs.forEach(Q=>{Q.index>=G.index&&Q.metaSync({index:Q.index+1},i)});const Z=Cn.new(i);Z.implements=[G.toJSON()],Z.index=G.index,Z.parent=d.toReference(),Z.name=G.name;const z=ae(Z,d.project);z.hydrateAncestors(),i==null||i.add(z,F.Added),z.setParent(d,i),z.initChildren(i),z.addSelfToProject(i)}),d.inputs.forEach(G=>{const{updated:W,added:Z,removed:z,affected:Q}=G.afterAllChildrenInitialized(i);a.push(...W),l.push(...Z),c.push(...z),e.push(...Q)}),d.inputs.sort((G,W)=>G.index-W.index);const{updated:I,added:E,removed:D}=d.removeUnrecognizedInputs(i);return a.push(...I),l.push(...E),c.push(...D),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function oCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.SyncInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.SyncInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];d.inputs.sort((I,E)=>I.index-E.index);const{updated:y,added:v,removed:T}=d.removeUnrecognizedInputs(i);return a.push(...y),l.push(...v),c.push(...T),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function dCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.SyncInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.SyncInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];d.inputs.sort((I,E)=>I.index-E.index);const{updated:y,added:v,removed:T}=d.removeUnrecognizedInputs(i);return a.push(...y),l.push(...v),c.push(...T),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function uCe(d,u){var E;const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];d.inputs.forEach(D=>{var B;if(!(((B=d.implements)==null?void 0:B.inputs)||[]).find(x=>D.implements.find(G=>G.id===x.id))){const x=D.remove({ignoreUpstream:!1},i);c.push(...x.removed),a.push(...x.updated)}}),d.inputs.filter((D,$)=>{const B=d.inputs.findIndex(G=>G.implements.every(W=>D.implements.includes(W))&&G.name===D.name&&G!==D);if(B===-1)return!1;const x=d.inputs[B];return M(x==null?void 0:x.createdAt).isSame(M(D.createdAt))?$>B:!!M(x==null?void 0:x.createdAt).isAfter(D.createdAt)}).forEach(D=>{const $=D.remove({ignoreUpstream:!1},i);c.push(...$.removed),a.push(...$.updated)});let v=!0;const T=d.parent.properties.find(D=>D.implements.find($=>$.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.method.id)),I=(((E=T==null?void 0:T.defaultValue)==null?void 0:E.value)||"").toString().toLowerCase();if(v=!(I==="get"||I==="head"||I==="options"),!v){const D=d.inputs.find($=>$.implements.find(B=>B.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.inputs.body.id));if(D){const $=D.remove({ignoreUpstream:!1},i);c.push(...$.removed),a.push(...$.updated)}}return i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function pCe(d,u){var i,a,l,c;return d.parent.type!==p.Loop?!1:((a=(i=d.dataType)==null?void 0:i.entity)==null?void 0:a.id)===((c=(l=u==null?void 0:u.dataType)==null?void 0:l.entity)==null?void 0:c.id)}function cCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];return d.inputs.forEach(v=>{var I;if(pCe(d,v))return;if(!(((I=d.implements)==null?void 0:I.inputs)||[]).find(E=>v.implements.find(D=>D.id===E.id))){const E=v.remove({ignoreUpstream:!1},i);c.push(...E.removed),a.push(...E.updated)}}),d.inputs.filter((v,T)=>{const I=d.inputs.findIndex(D=>D.implements.every($=>v.implements.includes($))&&D.name===v.name&&D!==v);if(I===-1)return!1;const E=d.inputs[I];return M(E==null?void 0:E.createdAt).isSame(M(v.createdAt))?T>I:!!M(E==null?void 0:E.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function fCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];return d.inputs.filter((v,T)=>{const I=d.inputs.findIndex(D=>D.implements.every($=>v.implements.includes($))&&D.name===v.name&&D!==v);if(I===-1)return!1;const E=d.inputs[I];return M(E==null?void 0:E.createdAt).isSame(M(v.createdAt))?T>I:!!M(E==null?void 0:E.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function yCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];return d.inputs.filter((v,T)=>{const I=d.inputs.findIndex(D=>D.implements.every($=>v.implements.includes($))&&D.name===v.name&&D!==v);if(I===-1)return!1;const E=d.inputs[I];return M(E==null?void 0:E.createdAt).isSame(M(v.createdAt))?T>I:!!M(E==null?void 0:E.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}var V6=(d=>(d.FunctionDeclarationImplements="function-declaration-implements",d.FunctionDeclarationExtends="function-declaration-extends",d.FunctionDeclarationDataType="function-declaration-data-type",d.FunctionDeclarationDataTypeEntity="function-declaration-data-type-entity",d))(V6||{});const zt=class zt extends mr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"collapsed");_(this,"private");_(this,"index",null);_(this,"type",p.FunctionDeclaration);_(this,"implements",null);_(this,"extends",null);_(this,"dataType",null);_(this,"inputs",[]);_(this,"calls",[]);_(this,"parent");_(this,"detachedChildren",[]);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(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:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.FunctionDeclaration,name:"",dataType:null,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=ie(i.parent);l=a.get(T)}let c=null;if(i.implements){const T=ie(i.implements);c=a.get(T)}let e=null;if(i.extends){const T=ie(i.extends);e=a.get(T)}const y={id:i.id,version:L.UUID.uuid(),createdAt:M().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:p.FunctionDeclaration,dataType:null,index:l.type===p.DefinitionEntity?l.methods.length:null,codeName:i.codeName||null,description:i.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:c,extends:e,x:0,y:0,parent:l},v=ae(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){var E;let l=JSON.parse(JSON.stringify(i));const c=[],e=kr(l,{parent:{list:!1,types:[p.Project,p.InstalledProject,p.DefinitionEntity,p.Loop],optional:!0},implements:{list:!1,types:[p.ActionDescriptor],optional:!0}},a);l=e.modifiedData;const y=cR(l,a),v=l.parent?a.get(l.parent):null;if(v&&v.type===p.DefinitionEntity){const D=v,B=ln(D).filter(G=>!G.interactive),x=D.methods.find(G=>{var W;return((W=G.implements)==null?void 0:W.id)===l.implements});if(x&&c.push(new fe({id:`${l.id}--${pe.MethodOverwritesOtherSiblingWithSameImplementation}`,code:pe.MethodOverwritesOtherSiblingWithSameImplementation,severity:te.Error,message:`The '${p.FunctionDeclaration}' with id "${l.id}" is trying to implement the '${p.ActionDescriptor}' with id "${l.implements}", but the parent definition-entity already has a ${p.FunctionDeclaration} with id '${x.id}' that implements the same base method.
|
|
26
|
+
Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}I===p.DataType&&(!l.parentRelationType||!(l.parentRelationType===ir.AndDataTypeGroup||l.parentRelationType===ir.OrDataTypeGroup))&&c.push(new fe({id:`${i.id}--${J.InvalidParentRelationType}`,code:J.InvalidParentRelationType,severity:te.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`}))}return{errors:c,modifiedData:l}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let a=0;for(const l of i)if(l.isResolved&&(a++,a>1))return!0}return!1}get isResolved(){return[p.BuiltInBaseEntity,p.ActionDescriptor].includes(this.parent.type)||_o(this.parent)?!0:!(!this.entity&&!this.isGroup)}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 k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const c=[],e=[],y=[],v=[];return a==="entity-field"&&this.setEntity(null,l),a==="foreign-key-ref-field"&&this.setForeignKeyRef(null,l),{updated:g(c),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const c=[],e=[],y=[],v=[];return a==="entity-field"&&this.setEntity(i,l),a==="foreign-key-ref-field"&&this.setForeignKeyRef(i,l),{updated:g(c),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,c;return(a=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.unsubscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,a,l,c;return(a=(i=this.entity)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.subscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ht(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.entity=this.entity,i.foreignKeyRef=this.foreignKeyRef,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],c=[],e=[];if(this.parent&&this.parent.type!==p.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],c=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[I,E]of this.knownVersions||new Map){if(T.set(I,E),E.activeVersion=!1,E.knownVersions)for(const[D,$]of E.knownVersions)T.set(D,$);E.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 Ht(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.entity=y.entity,this.foreignKeyRef=y.foreignKeyRef,this.andChildrenGroup=y.andChildrenGroup?[...y.andChildrenGroup]:null,this.orChildrenGroup=y.orChildrenGroup?[...y.orChildrenGroup]:null,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.UpdateWithShallowTransfer))){var l,c;if(!this.checkCanEdit(this,a))return S.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;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 e=ie(i.parent),y=this.project.get(e),v=this.parent;if(v&&v.id!==(y==null?void 0:y.id)&&this.removeFromParent(a),y)this.setParent(y,a),this.addSelfToProject(a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=ie(i.entity),y=this.project.get(e);y&&(y.type===p.DefinitionEntity&&y.parent===this||this.setEntity(y,null))}if(i.foreignKeyRef){const e=ie(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return(l=i.andChildrenGroup)==null||l.forEach(e=>{const y=ie(e),v=this.project.get(y);v&&(this.addToAndGroup(v,a),v.setParent(this,a))}),[...this.andChildrenGroup||[]].forEach(e=>{var v;((v=i.andChildrenGroup)==null?void 0:v.find(T=>ie(T)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=ie(e),v=this.project.get(y);v&&(this.addToOrGroup(v,a),v.setParent(this,a))}),[...this.orChildrenGroup||[]].forEach(e=>{var v;((v=i.orChildrenGroup)==null?void 0:v.find(T=>ie(T)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],c=[];if(this.initialData.parent){const e=ie(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=ie(this.initialData.entity),y=this.project.get(e);y&&(y.type===p.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==p.BuiltInBaseEntity&&y.type!==p.PrimitiveEntity&&i.push(y)))}if(this.initialData.foreignKeyRef){const e=ie(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:g(i),added:g(a),removed:g(l),affected:g(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.AfterAllChildrenInitialized))){var y,v,T;if(!this.checkCanEdit(this,i))return S.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===p.DataType){let I=this.index||0;const E=(this.parentRelationType===ir.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter($=>!$.deleted&&$.id!==this.id);E.length&&(I>E.length+1?I=E.length:I<0&&(I=0)),E.find($=>($.index||0)===I&&!$.deleted)&&E.filter($=>($.index||0)>=I&&!$.deleted).forEach($=>{$.metaSync({index:($.index||0)+1},i),i==null||i.add($,F.Updated),a.push($)}),this.metaSync({index:I},i)}return(v=this.andChildrenGroup)!=null&&v.length&&this.andChildrenGroup.sort((I,E)=>(I.index||0)-(E.index||0)),(T=this.orChildrenGroup)!=null&&T.length&&this.orChildrenGroup.sort((I,E)=>(I.index||0)-(E.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],c=[],e=[];return this.parent.type===p.DataType?(this.parentRelationType===ir.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===ir.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===p.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==p.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:this}}setParent(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,F.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}removeChildGroup(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RemoveChildGroup))){if(!this.checkCanEdit(this,a))return S.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const l=this.andChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.andChildrenGroup.splice(l,1),a==null||a.add(this,F.Updated))}if(this.orChildrenGroup){const l=this.orChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.orChildrenGroup.splice(l,1),a==null||a.add(this,F.Updated))}return a==null||a.attemptAutoclose(P.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"init-children"))){var a,l,c,e,y,v,T,I,E,D;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===p.GenericReference){const $=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=$}else this.entity=ae(this.initialData.entity,this.project),(((l=(a=this.initialData.entity)==null?void 0:a.parent)==null?void 0:l.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===p.GenericReference&&((v=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:v.entityId)==this.id)&&this.entity.setParent(this,null),(I=(T=this.entity).initChildren)==null||I.call(T,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===p.GenericReference){const $=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=$}else this.foreignKeyRef=ae(this.initialData.foreignKeyRef,this.project),(D=(E=this.foreignKeyRef).initChildren)==null||D.call(E,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map($=>{const B=ae($,this.project);return B.setParent(this,null),B.initChildren(i),B})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map($=>{const B=ae($,this.project);return B.setParent(this,null),B.initChildren(i),B})),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 k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const l=ur(this,i,a),c=dr(this,l),e=this.toMeta();return this.options=l.options||e.options,this.parentRelationType=l.parentRelationType||e.parentRelationType,this.isList=l.isList!==void 0?l.isList:e.isList,this.inferred=l.inferred!==void 0?l.inferred:e.inferred,this.like=l.like!==void 0?l.like:e.like,this.asType=l.asType!==void 0?l.asType:e.asType,this.index=l.index!==void 0?l.index:e.index,this.implementationChooseOne=l.implementationChooseOne!==void 0?l.implementationChooseOne:e.implementationChooseOne,this.staticEntities=l.staticEntities!==void 0?l.staticEntities:e.staticEntities,this.interactiveEntities=l.interactiveEntities!==void 0?l.interactiveEntities:e.interactiveEntities,this.actionEntities=l.actionEntities!==void 0?l.actionEntities:e.actionEntities,super.baseMetaSync(l,this,a),l.deleted===!0&&!e.deleted?a==null||a.add(this,F.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,F.Added):c&&(a==null||a.add(this,F.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=we,...a){return await Ht.repository.APILoad(this.id,...a),this}async APICreate(i=we,...a){return await Ht.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=we,...a){return await Ht.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=we,...a){return await Ht.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=we,...a){return await Ht.repository.APIClone(this.id,...a),this}async APILoadVersion(i=we,a,...l){return await Ht.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RemoveFromParent))){var y,v;if(!this.checkCanEdit(this,i))return S.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===p.DataType)this.parent.removeChildGroup(this,i);else if(((v=this.parent)==null?void 0:v.type)===p.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const T=this.parent;T==null||T.removeDataType(i)}return this.parent&&this.parent.type!==p.BuiltInBaseEntity&&a.push(this.parent),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(c),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RemoveEntity))){const l=[],c=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.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:I,added:E}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...T),c.push(...I),e.push(...E)}),this.entity&&this.entity.type===p.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:T}=this.entity.remove({ignoreUpstream:!0},a);l.push(...v),c.push(...T)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:T,updated:I}=v.remove({ignoreUpstream:!0},a);c.push(...T),l.push(...I)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:T,updated:I}=v.remove({ignoreUpstream:!0},a);c.push(...T),l.push(...I)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(c),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return S.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:I}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...T),a.push(...I)}),this.entity&&this.entity.type===p.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);l.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:T}=y.restore({},i);l.push(...v),a.push(...T)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:T}=y.restore({},i);l.push(...v),a.push(...T)}),this.parent.type===p.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===p.DataType){const y=this.parent;this.parentRelationType===ir.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===ir.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===p.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),l.push(y)}else{const y=this.parent;y.setDataType(this,i),l.push(y)}return i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(c),affected:g(e),self:this}}toFlat(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlat(i))||[]])}toFlatIds(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,c,e,y;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,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((a=this.foreignKeyRef)==null?void 0:a.toJSON(i))||null,andChildrenGroup:((l=this.andChildrenGroup)==null?void 0:l.map(v=>v.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(v=>v.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((y=this.entity)==null?void 0:y.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=He){var l,c,e,y,v,T,I,E,D,$;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||vr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(c=i.seenEntities)!=null&&c.has(a)||(e=i.seenEntities)!=null&&e.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:L.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((T=this.foreignKeyRef)==null?void 0:T.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((I=this.andChildrenGroup)==null?void 0:I.map(B=>B.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((E=this.orChildrenGroup)==null?void 0:E.map(B=>B.toJSONClone({...i,newId:null})))||null,entity:((D=this.entity)==null?void 0:D.parent)===this?this.entity.toJSONClone({...i,newId:null}):(($=this.entity)==null?void 0:$.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+L.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=He){var l,c,e,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,type:this.type,editable:this.editable,deletable:this.deletable,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.toReference(i))||null,andChildrenGroup:((e=this.andChildrenGroup)==null?void 0:e.map(T=>T.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(T=>T.toReference(i)))||null,entity:((v=this.entity)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(y=>y.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i,a;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,foreignKeyRef:((i=this.foreignKeyRef)==null?void 0:i.id)||null,asType:this.asType,entity:((a=this.entity)==null?void 0:a.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==p.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,a,l,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===p.DefinitionEntity&&((l=this.entity)==null?void 0:l.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){const i=N6(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,c=!0){var B,x,G,W;const e=or(a,this),y=a||this.parent,v=l||L.UUID.uuid(),T=new Set([...this.project.getAllBuiltInIds(),...Qi()]),I={id:v,version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,foreignKeyRef:((B=this.foreignKeyRef)==null?void 0:B.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ci(I,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,F.Added);const D=(x=this.andChildrenGroup)==null?void 0:x.map(Z=>T.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c)),$=(G=this.orChildrenGroup)==null?void 0:G.map(Z=>T.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c));if(E.andChildrenGroup=D||null,E.orChildrenGroup=$||null,this.entity&&this.entity.type===p.DefinitionEntity&&((W=this.entity)==null?void 0:W.parent)===this)if(T.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const Z=this.entity.clone(i,E,L.UUID.uuid(),c);E.setEntity(Z,i)}else if(this.entity){const Z=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(Z,i)}return i==null||i.attemptAutoclose(P.CloneEntity,this.id),E}merge(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.MergeDataTypes))){var v,T,I;const l=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,a))return S.warn(`[${P.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},a),a==null||a.add(this,F.Updated),l.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},a),a==null||a.add(this,F.Updated),l.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},a),a==null||a.add(this,F.Updated),l.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},a),a==null||a.add(this,F.Updated),l.push(this)),((v=i==null?void 0:i.foreignKeyRef)==null?void 0:v.id)!==((T=this.foreignKeyRef)==null?void 0:T.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,a),a==null||a.add(this,F.Updated),l.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===p.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((I=this.entity)==null?void 0:I.type)===p.DefinitionEntity&&this.entity.parent===this)Tw(this.entity,i.entity)||FZ(this.entity,i.entity,a);else{const E=i.entity.clone(a,this,L.UUID.uuid(),!0);this.setEntity(E,a),c.push(E)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,a),a==null||a.add(this,F.Updated),l.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},a),a==null||a.attemptAutoclose(P.MergeDataTypes,this.id),{updated:g(l),added:g(c),removed:g(e),affected:g(y),self:this}}addToAndGroup(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.AddToAndGroup))){return this.checkCanEdit(this,a)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),a==null||a.add(i,F.Affected)),a==null||a.attemptAutoclose(P.AddToAndGroup,this.id),this):(S.warn(`[${P.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddToAndGroup,this.id),this)}addToOrGroup(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.AddToOrGroup))){return this.checkCanEdit(this,a)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),a==null||a.add(i,F.Affected)),a==null||a.attemptAutoclose(P.AddToOrGroup,this.id),this):(S.warn(`[${P.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddToOrGroup,this.id),this)}setForeignKeyRef(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,a))return S.warn(`[${P.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataTypeForeignKeyRef,this.id),this;const l=this.foreignKeyRef;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose(P.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,P.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,a))return S.warn(`[${P.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataTypeEntityValue,this.id),this;const l=this.entity;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.entity=i,a==null||a.add(this,F.Affected),l&&l.type===p.DefinitionEntity&&((c=l.parent)==null?void 0:c.id)===this.id&&(l==null||l.remove({ignoreUpstream:!0},a))),a==null||a.attemptAutoclose(P.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===p.DefinitionEntity||this.entity.type===p.BuiltInBaseEntity||this.entity.name===ne.KeyValue)&&!this.isList}canBeObject(){var a;let i=!1;if(this.parent.type!==p.DataType&&this.parent.type!==p.ActionDescriptor&&this.parent.type!==p.BuiltInBaseEntity&&this.parent.type!==p.DefinitionEntity&&this.parent.type!==p.FunctionDeclaration){const l=(a=this.project.requestActiveDynamicValue(this.parent))==null?void 0:a.value;l?!l.valueAsType&&(l.value===""||l.value===null||bi(l))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===ne.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===p.DefinitionEntity}isInlineDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===p.DefinitionEntity&&((a=this.entity.parent)==null?void 0:a.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===p.DefinitionEntity&&((a=this.entity)==null?void 0:a.parent)!==this}canModifyObjectStructure(){var a;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((a=this.entity)==null?void 0:a.name)===ne.KeyValue)&&!i}inferFromInputs(i,a=this.project.addChangeSet(new k(this.project,L.sessionAuthor,M().toISOString(),this,!0,"infer-data-type-from-inputs"))){var v;const l=[],c=[],e=[],y=[];if(!this.inferred)return a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const T=X(this.parent,this.project)+" data type definition",I={id:L.UUID.uuid(),deletable:!0,editable:!0,type:p.DefinitionEntity,version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||M().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:T,description:((v=this.parent)==null?void 0:v.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:null,implements:[],abstractMethods:[],allPropertiesImplement:null,additionalPropertiesDataType:null,additionalProperties:!0,x:0,y:0,parent:this.toReference()},E=ae(I,this.project);E.hydrateAncestors(),E.setParent(this,a),E.initChildren(a),a==null||a.add(E,F.Added),E.metaSync(I,a),this.setEntity(E,a),a==null||a.add(this,F.Updated)}if(this.entity){const{updated:T,added:I,removed:E,affected:D}=this.entity.inferFromInputs(i,a);c.push(...T),l.push(...I),e.push(...E),y.push(...D)}return this.like||this.metaSync({like:!0},a),a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:g(c),added:g(l),removed:g(e),affected:g(y),self:this}}};_(Ht,"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}),_(Ht,"type",p.DataType),_(Ht,"USER_MANAGED_PARENT_TYPES",[p.Property,p.ArgumentDeclaration,p.ReturnStatement,p.BreakStatement,p.ContinueStatement,p.VariableDeclaration,p.ValueDescriptor,p.InputMap,p.OutputMap,p.DataType,p.FunctionDeclaration,p.ActionDescriptor,p.Loop,p.Search,p.DefinitionEntity]),_(Ht,"PARENT_TYPES",[...Ht.USER_MANAGED_PARENT_TYPES,p.BuiltInBaseEntity]),_(Ht,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),_(Ht,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),_(Ht,"BASE_PROPERTIES",[...Ht.MUTABLE_BASE_PROPERTIES,...Ht.INMUTABLE_BASE_PROPERTIES]),_(Ht,"MUTABLE_META_PROPERTIES",[...Ht.MUTABLE_BASE_PROPERTIES,"inferred"]),_(Ht,"INMUTABLE_META_PROPERTIES",[...Ht.INMUTABLE_BASE_PROPERTIES]),_(Ht,"META_PROPERTIES",[...Ht.MUTABLE_META_PROPERTIES,...Ht.INMUTABLE_META_PROPERTIES]),_(Ht,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),_(Ht,"INMUTABLE_UPSTREAM_PROPERTIES",[]),_(Ht,"UPSTREAM_PROPERTIES",[...Ht.MUTABLE_UPSTREAM_PROPERTIES,...Ht.INMUTABLE_UPSTREAM_PROPERTIES]),_(Ht,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Ht,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),_(Ht,"DOWNSTREAM_PROPERTIES",[...Ht.MUTABLE_DOWNSTREAM_PROPERTIES,...Ht.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Ht,"PROPERTIES",[...Ht.META_PROPERTIES,...Ht.UPSTREAM_PROPERTIES,...Ht.DOWNSTREAM_PROPERTIES]);let zi=Ht;function lCe(d,u){var $,B,x;const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.SyncInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.SyncInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[],y=((($=d.implements)==null?void 0:$.inputs)||[]).filter(G=>G.parentRelationType===me.FixedArguments&&!d.inputs.find(W=>W.implements.find(Z=>Z.id===G.id)));d.inputs.sort((G,W)=>G.index-W.index);const v=((B=d.implements)==null?void 0:B.id)===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id;let T=!0;if(v){const G=d.parent.properties.find(Z=>Z.implements.find(z=>z.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.method.id)),W=(((x=G==null?void 0:G.defaultValue)==null?void 0:x.value)||"").toString().toLowerCase();T=!(W==="get"||W==="head"||W==="options")}y.forEach(G=>{if(G.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.inputs.body.id&&!T)return;d.inputs.forEach(Q=>{Q.index>=G.index&&Q.metaSync({index:Q.index+1},i)});const Z=Cn.new(i);Z.implements=[G.toJSON()],Z.index=G.index,Z.parent=d.toReference(),Z.name=G.name;const z=ae(Z,d.project);z.hydrateAncestors(),i==null||i.add(z,F.Added),z.setParent(d,i),z.initChildren(i),z.addSelfToProject(i)}),d.inputs.forEach(G=>{const{updated:W,added:Z,removed:z,affected:Q}=G.afterAllChildrenInitialized(i);a.push(...W),l.push(...Z),c.push(...z),e.push(...Q)}),d.inputs.sort((G,W)=>G.index-W.index);const{updated:I,added:E,removed:D}=d.removeUnrecognizedInputs(i);return a.push(...I),l.push(...E),c.push(...D),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function oCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.SyncInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.SyncInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];d.inputs.sort((I,E)=>I.index-E.index);const{updated:y,added:v,removed:T}=d.removeUnrecognizedInputs(i);return a.push(...y),l.push(...v),c.push(...T),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function dCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.SyncInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.SyncInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];d.inputs.sort((I,E)=>I.index-E.index);const{updated:y,added:v,removed:T}=d.removeUnrecognizedInputs(i);return a.push(...y),l.push(...v),c.push(...T),i==null||i.attemptAutoclose(P.SyncInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function uCe(d,u){var E;const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];d.inputs.forEach(D=>{var B;if(!(((B=d.implements)==null?void 0:B.inputs)||[]).find(x=>D.implements.find(G=>G.id===x.id))){const x=D.remove({ignoreUpstream:!1},i);c.push(...x.removed),a.push(...x.updated)}}),d.inputs.filter((D,$)=>{const B=d.inputs.findIndex(G=>G.implements.every(W=>D.implements.includes(W))&&G.name===D.name&&G!==D);if(B===-1)return!1;const x=d.inputs[B];return M(x==null?void 0:x.createdAt).isSame(M(D.createdAt))?$>B:!!M(x==null?void 0:x.createdAt).isAfter(D.createdAt)}).forEach(D=>{const $=D.remove({ignoreUpstream:!1},i);c.push(...$.removed),a.push(...$.updated)});let v=!0;const T=d.parent.properties.find(D=>D.implements.find($=>$.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.method.id)),I=(((E=T==null?void 0:T.defaultValue)==null?void 0:E.value)||"").toString().toLowerCase();if(v=!(I==="get"||I==="head"||I==="options"),!v){const D=d.inputs.find($=>$.implements.find(B=>B.id===ue["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.inputs.body.id));if(D){const $=D.remove({ignoreUpstream:!1},i);c.push(...$.removed),a.push(...$.updated)}}return i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function pCe(d,u){var i,a,l,c;return d.parent.type!==p.Loop?!1:((a=(i=d.dataType)==null?void 0:i.entity)==null?void 0:a.id)===((c=(l=u==null?void 0:u.dataType)==null?void 0:l.entity)==null?void 0:c.id)}function cCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];return d.inputs.forEach(v=>{var I;if(pCe(d,v))return;if(!(((I=d.implements)==null?void 0:I.inputs)||[]).find(E=>v.implements.find(D=>D.id===E.id))){const E=v.remove({ignoreUpstream:!1},i);c.push(...E.removed),a.push(...E.updated)}}),d.inputs.filter((v,T)=>{const I=d.inputs.findIndex(D=>D.implements.every($=>v.implements.includes($))&&D.name===v.name&&D!==v);if(I===-1)return!1;const E=d.inputs[I];return M(E==null?void 0:E.createdAt).isSame(M(v.createdAt))?T>I:!!M(E==null?void 0:E.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function fCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];return d.inputs.filter((v,T)=>{const I=d.inputs.findIndex(D=>D.implements.every($=>v.implements.includes($))&&D.name===v.name&&D!==v);if(I===-1)return!1;const E=d.inputs[I];return M(E==null?void 0:E.createdAt).isSame(M(v.createdAt))?T>I:!!M(E==null?void 0:E.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}function yCe(d,u){const i=u===void 0?d.project.addChangeSet(new k(d.project,L.sessionAuthor,M().toISOString(),d,!0,P.RemoveUnrecognizedInputs)):u;if(!d.checkCanEdit(d,i))return S.warn(`[${P.RemoveUnrecognizedInputs}] User is not allowed to edit this ${d.type} entity with id: ${d.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:[],added:[],removed:[],affected:[],self:d};const a=[],l=[],c=[],e=[];return d.inputs.filter((v,T)=>{const I=d.inputs.findIndex(D=>D.implements.every($=>v.implements.includes($))&&D.name===v.name&&D!==v);if(I===-1)return!1;const E=d.inputs[I];return M(E==null?void 0:E.createdAt).isSame(M(v.createdAt))?T>I:!!M(E==null?void 0:E.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,d.id),{updated:g(a),added:g(l),removed:g(c),affected:g(e),self:d}}var V6=(d=>(d.FunctionDeclarationImplements="function-declaration-implements",d.FunctionDeclarationExtends="function-declaration-extends",d.FunctionDeclarationDataType="function-declaration-data-type",d.FunctionDeclarationDataTypeEntity="function-declaration-data-type-entity",d))(V6||{});const zt=class zt extends mr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"collapsed");_(this,"private");_(this,"index",null);_(this,"type",p.FunctionDeclaration);_(this,"implements",null);_(this,"extends",null);_(this,"dataType",null);_(this,"inputs",[]);_(this,"calls",[]);_(this,"parent");_(this,"detachedChildren",[]);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(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:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.FunctionDeclaration,name:"",dataType:null,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=ie(i.parent);l=a.get(T)}let c=null;if(i.implements){const T=ie(i.implements);c=a.get(T)}let e=null;if(i.extends){const T=ie(i.extends);e=a.get(T)}const y={id:i.id,version:L.UUID.uuid(),createdAt:M().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:p.FunctionDeclaration,dataType:null,index:l.type===p.DefinitionEntity?l.methods.length:null,codeName:i.codeName||null,description:i.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:c,extends:e,x:0,y:0,parent:l},v=ae(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){var E;let l=JSON.parse(JSON.stringify(i));const c=[],e=kr(l,{parent:{list:!1,types:[p.Project,p.InstalledProject,p.DefinitionEntity,p.Loop],optional:!0},implements:{list:!1,types:[p.ActionDescriptor],optional:!0}},a);l=e.modifiedData;const y=cR(l,a),v=l.parent?a.get(l.parent):null;if(v&&v.type===p.DefinitionEntity){const D=v,B=ln(D).filter(G=>!G.interactive),x=D.methods.find(G=>{var W;return((W=G.implements)==null?void 0:W.id)===l.implements});if(x&&c.push(new fe({id:`${l.id}--${pe.MethodOverwritesOtherSiblingWithSameImplementation}`,code:pe.MethodOverwritesOtherSiblingWithSameImplementation,severity:te.Error,message:`The '${p.FunctionDeclaration}' with id "${l.id}" is trying to implement the '${p.ActionDescriptor}' with id "${l.implements}", but the parent definition-entity already has a ${p.FunctionDeclaration} with id '${x.id}' that implements the same base method.
|
|
27
27
|
A ${p.FunctionDeclaration} that has a parent of type '${p.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${p.ActionDescriptor}' more than once.
|
|
28
28
|
${p.ActionDescriptor} entities inside a ${p.DefinitionEntity} are considered abstract methods that can be implemented by ${p.FunctionDeclaration} entities inside the same parent.
|
|
29
29
|
If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${p.ActionDescriptor} signature, otherwise the implementation will have a validation error.`})),!l.implements&&B.length){let G=B.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${D.id}' because it extends or implements multiple '${p.BuiltInBaseEntity}' entities that are non-interactive ("${yt(B.map(W=>X(W,W.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${D.id}' because it extends or implements a '${p.BuiltInBaseEntity}' entity that is non-interactive ("${X(B[0],B[0].project)}").`;G+=`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6614",
|
|
4
4
|
"author": "Sergio Herrero",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",
|