@elyx-code/project-logic-tree 0.0.6319 → 0.0.6321
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -2
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34791,7 +34791,12 @@ Please consider than any updates might affect the overlap with the signature of
|
|
|
34791
34791
|
return a !== -1 && this.returnStatements.splice(a, 1), this;
|
|
34792
34792
|
}
|
|
34793
34793
|
getUniqueReturnDeclarations() {
|
|
34794
|
-
const s = [],
|
|
34794
|
+
const s = [], a = [...this.returnStatements];
|
|
34795
|
+
this.parent.type === f.Loop && a.push(
|
|
34796
|
+
...this.parent.breakStatements,
|
|
34797
|
+
...this.parent.continueStatements
|
|
34798
|
+
);
|
|
34799
|
+
const l = a.flatMap((c) => c.outputs);
|
|
34795
34800
|
if (this.implements) {
|
|
34796
34801
|
const c = this.implements.outputs;
|
|
34797
34802
|
return l.forEach((t) => {
|
|
@@ -39231,7 +39236,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
39231
39236
|
this.implements ? s = l.filter(
|
|
39232
39237
|
(t) => {
|
|
39233
39238
|
var m;
|
|
39234
|
-
return this.implements.id === ((m = t.implements) == null ? void 0 : m.id);
|
|
39239
|
+
return this.implements.id === ((m = t.implements) == null ? void 0 : m.id) && t.id !== this.id;
|
|
39235
39240
|
}
|
|
39236
39241
|
) : s = l.filter(
|
|
39237
39242
|
(t) => ce(t, this.project) === ce(this, this.project) && t.id !== this.id
|
package/dist/index.umd.cjs
CHANGED
|
@@ -55,7 +55,7 @@ If you want to implement a new method, you can create a new 'function-declaratio
|
|
|
55
55
|
If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${f.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null}))}}else if(v&&v.type===f.Loop){const V=v.body;V&&((I=V.implements)==null?void 0:I.id)===l.implements&&p.push(new Y({id:`${l.id}--${le.LoopBodyFunctionOverwrite}`,code:le.LoopBodyFunctionOverwrite,severity:S.Error,message:`The '${f.FunctionDeclaration}' with id "${l.id}" is being added as the 'body' of the ${f.Loop} with id "${v.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`,issue:null}))}const b=l.parent&&a.get(l.parent)||a.getBuiltIn(l.parent),_=b?ka(b):null;return _&&p.push(new Y({id:`${s.id}--${k.BuiltInEntityParent}`,code:k.BuiltInEntityParent,severity:S.Error,message:`The entity with id '${s.id}' and type '${s.type}', belongs to a built-in system entity "${fe(_,a)}" with id '${_.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),p.push(...t.errors,...m,...ur(l)),{errors:p,modifiedData:l}}get isExtendedMethod(){if(this.parent.type!==f.DefinitionEntity)return!1;const s=this.parent.allBaseMethodsFromExtendedAndImplementedEntities.find(a=>{var l;return a.id===((l=this.extends)==null?void 0:l.id)});return!!s&&s.id!==this.id&&s.type!==f.ActionDescriptor}get returnStatements(){return at(this).filter(l=>l.type===f.ReturnStatement&&l.parent.id===this.id)}validateGeneratedUpdate(s){const a=[];return s.parent&&(this.parent.type===f.Project?a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
56
56
|
This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`,issue:null})):a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
57
57
|
This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.
|
|
58
|
-
Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:a,modifiedData:s}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];if(a==="function-declaration-implements"&&this.setImplements(null,l),a==="function-declaration-extends"){const{updated:b,added:_,removed:I,affected:V}=this.remove({ignoreUpstream:!1},l);p.push(...b),t.push(..._),m.push(...I),v.push(...V)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];if(a==="function-declaration-implements"&&(this.setImplements(s,l),p.push(s)),a==="function-declaration-extends"){const{updated:b,added:_,removed:I,affected:V}=this.restore({},l);p.push(...b),t.push(..._),m.push(...I),v.push(...V)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s,a;return(s=this.implements)==null||s.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var s,a;return(s=this.implements)==null||s.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.subscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new pt(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.inputs=[...this.inputs],s.calls=[...this.calls],s.implements=this.implements,s.extends=this.extends,s.detachedChildren=[...this.detachedChildren],s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new pt(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.inputs=m.inputs,this.calls=m.calls,this.implements=m.implements,this.detachedChildren=m.detachedChildren,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(s.implements){const l=W(s.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${kr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(s.extends){const l=W(s.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${kr(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${kr(this.type)} with id '${this.id}' has a 'parent' reference "${t}" which is missing in the project`)}else throw new Error(`${kr(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const t=W(this.initialData.implements),m=this.project.get(t);if(m)this.setImplements(m,null),s.push(m);else if(t)throw new Error(`${kr(this.type)} with id '${this.id}' has a 'implements' reference "${t}" which is missing in the project`)}if(this.initialData.extends){const t=W(this.initialData.extends),m=this.project.get(t);if(m)this.setExtends(m,null),s.push(m);else if(t)throw new Error(`${kr(this.type)} with id '${this.id}' has a 'extends' reference "${t}" which is missing in the project`)}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===f.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===f.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}replaceDetachedChild(s,a){const l=this.detachedChildren.indexOf(s);return l!==-1&&(this.detachedChildren[l]=a),this}subscribeDetachedChild(s){return this.detachedChildren.includes(s)||this.detachedChildren.push(s),this}unsubscribeDetachedChild(s){const a=this.detachedChildren.indexOf(s);return a!==-1&&this.detachedChildren.splice(a,1),this}addInputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(s)?(a==null||a.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(s),a==null||a.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-input-declaration"))){const l=this.inputs.findIndex(p=>p.id===s.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,G.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",this.id),this}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.implements=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.extends=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}addCall(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-call"))){return this.calls.includes(s)||(this.calls.push(s),a==null||a.add(s,G.Affected)),a==null||a.attemptAutoclose("add-call",this.id),this}removeCall(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-call"))){const l=this.calls.indexOf(s);return l!==-1&&(this.calls.splice(l,1),a==null||a.add(s,G.Affected)),a==null||a.attemptAutoclose("remove-call",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(a=>{const l=z(a,this.project);return l.setParent(this,null),l.initChildren(s),l}),this.calls=this.initialData.calls.map(a=>{const l=z(a,this.project);return l.addEntryCaller(this,null),[f.BreakStatement,f.ContinueStatement].includes(l.type)?(l.setParent(this.parent,null),l.initChildren(s)):l.type!==f.InternalCall&&(l.setParent(this,null),l.initChildren(s)),l}),this.initialData.implements&&(this.implements=z(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=z(this.initialData.extends,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.name=s.name!==void 0?s.name:p.name,this.description=s.description!==void 0?s.description:p.description,this.private=s.private!==void 0?s.private:this.private,this.index=s.index||(s.index!==0?p.index:0),this.collapsed=s.collapsed!==void 0?s.collapsed:p.collapsed,this.x=s.x||p.x,this.y=s.y||p.y,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await pt.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await pt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await pt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await pt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await pt.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await pt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.DefinitionEntity?(this.parent.removeMethod(this),s==null||s.add(this.parent,G.Affected),t.push(this.parent)):this.parent.type===f.Loop?(this.parent.detachBody(),s==null||s.add(this.parent,G.Affected),t.push(this.parent)):this.parent.type===f.Project&&(this.project.removeFunctionDeclaration(this),s==null||s.add(this.parent,G.Affected),t.push(this.parent)),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(b=>{const{updated:_,removed:I,added:V}=b.entity.onDetachedDependencyRemoved(this,b.field,a);l.push(..._),p.push(...I),t.push(...V)}),this.inputs.forEach(b=>{const{updated:_,removed:I}=b.remove({ignoreUpstream:!0},a);l.push(..._),p.push(...I)}),xi(this).forEach(b=>{const{updated:_,removed:I}=b.remove({ignoreUpstream:!0},a);l.push(..._),p.push(...I)}),!s){const b=this.removeFromParent(a);t.push(...b.added),l.push(...b.updated),p.push(...b.removed),m.push(...b.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return s!=null&&s.hasAdded(this.id)?(s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:_,added:I}=v.entity.onDetachedDependencyRestored(this,v.field,s);l.push(...b),p.push(..._),a.push(...I)}),this.inputs.forEach(v=>{const{updated:b}=v.restore({},s);l.push(...b)}),xi(this).forEach(v=>{const{updated:b}=v.restore({},s);l.push(...b)}),this.parent.type===f.DefinitionEntity&&(this.parent.addMethod(this),s==null||s.add(this.parent,G.Affected),t.push(this.parent)),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this})}toFlat(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(s)),...this.calls.flatMap(l=>l.toFlat(s)),...this.returnStatements.flatMap(l=>l.toFlat(s)),...this.implements?this.implements.toFlat(s):[]])}toFlatIds(s=new Set){if(s.has(this.id))return[];s.add(this.id);const a=xi(this);return[this.id,...this.inputs.flatMap(p=>p.toFlatIds(s)),...this.calls.flatMap(p=>p.toFlatIds(s)),...this.returnStatements.flatMap(p=>p.toFlatIds(s)),...this.implements?this.implements.toFlatIds(s):[],...a.flatMap(p=>p.toFlatIds(s))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(s=new Set){var a,l;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(p=>p.toJSON(s)),inputs:this.inputs.map(p=>p.toJSON(s)),implements:((a=this.implements)==null?void 0:a.toJSON(s))||null,extends:((l=this.extends)==null?void 0:l.toJSON(s))||null,parent:this.parent.toReference()})}toJSONClone(s=Ce){var l,p,t,m,v;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(b=>b.toJSONClone({...s,newId:null})),inputs:this.inputs.map(b=>b.toJSONClone({...s,newId:null})),implements:(()=>{var b;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(b=this.implements)==null?void 0:b.toJSONClone({...s,newId:null})})(),extends:(()=>{var b;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(b=this.extends)==null?void 0:b.toJSONClone({...s,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:s.seenEntityMaps})})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p,t;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(m=>m.toReference(s)),calls:this.calls.map(m=>m.toReference(s)),implements:((p=this.implements)==null?void 0:p.toReference(s))||null,extends:((t=this.extends)==null?void 0:t.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(s)),...this.calls.flatMap(l=>l.toFlatJSON(s)),...this.returnStatements.flatMap(l=>l.toFlatJSON(s)),...this.implements?this.implements.toFlatJSON(s):[]])}toGenerationTarget(){var a,l;const s=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((a=this.implements)==null?void 0:a.id)||void 0,extends:((l=this.extends)==null?void 0:l.id)||void 0,parent:s}}toFlatGenerationTarget(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(s)),...this.calls.flatMap(l=>l.toFlatGenerationTarget(s)),...this.returnStatements.flatMap(l=>l.toFlatGenerationTarget(s))])}clearErrors(){return this.errors=[],this.inputs.forEach(s=>s.clearErrors()),this.calls.forEach(s=>s.clearErrors()),this.returnStatements.forEach(s=>s.clearErrors()),this}validate(){const s=iM(this);return this.errors=[...s],{success:!0,error:null,data:this.toJSON()}}getErrors(){const s=xi(this);return[...this.errors,...this.inputs.flatMap(l=>l.getErrors()),...s.flatMap(l=>l.getErrors())]}getShallowErrors(){return this.errors}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0,t=!1){var B;let m=yr(a,this);const v=this.toJSON(),b=l||P.UUID.uuid();v.inputs=[],v.calls=[],v.id=b,v.version=P.UUID.uuid(),v.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),v.author=(s==null?void 0:s.author)||"1",v.previousVersion=null,v.deleted=!1;const _=er(v,m);a?_.setParent(a,null):_.setParent(this.parent,null),p&&_.subscribe(),_.initChildren(s),s==null||s.add(_,G.Added);const I=(B=this.inputs)==null?void 0:B.map(K=>K.clone(s,_,P.UUID.uuid(),p));return _.inputs=I,t?(xi(this).map(K=>K.clone(s,_,P.UUID.uuid(),p)),s==null||s.attemptAutoclose("clone-entity",this.id),_):(s==null||s.attemptAutoclose("clone-entity",this.id),_)}getVariableInstances(){return kt(this).filter(l=>l.type===f.VariableInstance)}getArgument(s){return this.inputs.find(a=>a.id===s)||null}createCall(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"create-call")),a=this.project,l={}){const p={id:l.id||P.UUID.uuid(),version:l.version||P.UUID.uuid(),createdAt:l.createdAt||(s==null?void 0:s.timestamp)||N().toISOString(),author:l.author||P.sessionAuthor||"1",previousVersion:l.previousVersion||null,deleted:l.deleted||!1,type:f.FunctionCall,parent:a.toReference(),successCalls:l.successCalls||[],errorCalls:l.errorCalls||[],inputs:l.inputs||[],outputs:l.outputs||[],error:l.error||null,process:l.process||null,calledBySuccess:l.calledBySuccess||[],calledByError:l.calledByError||[],calledByEntry:l.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},t=z(p,this.project);return t.hydrateAncestors(),s==null||s.add(t,G.Added),t.addSelfToProject(s),t.setParent(a,s),t.initChildren(s),t.afterAllChildrenInitialized(s),s==null||s.add(t,G.Added),s==null||s.attemptAutoclose("create-call",this.id),t}createInternalCall(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"create-internal")),a,l={}){const p={id:l.id||P.UUID.uuid(),version:l.version||P.UUID.uuid(),createdAt:l.createdAt||(s==null?void 0:s.timestamp)||N().toISOString(),author:l.author||P.sessionAuthor||"1",previousVersion:l.previousVersion||null,deleted:l.deleted||!1,type:f.InternalCall,parent:a.toReference(),successCalls:l.successCalls||[],errorCalls:l.errorCalls||[],inputs:l.inputs||[],outputs:l.outputs||[],error:l.error||null,process:l.process||null,calledBySuccess:l.calledBySuccess||[],calledByError:l.calledByError||[],calledByEntry:l.calledByEntry||[],declaration:this.toShallowJSON(),index:a.internalCalls.length},t=z(p,this.project);return t.hydrateAncestors(),s==null||s.add(t,G.Added),t.addSelfToProject(s),t.setParent(a,s),t.initChildren(s),t.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("create-internal",this.id),t}addReturnStatement(s){return this.returnStatements.includes(s)||this.returnStatements.push(s),this}removeReturnStatement(s){const a=this.returnStatements.indexOf(s);return a!==-1&&this.returnStatements.splice(a,1),this}getUniqueReturnDeclarations(){const s=[],l=[...this.returnStatements].flatMap(p=>p.outputs);if(this.implements){const p=this.implements.outputs;return l.forEach(t=>{const m=p.find(b=>b===t.implements),v=s.find(b=>b.implements===t.implements);m&&!v&&s.push(t)}),w(s)}else return l.forEach(p=>{s.find(m=>m===p||fe(m,this.project)===fe(p,this.project)&&vs(m.dataType,p.dataType))||s.push(p)}),w(s)}};g(pt,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g(pt,"type",f.FunctionDeclaration),g(pt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop]),g(pt,"PARENT_TYPES",[...pt.USER_MANAGED_PARENT_TYPES,f.BuiltInBaseEntity,f.PrimitiveEntity]),g(pt,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),g(pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(pt,"BASE_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,...pt.INMUTABLE_BASE_PROPERTIES]),g(pt,"MUTABLE_META_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),g(pt,"INMUTABLE_META_PROPERTIES",[...pt.INMUTABLE_BASE_PROPERTIES]),g(pt,"META_PROPERTIES",[...pt.MUTABLE_META_PROPERTIES,...pt.INMUTABLE_META_PROPERTIES]),g(pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(pt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(pt,"UPSTREAM_PROPERTIES",[...pt.MUTABLE_UPSTREAM_PROPERTIES,...pt.INMUTABLE_UPSTREAM_PROPERTIES]),g(pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),g(pt,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),g(pt,"DOWNSTREAM_PROPERTIES",[...pt.MUTABLE_DOWNSTREAM_PROPERTIES,...pt.INMUATABLE_DOWNSTREAM_PROPERTIES]),g(pt,"PROPERTIES",[...pt.META_PROPERTIES,...pt.UPSTREAM_PROPERTIES,...pt.DOWNSTREAM_PROPERTIES]);let _a=pt;function nM(u){const d=Yle(),s=u.toJSON();d.safeParse(s).success;const l=[];if(u.entity&&u.andChildrenGroup||u.entity&&u.orChildrenGroup||u.andChildrenGroup&&u.orChildrenGroup){const p=tt({id:u.id+"--"+me.InvalidPropertiesCombination,message:`Data type with id "${u.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:S.Error,code:me.InvalidPropertiesCombination,entity:u});l.push(p.error)}return qt(u.errors,l)}const ape=Object.freeze(Object.defineProperty({__proto__:null,validate:nM},Symbol.toStringTag,{value:"Module"}));function ope(u,d){const s=[],a=[f.DefinitionEntity,f.ActionDescriptor,f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.ValueDescriptor,f.DataType],l=`'${Ke(a,"', '","' or '")}'`;if(u.parent)if(u.id===u.parent)s.push(new Y({id:`${u.id}--${u.parent}--${k.SelfReference}`,code:k.SelfReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const p=d.get(u.parent);p?a.includes(p.type)||s.push(new Y({id:`${u.id}--${u.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has a parent reference that isn't pointing to an entity of type ${l}.`,issue:null})):s.push(new Y({id:`${u.id}--${u.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", is referencing an entity with id "${u.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else s.push(new Y({id:`${u.id}--${le.InvalidObjectStructure}`,code:le.InvalidObjectStructure,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${l}.`,issue:null}));if(u.entity){if(u.id===u.entity)return s.push(new Y({id:`${u.id}--${u.entity}--${k.SelfReference}`,code:k.SelfReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),s;const p=d.get(u.entity);p?[f.DefinitionEntity,f.PrimitiveEntity,f.ActionDescriptor,f.BuiltInBaseEntity].includes(p.type)||s.push(new Y({id:`${u.id}--${u.entity}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):s.push(new Y({id:`${u.id}--${u.entity}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", is referencing an entity with id "${u.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return s}var xT=(u=>(u.Entity="entity",u))(xT||{});const ft=class ft extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"isList",null);g(this,"asType",null);g(this,"type",f.DataType);g(this,"options",null);g(this,"parentRelationType",null);g(this,"like");g(this,"implementationChooseOne",!1);g(this,"inferred",!1);g(this,"staticEntities",null);g(this,"interactiveEntities",null);g(this,"actionEntities",null);g(this,"entity",null);g(this,"andChildrenGroup",null);g(this,"orChildrenGroup",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);this.initialData=s,this.project=a,this.id=s.id,this.isList=s.isList,this.asType=s.asType,this.options=s.options,this.parentRelationType=s.parentRelationType,this.inferred=s.inferred||!1,this.like=s.like||!1,this.implementationChooseOne=s.implementationChooseOne||!1,this.staticEntities=s.staticEntities,this.interactiveEntities=s.interactiveEntities,this.actionEntities=s.actionEntities}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l);let t=null;s.entity&&(t=a.get(s.entity));const m={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:s.parentRelationType||null,options:s.options||null,isList:s.isList,like:s.like||!1,inferred:!1,implementationChooseOne:s.implementationChooseOne||!1,staticEntities:s.staticEntities??null,interactiveEntities:s.interactiveEntities??null,actionEntities:s.actionEntities??null,entity:t,asType:s.asType,parent:p},v=z(m,a);return v.setParent(p,null),v.initChildren(null),v}static validateGenerationTarget(s,a){var b;let l=JSON.parse(JSON.stringify(s));const p=[],t=ope(l,a);if(p.push(...t,...ur(l)),l.entity){const _=a.get(l.entity);if(_.type===f.DefinitionEntity){const V=hi(_).filter(B=>!B.interactive);if(V.length){const B=V.length>1?`entities with ids '${Ke(V.map(K=>K.id),"', '","' and '")}'`:`entity with id '${V[0].id}'`;p.push(new Y({id:`${s.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:S.Error,message:`The entity with id '${s.id}' and type '${s.type}', cannot reference 'definition-entity' with id '${l.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${B}.
|
|
58
|
+
Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:a,modifiedData:s}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];if(a==="function-declaration-implements"&&this.setImplements(null,l),a==="function-declaration-extends"){const{updated:b,added:_,removed:I,affected:V}=this.remove({ignoreUpstream:!1},l);p.push(...b),t.push(..._),m.push(...I),v.push(...V)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];if(a==="function-declaration-implements"&&(this.setImplements(s,l),p.push(s)),a==="function-declaration-extends"){const{updated:b,added:_,removed:I,affected:V}=this.restore({},l);p.push(...b),t.push(..._),m.push(...I),v.push(...V)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s,a;return(s=this.implements)==null||s.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var s,a;return(s=this.implements)==null||s.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.subscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new pt(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.inputs=[...this.inputs],s.calls=[...this.calls],s.implements=this.implements,s.extends=this.extends,s.detachedChildren=[...this.detachedChildren],s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new pt(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.inputs=m.inputs,this.calls=m.calls,this.implements=m.implements,this.detachedChildren=m.detachedChildren,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(s.implements){const l=W(s.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${kr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(s.extends){const l=W(s.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${kr(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${kr(this.type)} with id '${this.id}' has a 'parent' reference "${t}" which is missing in the project`)}else throw new Error(`${kr(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const t=W(this.initialData.implements),m=this.project.get(t);if(m)this.setImplements(m,null),s.push(m);else if(t)throw new Error(`${kr(this.type)} with id '${this.id}' has a 'implements' reference "${t}" which is missing in the project`)}if(this.initialData.extends){const t=W(this.initialData.extends),m=this.project.get(t);if(m)this.setExtends(m,null),s.push(m);else if(t)throw new Error(`${kr(this.type)} with id '${this.id}' has a 'extends' reference "${t}" which is missing in the project`)}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],t=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===f.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===f.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}replaceDetachedChild(s,a){const l=this.detachedChildren.indexOf(s);return l!==-1&&(this.detachedChildren[l]=a),this}subscribeDetachedChild(s){return this.detachedChildren.includes(s)||this.detachedChildren.push(s),this}unsubscribeDetachedChild(s){const a=this.detachedChildren.indexOf(s);return a!==-1&&this.detachedChildren.splice(a,1),this}addInputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(s)?(a==null||a.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(s),a==null||a.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-input-declaration"))){const l=this.inputs.findIndex(p=>p.id===s.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,G.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",this.id),this}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.implements=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.extends=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}addCall(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-call"))){return this.calls.includes(s)||(this.calls.push(s),a==null||a.add(s,G.Affected)),a==null||a.attemptAutoclose("add-call",this.id),this}removeCall(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-call"))){const l=this.calls.indexOf(s);return l!==-1&&(this.calls.splice(l,1),a==null||a.add(s,G.Affected)),a==null||a.attemptAutoclose("remove-call",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(a=>{const l=z(a,this.project);return l.setParent(this,null),l.initChildren(s),l}),this.calls=this.initialData.calls.map(a=>{const l=z(a,this.project);return l.addEntryCaller(this,null),[f.BreakStatement,f.ContinueStatement].includes(l.type)?(l.setParent(this.parent,null),l.initChildren(s)):l.type!==f.InternalCall&&(l.setParent(this,null),l.initChildren(s)),l}),this.initialData.implements&&(this.implements=z(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=z(this.initialData.extends,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.name=s.name!==void 0?s.name:p.name,this.description=s.description!==void 0?s.description:p.description,this.private=s.private!==void 0?s.private:this.private,this.index=s.index||(s.index!==0?p.index:0),this.collapsed=s.collapsed!==void 0?s.collapsed:p.collapsed,this.x=s.x||p.x,this.y=s.y||p.y,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await pt.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await pt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await pt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await pt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await pt.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await pt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.type===f.DefinitionEntity?(this.parent.removeMethod(this),s==null||s.add(this.parent,G.Affected),t.push(this.parent)):this.parent.type===f.Loop?(this.parent.detachBody(),s==null||s.add(this.parent,G.Affected),t.push(this.parent)):this.parent.type===f.Project&&(this.project.removeFunctionDeclaration(this),s==null||s.add(this.parent,G.Affected),t.push(this.parent)),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(b=>{const{updated:_,removed:I,added:V}=b.entity.onDetachedDependencyRemoved(this,b.field,a);l.push(..._),p.push(...I),t.push(...V)}),this.inputs.forEach(b=>{const{updated:_,removed:I}=b.remove({ignoreUpstream:!0},a);l.push(..._),p.push(...I)}),xi(this).forEach(b=>{const{updated:_,removed:I}=b.remove({ignoreUpstream:!0},a);l.push(..._),p.push(...I)}),!s){const b=this.removeFromParent(a);t.push(...b.added),l.push(...b.updated),p.push(...b.removed),m.push(...b.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];return s!=null&&s.hasAdded(this.id)?(s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:_,added:I}=v.entity.onDetachedDependencyRestored(this,v.field,s);l.push(...b),p.push(..._),a.push(...I)}),this.inputs.forEach(v=>{const{updated:b}=v.restore({},s);l.push(...b)}),xi(this).forEach(v=>{const{updated:b}=v.restore({},s);l.push(...b)}),this.parent.type===f.DefinitionEntity&&(this.parent.addMethod(this),s==null||s.add(this.parent,G.Affected),t.push(this.parent)),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this})}toFlat(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(s)),...this.calls.flatMap(l=>l.toFlat(s)),...this.returnStatements.flatMap(l=>l.toFlat(s)),...this.implements?this.implements.toFlat(s):[]])}toFlatIds(s=new Set){if(s.has(this.id))return[];s.add(this.id);const a=xi(this);return[this.id,...this.inputs.flatMap(p=>p.toFlatIds(s)),...this.calls.flatMap(p=>p.toFlatIds(s)),...this.returnStatements.flatMap(p=>p.toFlatIds(s)),...this.implements?this.implements.toFlatIds(s):[],...a.flatMap(p=>p.toFlatIds(s))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(s=new Set){var a,l;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(p=>p.toJSON(s)),inputs:this.inputs.map(p=>p.toJSON(s)),implements:((a=this.implements)==null?void 0:a.toJSON(s))||null,extends:((l=this.extends)==null?void 0:l.toJSON(s))||null,parent:this.parent.toReference()})}toJSONClone(s=Ce){var l,p,t,m,v;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(b=>b.toJSONClone({...s,newId:null})),inputs:this.inputs.map(b=>b.toJSONClone({...s,newId:null})),implements:(()=>{var b;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(b=this.implements)==null?void 0:b.toJSONClone({...s,newId:null})})(),extends:(()=>{var b;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(b=this.extends)==null?void 0:b.toJSONClone({...s,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:s.seenEntityMaps})})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p,t;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(m=>m.toReference(s)),calls:this.calls.map(m=>m.toReference(s)),implements:((p=this.implements)==null?void 0:p.toReference(s))||null,extends:((t=this.extends)==null?void 0:t.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(s)),...this.calls.flatMap(l=>l.toFlatJSON(s)),...this.returnStatements.flatMap(l=>l.toFlatJSON(s)),...this.implements?this.implements.toFlatJSON(s):[]])}toGenerationTarget(){var a,l;const s=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((a=this.implements)==null?void 0:a.id)||void 0,extends:((l=this.extends)==null?void 0:l.id)||void 0,parent:s}}toFlatGenerationTarget(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(s)),...this.calls.flatMap(l=>l.toFlatGenerationTarget(s)),...this.returnStatements.flatMap(l=>l.toFlatGenerationTarget(s))])}clearErrors(){return this.errors=[],this.inputs.forEach(s=>s.clearErrors()),this.calls.forEach(s=>s.clearErrors()),this.returnStatements.forEach(s=>s.clearErrors()),this}validate(){const s=iM(this);return this.errors=[...s],{success:!0,error:null,data:this.toJSON()}}getErrors(){const s=xi(this);return[...this.errors,...this.inputs.flatMap(l=>l.getErrors()),...s.flatMap(l=>l.getErrors())]}getShallowErrors(){return this.errors}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0,t=!1){var B;let m=yr(a,this);const v=this.toJSON(),b=l||P.UUID.uuid();v.inputs=[],v.calls=[],v.id=b,v.version=P.UUID.uuid(),v.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),v.author=(s==null?void 0:s.author)||"1",v.previousVersion=null,v.deleted=!1;const _=er(v,m);a?_.setParent(a,null):_.setParent(this.parent,null),p&&_.subscribe(),_.initChildren(s),s==null||s.add(_,G.Added);const I=(B=this.inputs)==null?void 0:B.map(K=>K.clone(s,_,P.UUID.uuid(),p));return _.inputs=I,t?(xi(this).map(K=>K.clone(s,_,P.UUID.uuid(),p)),s==null||s.attemptAutoclose("clone-entity",this.id),_):(s==null||s.attemptAutoclose("clone-entity",this.id),_)}getVariableInstances(){return kt(this).filter(l=>l.type===f.VariableInstance)}getArgument(s){return this.inputs.find(a=>a.id===s)||null}createCall(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"create-call")),a=this.project,l={}){const p={id:l.id||P.UUID.uuid(),version:l.version||P.UUID.uuid(),createdAt:l.createdAt||(s==null?void 0:s.timestamp)||N().toISOString(),author:l.author||P.sessionAuthor||"1",previousVersion:l.previousVersion||null,deleted:l.deleted||!1,type:f.FunctionCall,parent:a.toReference(),successCalls:l.successCalls||[],errorCalls:l.errorCalls||[],inputs:l.inputs||[],outputs:l.outputs||[],error:l.error||null,process:l.process||null,calledBySuccess:l.calledBySuccess||[],calledByError:l.calledByError||[],calledByEntry:l.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},t=z(p,this.project);return t.hydrateAncestors(),s==null||s.add(t,G.Added),t.addSelfToProject(s),t.setParent(a,s),t.initChildren(s),t.afterAllChildrenInitialized(s),s==null||s.add(t,G.Added),s==null||s.attemptAutoclose("create-call",this.id),t}createInternalCall(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"create-internal")),a,l={}){const p={id:l.id||P.UUID.uuid(),version:l.version||P.UUID.uuid(),createdAt:l.createdAt||(s==null?void 0:s.timestamp)||N().toISOString(),author:l.author||P.sessionAuthor||"1",previousVersion:l.previousVersion||null,deleted:l.deleted||!1,type:f.InternalCall,parent:a.toReference(),successCalls:l.successCalls||[],errorCalls:l.errorCalls||[],inputs:l.inputs||[],outputs:l.outputs||[],error:l.error||null,process:l.process||null,calledBySuccess:l.calledBySuccess||[],calledByError:l.calledByError||[],calledByEntry:l.calledByEntry||[],declaration:this.toShallowJSON(),index:a.internalCalls.length},t=z(p,this.project);return t.hydrateAncestors(),s==null||s.add(t,G.Added),t.addSelfToProject(s),t.setParent(a,s),t.initChildren(s),t.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("create-internal",this.id),t}addReturnStatement(s){return this.returnStatements.includes(s)||this.returnStatements.push(s),this}removeReturnStatement(s){const a=this.returnStatements.indexOf(s);return a!==-1&&this.returnStatements.splice(a,1),this}getUniqueReturnDeclarations(){const s=[],a=[...this.returnStatements];this.parent.type===f.Loop&&a.push(...this.parent.breakStatements,...this.parent.continueStatements);const l=a.flatMap(p=>p.outputs);if(this.implements){const p=this.implements.outputs;return l.forEach(t=>{const m=p.find(b=>b===t.implements),v=s.find(b=>b.implements===t.implements);m&&!v&&s.push(t)}),w(s)}else return l.forEach(p=>{s.find(m=>m===p||fe(m,this.project)===fe(p,this.project)&&vs(m.dataType,p.dataType))||s.push(p)}),w(s)}};g(pt,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g(pt,"type",f.FunctionDeclaration),g(pt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop]),g(pt,"PARENT_TYPES",[...pt.USER_MANAGED_PARENT_TYPES,f.BuiltInBaseEntity,f.PrimitiveEntity]),g(pt,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),g(pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(pt,"BASE_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,...pt.INMUTABLE_BASE_PROPERTIES]),g(pt,"MUTABLE_META_PROPERTIES",[...pt.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),g(pt,"INMUTABLE_META_PROPERTIES",[...pt.INMUTABLE_BASE_PROPERTIES]),g(pt,"META_PROPERTIES",[...pt.MUTABLE_META_PROPERTIES,...pt.INMUTABLE_META_PROPERTIES]),g(pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(pt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(pt,"UPSTREAM_PROPERTIES",[...pt.MUTABLE_UPSTREAM_PROPERTIES,...pt.INMUTABLE_UPSTREAM_PROPERTIES]),g(pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),g(pt,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),g(pt,"DOWNSTREAM_PROPERTIES",[...pt.MUTABLE_DOWNSTREAM_PROPERTIES,...pt.INMUATABLE_DOWNSTREAM_PROPERTIES]),g(pt,"PROPERTIES",[...pt.META_PROPERTIES,...pt.UPSTREAM_PROPERTIES,...pt.DOWNSTREAM_PROPERTIES]);let _a=pt;function nM(u){const d=Yle(),s=u.toJSON();d.safeParse(s).success;const l=[];if(u.entity&&u.andChildrenGroup||u.entity&&u.orChildrenGroup||u.andChildrenGroup&&u.orChildrenGroup){const p=tt({id:u.id+"--"+me.InvalidPropertiesCombination,message:`Data type with id "${u.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:S.Error,code:me.InvalidPropertiesCombination,entity:u});l.push(p.error)}return qt(u.errors,l)}const ape=Object.freeze(Object.defineProperty({__proto__:null,validate:nM},Symbol.toStringTag,{value:"Module"}));function ope(u,d){const s=[],a=[f.DefinitionEntity,f.ActionDescriptor,f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.ValueDescriptor,f.DataType],l=`'${Ke(a,"', '","' or '")}'`;if(u.parent)if(u.id===u.parent)s.push(new Y({id:`${u.id}--${u.parent}--${k.SelfReference}`,code:k.SelfReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const p=d.get(u.parent);p?a.includes(p.type)||s.push(new Y({id:`${u.id}--${u.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has a parent reference that isn't pointing to an entity of type ${l}.`,issue:null})):s.push(new Y({id:`${u.id}--${u.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", is referencing an entity with id "${u.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else s.push(new Y({id:`${u.id}--${le.InvalidObjectStructure}`,code:le.InvalidObjectStructure,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${l}.`,issue:null}));if(u.entity){if(u.id===u.entity)return s.push(new Y({id:`${u.id}--${u.entity}--${k.SelfReference}`,code:k.SelfReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),s;const p=d.get(u.entity);p?[f.DefinitionEntity,f.PrimitiveEntity,f.ActionDescriptor,f.BuiltInBaseEntity].includes(p.type)||s.push(new Y({id:`${u.id}--${u.entity}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):s.push(new Y({id:`${u.id}--${u.entity}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:S.Error,message:`Entity of type "${u.type}" with id "${u.id}", is referencing an entity with id "${u.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return s}var xT=(u=>(u.Entity="entity",u))(xT||{});const ft=class ft extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"isList",null);g(this,"asType",null);g(this,"type",f.DataType);g(this,"options",null);g(this,"parentRelationType",null);g(this,"like");g(this,"implementationChooseOne",!1);g(this,"inferred",!1);g(this,"staticEntities",null);g(this,"interactiveEntities",null);g(this,"actionEntities",null);g(this,"entity",null);g(this,"andChildrenGroup",null);g(this,"orChildrenGroup",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);this.initialData=s,this.project=a,this.id=s.id,this.isList=s.isList,this.asType=s.asType,this.options=s.options,this.parentRelationType=s.parentRelationType,this.inferred=s.inferred||!1,this.like=s.like||!1,this.implementationChooseOne=s.implementationChooseOne||!1,this.staticEntities=s.staticEntities,this.interactiveEntities=s.interactiveEntities,this.actionEntities=s.actionEntities}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l);let t=null;s.entity&&(t=a.get(s.entity));const m={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:s.parentRelationType||null,options:s.options||null,isList:s.isList,like:s.like||!1,inferred:!1,implementationChooseOne:s.implementationChooseOne||!1,staticEntities:s.staticEntities??null,interactiveEntities:s.interactiveEntities??null,actionEntities:s.actionEntities??null,entity:t,asType:s.asType,parent:p},v=z(m,a);return v.setParent(p,null),v.initChildren(null),v}static validateGenerationTarget(s,a){var b;let l=JSON.parse(JSON.stringify(s));const p=[],t=ope(l,a);if(p.push(...t,...ur(l)),l.entity){const _=a.get(l.entity);if(_.type===f.DefinitionEntity){const V=hi(_).filter(B=>!B.interactive);if(V.length){const B=V.length>1?`entities with ids '${Ke(V.map(K=>K.id),"', '","' and '")}'`:`entity with id '${V[0].id}'`;p.push(new Y({id:`${s.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:S.Error,message:`The entity with id '${s.id}' and type '${s.type}', cannot reference 'definition-entity' with id '${l.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${B}.
|
|
59
59
|
${xa}`,issue:null}))}}}const m=l.parent&&a.get(l.parent)||a.getBuiltIn(l.parent),v=m?ka(m):null;if(v)p.push(new Y({id:`${s.id}--${k.BuiltInEntityParent}`,code:k.BuiltInEntityParent,severity:S.Error,message:`The entity with id '${s.id}' and type '${s.type}', belongs to a built-in system entity "${fe(v,a)}" with id '${v.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(m){const _=m.type,I=[f.Property,f.VariableDeclaration,f.ArgumentDeclaration,f.ReturnDeclaration,f.ValueDescriptor];if(I.includes(_)&&(l.parentRelationType&&p.push(new Y({id:`${s.id}--${k.InvalidParentRelationType}`,code:k.InvalidParentRelationType,severity:S.Error,message:`The entity with id '${s.id}' and type '${s.type}', cannot have a 'parentRelationType' property set of type '${_}'.
|
|
60
60
|
The entitities of type '${Ke(I,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),m.dataType)){const V=(b=m.dataType)==null?void 0:b.id;p.push(new Y({id:`${s.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:S.Error,message:`The entity with id '${s.id}' and type '${s.type}', cannot be added as a child to the entity with id '${l.parent}' and type '${_}', because it already has a 'data-type' child with id '${V}'.
|
|
61
61
|
The entitities of type '${Ke(I,"', '","' 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:
|
|
@@ -76,7 +76,7 @@ ${ue}`,issue:null})):p.push(new Y({id:`${l.id}--${le.NoOverlapWithImplementedSig
|
|
|
76
76
|
Adding a new return would make the implementation invalid. There are no returns in the descriptor with the same name.
|
|
77
77
|
${re}
|
|
78
78
|
${ue}`,issue:null}))}}}}return p.push(...t.errors,...m,...ur(l)),{errors:p,modifiedData:l}}get codeNativeValueValidation(){var s;return this._codeNativeValueValidation||((s=this.implements)==null?void 0:s.codeNativeValueValidation)||null}validateGeneratedUpdate(s){const a=[];let l=JSON.parse(JSON.stringify(s));const p=Qc(l,this);return l=p.modifiedData,a.push(...p.errors),l.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
79
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:a,modifiedData:l}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(null,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(s,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.unsubscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.subscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yt(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.defaultValue=this.defaultValue,s.dataType=this.dataType,s.readsValue=this.readsValue,s.implements=this.implements,s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new yt(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.defaultValue=m.defaultValue,this.dataType=m.dataType,this.readsValue=m.readsValue,this.implements=m.implements,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(s.readsValue){const l=W(s.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(s.implements){const l=W(s.implements),p=this.project.get(l);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const t=W(this.initialData.readsValue),m=this.project.get(t);m&&(this.setValueWriter(m,null),s.push(m))}if(this.initialData.implements){const t=W(this.initialData.implements),m=this.project.get(t);m&&(this.setImplements(m,null),s.push(m))}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){var m;const a=[this],l=[],p=[],t=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,s),t.push(this.parent),(m=this.readsValue)==null||m.addValueReader(this,s),this.readsValue&&a.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}propagateChanges(){const s=[this],a=[],l=[],p=[];if(this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent,{updated:m,added:v,removed:b}=t.syncChildren();s.push(...m),a.push(...v),l.push(...b)}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.implements=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=z(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(s)),this.initialData.dataType){const a=z(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(s),this.dataType=a}if(this.initialData.implements){const a=z(this.initialData.implements,this.project);this.setImplements(a,null)}return dp.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this}setValueWriter(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==s&&(this.readsValue=s,a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,s==null||s.add(this,G.Updated)),s==null||s.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.index=s.index||(s.index!==0?p.index:0),this.name=s.name!==void 0?s.name:p.name,this.description=s.description!==void 0?s.description:p.description,this.required=s.required!==void 0?s.required:this.required,this.isError=s.isError!==void 0?s.isError:this.isError,this.constant=s.constant!==void 0?s.constant:p.constant,this.required=s.required!==void 0?s.required:p.required,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await yt.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await yt.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.isError?(this.parent.throws=null,s==null||s.add(this.parent,G.Updated),t.push(this.parent)):(this.parent.removeOutputDeclaration(this,s),t.push(this.parent)),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:_,added:I}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...b),p.push(..._),t.push(...I)}),this.defaultValue){const{updated:v,removed:b}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...b)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v.updated),p.push(...v.removed)}if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const v=this.getCounterparts();v.length&&v.forEach(b=>{if((!(a!=null&&a.hasRemoved(b.id))||!a)&&!b.deleted){const{updated:_,removed:I,added:V,affected:B}=b.remove({ignoreUpstream:s},a);l.push(..._),p.push(...I),t.push(...V),m.push(...B)}})}if(!s&&this.parent){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),m.push(...v.affected)}if(!s&&this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===f.Loop&&(a==null?void 0:a.self)===this&&this.parent.parent.afterAllChildrenInitialized(a),this.isError&&this.parent.type===f.ReturnStatement){const{updated:v,added:b,removed:_,affected:I}=this.parent.syncReturnDeclarations(a);l.push(...v),t.push(...b),p.push(..._),m.push(...I)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(s!=null&&s.hasAdded(this.id))return s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:b,added:_}=m.entity.onDetachedDependencyRestored(this,m.field,s);l.push(...v),p.push(...b),a.push(..._)}),this.defaultValue){const{updated:m}=this.defaultValue.restore({},s);l.push(...m)}if(this.dataType){const m=this.dataType.restore({},s);l.push(...m.updated)}return this.parent&&this.parent.addOutputDeclaration(this,s),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this}}toFlat(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(s))||[],...((p=this.readsValue)==null?void 0:p.toFlat(s))||[],...((t=this.dataType)==null?void 0:t.toFlat(s))||[]])}toFlatIds(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatIds(s))||[],...((t=this.dataType)==null?void 0:t.toFlatIds(s))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(s=new Set){var a,l,p,t;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(s))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(s))||null,implements:((p=this.implements)==null?void 0:p.toJSON(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toJSON(s))||null,parent:this.parent.toReference()})}toJSONClone(s=Ce){var l,p,t,m,v,b,_,I,V;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((b=this.defaultValue)==null?void 0:b.toJSONClone({...s,newId:null}))||null,dataType:((_=this.dataType)==null?void 0:_.toJSONClone({...s,newId:null}))||null,implements:((I=this.implements)==null?void 0:I.toJSONClone({...s,newId:null}))||null,readsValue:((V=this.readsValue)==null?void 0:V.toReference({seenEntityMaps:s.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:s.seenEntityMaps})})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p,t,m,v;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toReference(s))||null,implements:((m=this.implements)==null?void 0:m.toReference(s))||null,dataType:((v=this.dataType)==null?void 0:v.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatJSON(s))||[],...((t=this.dataType)==null?void 0:t.toFlatJSON(s))||[]])}toGenerationTarget(){var s;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(s=this.readsValue)==null?void 0:s.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatGenerationTarget(s))||[],...((t=this.dataType)==null?void 0:t.toFlatGenerationTarget(s))||[]])}clearErrors(){var s,a;return this.errors=[],(s=this.defaultValue)==null||s.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){const s=lM(this);return this.errors=s,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=s,a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,B;let t=yr(a,this);const m=this.toJSON(),v=l||P.UUID.uuid();m.dataType=null,m.id=v,m.version=P.UUID.uuid(),m.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),m.author=(s==null?void 0:s.author)||"1",m.previousVersion=null,m.deleted=!1;const b=er(m,t);a?b.setParent(a,null):b.setParent(this.parent,null),p&&b.subscribe(),b.initChildren(s),s==null||s.add(b,G.Added);const _=(V=this.dataType)==null?void 0:V.clone(s,b,P.UUID.uuid(),p);b.setDataType(_||null,s);const I=(B=this.defaultValue)==null?void 0:B.clone(s,b,P.UUID.uuid(),p);return b.defaultValue=I||null,s==null||s.attemptAutoclose("clone-entity",this.id),b}setDataType(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=s,this.subscribeToDependencies(),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}inferDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type"))){var l;const a=$T(this,s);if(a&&a.parent===this)this.dataType&&this.dataType.merge(a,s);else if(a&&a.parent!==this)if(this.dataType)this.dataType.merge(a,s);else{const p=a.clone(s,this);s==null||s.add(p,G.Added),this.setDataType(p,s)}return(l=this.dataType)==null||l.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let s=[];if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const a=this.parent.parent;s=[...a.breakStatements,...a.continueStatements].flatMap(t=>t.outputs).filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}else if(this.parent.type===f.ReturnStatement&&[f.FunctionDeclaration,f.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const l=this.parent.parent.returnStatements.flatMap(p=>p.outputs);this.implements?s=l.filter(t=>{var m;return this.implements.id===((m=t.implements)==null?void 0:m.id)}):s=l.filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}return s}inferDataTypeFromCounterparts(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var p,t,m;const a=this.getCounterparts(),l=a.find(v=>{var b;return(b=v.dataType)==null?void 0:b.isResolved});if(l)this.setDataType(l.dataType,s),s==null||s.add(this,G.Updated);else for(let v=0;v<a.length;v++){const b=a[v];if((!b.dataType||!b.dataType.isResolved||(p=b.dataType)!=null&&p.inferred)&&b.readsValue&&b.inferDataType(s),(t=b.dataType)!=null&&t.isResolved){this.setDataType(b.dataType,s),s==null||s.add(this,G.Updated);break}}return(m=this.dataType)==null||m.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"get-data-type"))){var a;return(!this.dataType||!this.dataType.isResolved||(a=this.dataType)!=null&&a.inferred)&&this.readsValue?this.inferDataType(s):this.inferDataTypeFromCounterparts(s),this.dataType}};g(yt,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g(yt,"type",f.ReturnDeclaration),g(yt,"USER_MANAGED_PARENT_TYPES",[f.ReturnStatement,f.BreakStatement,f.ContinueStatement]),g(yt,"PARENT_TYPES",[...yt.USER_MANAGED_PARENT_TYPES]),g(yt,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),g(yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(yt,"BASE_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"MUTABLE_META_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,"index"]),g(yt,"INMUTABLE_META_PROPERTIES",[...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"META_PROPERTIES",[...yt.MUTABLE_META_PROPERTIES,...yt.INMUTABLE_META_PROPERTIES]),g(yt,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),g(yt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),g(yt,"UPSTREAM_PROPERTIES",[...yt.MUTABLE_UPSTREAM_PROPERTIES,...yt.INMUTABLE_UPSTREAM_PROPERTIES]),g(yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),g(yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(yt,"DOWNSTREAM_PROPERTIES",[...yt.MUTABLE_DOWNSTREAM_PROPERTIES,...yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(yt,"PROPERTIES",[...yt.META_PROPERTIES,...yt.UPSTREAM_PROPERTIES,...yt.DOWNSTREAM_PROPERTIES]);let wi=yt;function uM(u){var p;const d=Woe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const cpe=Object.freeze(Object.defineProperty({__proto__:null,validate:uM},Symbol.toStringTag,{value:"Module"}));function cM(u){var p;const d=qoe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const ppe=Object.freeze(Object.defineProperty({__proto__:null,validate:cM},Symbol.toStringTag,{value:"Module"}));var pM=(u=>(u.Parent="parent",u))(pM||{});const $t=class $t extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.ContinueStatement);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"throws",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);this.initialData=s,this.project=a,this.id=s.id,this.x=s.x,this.y=s.y}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l),t=s.calledByEntry.map(I=>{const V=W(I);return a.get(V)}),m=s.calledBySuccess.map(I=>{const V=W(I);return a.get(V)}),v=s.calledByError.map(I=>{const V=W(I);return a.get(V)}),b={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:m,calledByError:v,calledByEntry:t,throws:null,parent:p},_=z(b,a);return _.setParent(p,null),_.initChildren(null),_}static validateGenerationTarget(s,a){let l=JSON.parse(JSON.stringify(s));const p=[],t=Cr(l,{parent:{list:!1,types:[f.Loop]}},a);return l=t.modifiedData,p.push(...t.errors,...ur(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(s){const a=[];return s.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
79
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:a,modifiedData:l}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(null,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(s,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.unsubscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.subscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yt(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.defaultValue=this.defaultValue,s.dataType=this.dataType,s.readsValue=this.readsValue,s.implements=this.implements,s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new yt(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.defaultValue=m.defaultValue,this.dataType=m.dataType,this.readsValue=m.readsValue,this.implements=m.implements,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(s.readsValue){const l=W(s.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(s.implements){const l=W(s.implements),p=this.project.get(l);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const t=W(this.initialData.readsValue),m=this.project.get(t);m&&(this.setValueWriter(m,null),s.push(m))}if(this.initialData.implements){const t=W(this.initialData.implements),m=this.project.get(t);m&&(this.setImplements(m,null),s.push(m))}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){var m;const a=[this],l=[],p=[],t=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,s),t.push(this.parent),(m=this.readsValue)==null||m.addValueReader(this,s),this.readsValue&&a.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}propagateChanges(){const s=[this],a=[],l=[],p=[];if(this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent,{updated:m,added:v,removed:b}=t.syncChildren();s.push(...m),a.push(...v),l.push(...b)}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.implements=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=z(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(s)),this.initialData.dataType){const a=z(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(s),this.dataType=a}if(this.initialData.implements){const a=z(this.initialData.implements,this.project);this.setImplements(a,null)}return dp.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this}setValueWriter(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==s&&(this.readsValue=s,a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,s==null||s.add(this,G.Updated)),s==null||s.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.index=s.index||(s.index!==0?p.index:0),this.name=s.name!==void 0?s.name:p.name,this.description=s.description!==void 0?s.description:p.description,this.required=s.required!==void 0?s.required:this.required,this.isError=s.isError!==void 0?s.isError:this.isError,this.constant=s.constant!==void 0?s.constant:p.constant,this.required=s.required!==void 0?s.required:p.required,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await yt.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await yt.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.isError?(this.parent.throws=null,s==null||s.add(this.parent,G.Updated),t.push(this.parent)):(this.parent.removeOutputDeclaration(this,s),t.push(this.parent)),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:_,added:I}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...b),p.push(..._),t.push(...I)}),this.defaultValue){const{updated:v,removed:b}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...b)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v.updated),p.push(...v.removed)}if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const v=this.getCounterparts();v.length&&v.forEach(b=>{if((!(a!=null&&a.hasRemoved(b.id))||!a)&&!b.deleted){const{updated:_,removed:I,added:V,affected:B}=b.remove({ignoreUpstream:s},a);l.push(..._),p.push(...I),t.push(...V),m.push(...B)}})}if(!s&&this.parent){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),m.push(...v.affected)}if(!s&&this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===f.Loop&&(a==null?void 0:a.self)===this&&this.parent.parent.afterAllChildrenInitialized(a),this.isError&&this.parent.type===f.ReturnStatement){const{updated:v,added:b,removed:_,affected:I}=this.parent.syncReturnDeclarations(a);l.push(...v),t.push(...b),p.push(..._),m.push(...I)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(s!=null&&s.hasAdded(this.id))return s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:b,added:_}=m.entity.onDetachedDependencyRestored(this,m.field,s);l.push(...v),p.push(...b),a.push(..._)}),this.defaultValue){const{updated:m}=this.defaultValue.restore({},s);l.push(...m)}if(this.dataType){const m=this.dataType.restore({},s);l.push(...m.updated)}return this.parent&&this.parent.addOutputDeclaration(this,s),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this}}toFlat(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(s))||[],...((p=this.readsValue)==null?void 0:p.toFlat(s))||[],...((t=this.dataType)==null?void 0:t.toFlat(s))||[]])}toFlatIds(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatIds(s))||[],...((t=this.dataType)==null?void 0:t.toFlatIds(s))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(s=new Set){var a,l,p,t;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(s))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(s))||null,implements:((p=this.implements)==null?void 0:p.toJSON(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toJSON(s))||null,parent:this.parent.toReference()})}toJSONClone(s=Ce){var l,p,t,m,v,b,_,I,V;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((b=this.defaultValue)==null?void 0:b.toJSONClone({...s,newId:null}))||null,dataType:((_=this.dataType)==null?void 0:_.toJSONClone({...s,newId:null}))||null,implements:((I=this.implements)==null?void 0:I.toJSONClone({...s,newId:null}))||null,readsValue:((V=this.readsValue)==null?void 0:V.toReference({seenEntityMaps:s.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:s.seenEntityMaps})})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p,t,m,v;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toReference(s))||null,implements:((m=this.implements)==null?void 0:m.toReference(s))||null,dataType:((v=this.dataType)==null?void 0:v.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatJSON(s))||[],...((t=this.dataType)==null?void 0:t.toFlatJSON(s))||[]])}toGenerationTarget(){var s;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(s=this.readsValue)==null?void 0:s.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatGenerationTarget(s))||[],...((t=this.dataType)==null?void 0:t.toFlatGenerationTarget(s))||[]])}clearErrors(){var s,a;return this.errors=[],(s=this.defaultValue)==null||s.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){const s=lM(this);return this.errors=s,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=s,a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,B;let t=yr(a,this);const m=this.toJSON(),v=l||P.UUID.uuid();m.dataType=null,m.id=v,m.version=P.UUID.uuid(),m.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),m.author=(s==null?void 0:s.author)||"1",m.previousVersion=null,m.deleted=!1;const b=er(m,t);a?b.setParent(a,null):b.setParent(this.parent,null),p&&b.subscribe(),b.initChildren(s),s==null||s.add(b,G.Added);const _=(V=this.dataType)==null?void 0:V.clone(s,b,P.UUID.uuid(),p);b.setDataType(_||null,s);const I=(B=this.defaultValue)==null?void 0:B.clone(s,b,P.UUID.uuid(),p);return b.defaultValue=I||null,s==null||s.attemptAutoclose("clone-entity",this.id),b}setDataType(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=s,this.subscribeToDependencies(),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}inferDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type"))){var l;const a=$T(this,s);if(a&&a.parent===this)this.dataType&&this.dataType.merge(a,s);else if(a&&a.parent!==this)if(this.dataType)this.dataType.merge(a,s);else{const p=a.clone(s,this);s==null||s.add(p,G.Added),this.setDataType(p,s)}return(l=this.dataType)==null||l.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let s=[];if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const a=this.parent.parent;s=[...a.breakStatements,...a.continueStatements].flatMap(t=>t.outputs).filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}else if(this.parent.type===f.ReturnStatement&&[f.FunctionDeclaration,f.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const l=this.parent.parent.returnStatements.flatMap(p=>p.outputs);this.implements?s=l.filter(t=>{var m;return this.implements.id===((m=t.implements)==null?void 0:m.id)&&t.id!==this.id}):s=l.filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}return s}inferDataTypeFromCounterparts(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var p,t,m;const a=this.getCounterparts(),l=a.find(v=>{var b;return(b=v.dataType)==null?void 0:b.isResolved});if(l)this.setDataType(l.dataType,s),s==null||s.add(this,G.Updated);else for(let v=0;v<a.length;v++){const b=a[v];if((!b.dataType||!b.dataType.isResolved||(p=b.dataType)!=null&&p.inferred)&&b.readsValue&&b.inferDataType(s),(t=b.dataType)!=null&&t.isResolved){this.setDataType(b.dataType,s),s==null||s.add(this,G.Updated);break}}return(m=this.dataType)==null||m.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"get-data-type"))){var a;return(!this.dataType||!this.dataType.isResolved||(a=this.dataType)!=null&&a.inferred)&&this.readsValue?this.inferDataType(s):this.inferDataTypeFromCounterparts(s),this.dataType}};g(yt,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g(yt,"type",f.ReturnDeclaration),g(yt,"USER_MANAGED_PARENT_TYPES",[f.ReturnStatement,f.BreakStatement,f.ContinueStatement]),g(yt,"PARENT_TYPES",[...yt.USER_MANAGED_PARENT_TYPES]),g(yt,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),g(yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(yt,"BASE_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"MUTABLE_META_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,"index"]),g(yt,"INMUTABLE_META_PROPERTIES",[...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"META_PROPERTIES",[...yt.MUTABLE_META_PROPERTIES,...yt.INMUTABLE_META_PROPERTIES]),g(yt,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),g(yt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),g(yt,"UPSTREAM_PROPERTIES",[...yt.MUTABLE_UPSTREAM_PROPERTIES,...yt.INMUTABLE_UPSTREAM_PROPERTIES]),g(yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),g(yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(yt,"DOWNSTREAM_PROPERTIES",[...yt.MUTABLE_DOWNSTREAM_PROPERTIES,...yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(yt,"PROPERTIES",[...yt.META_PROPERTIES,...yt.UPSTREAM_PROPERTIES,...yt.DOWNSTREAM_PROPERTIES]);let wi=yt;function uM(u){var p;const d=Woe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const cpe=Object.freeze(Object.defineProperty({__proto__:null,validate:uM},Symbol.toStringTag,{value:"Module"}));function cM(u){var p;const d=qoe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const ppe=Object.freeze(Object.defineProperty({__proto__:null,validate:cM},Symbol.toStringTag,{value:"Module"}));var pM=(u=>(u.Parent="parent",u))(pM||{});const $t=class $t extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.ContinueStatement);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"throws",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);this.initialData=s,this.project=a,this.id=s.id,this.x=s.x,this.y=s.y}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l),t=s.calledByEntry.map(I=>{const V=W(I);return a.get(V)}),m=s.calledBySuccess.map(I=>{const V=W(I);return a.get(V)}),v=s.calledByError.map(I=>{const V=W(I);return a.get(V)}),b={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:m,calledByError:v,calledByEntry:t,throws:null,parent:p},_=z(b,a);return _.setParent(p,null),_.initChildren(null),_}static validateGenerationTarget(s,a){let l=JSON.parse(JSON.stringify(s));const p=[],t=Cr(l,{parent:{list:!1,types:[f.Loop]}},a);return l=t.modifiedData,p.push(...t.errors,...ur(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(s){const a=[];return s.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
80
80
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
81
81
|
You shouldn't have to manually update a 'parent' property.
|
|
82
82
|
Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:a,modifiedData:s}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];if(a==="parent"){const{updated:b,added:_,removed:I}=this.remove({ignoreUpstream:!1},l);p.push(...b),t.push(..._),m.push(...I)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];if(a==="parent"){const{updated:b,added:_,removed:I}=this.restore({},l);p.push(...b),t.push(..._),m.push(...I)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s;return(s=this.parent)==null||s.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var s;return(s=this.parent)==null||s.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new $t(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.outputs=[...this.outputs],s.throws=this.throws,s.calledBySuccess=[...this.calledBySuccess],s.calledByError=[...this.calledByError],s.calledByEntry=[...this.calledByEntry],s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new $t(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.outputs=m.outputs,this.throws=m.throws,this.calledBySuccess=m.calledBySuccess,this.calledByError=m.calledByError,this.calledByEntry=m.calledByEntry,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return s.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{s.calledByEntry.find(t=>t.id===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),s.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{s.calledBySuccess.find(t=>t.id===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),s.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{s.calledBySuccess.find(t=>t.id===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(t=>{const m=W(t),v=this.project.get(m);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const m=W(t),v=this.project.get(m);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const m=W(t),v=this.project.get(m);v&&this.addErrorCaller(v,null)}),{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.parent.syncTerminationStatements(s),this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){var m,v;const a=[this],l=[],p=[],t=[];return this.calledByEntry.forEach(b=>{b.addCall(this,s),a.push(b)}),this.calledBySuccess.forEach(b=>{b.addSuccessCall(this,s),a.push(b)}),this.calledByError.forEach(b=>{b.addErrorCall(this,s),a.push(b)}),this.parent.addContinueStatement(this),a.push(this),s==null||s.add(this.parent,G.Affected),(m=this.parent)==null||m.breakStatements.forEach(b=>{b.id!==this.id&&(t.push(b),s==null||s.add(b,G.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(b=>{b.id!==this.id&&(t.push(b),s==null||s.add(b,G.Affected))}),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===s.id)||(this.calledBySuccess.push(s),a==null||a.add(this,G.Updated),l&&Me(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===s.id)||(this.calledByError.push(s),a==null||a.add(this,G.Updated),l&&Me(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===s.id)||(this.calledByEntry.push(s),a==null||a.add(this,G.Updated),l&&Me(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==s.id?!0:(a==null||a.add(this,G.Updated),a==null||a.add(p,G.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==s.id?!0:(a==null||a.add(this,G.Updated),a==null||a.add(p,G.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==s.id?!0:(a==null||a.add(this,G.Updated),a==null||a.add(p,G.Affected),!1)),l&&Me(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(l=>l.id===s.id)||(this.outputs.push(s),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(l=>l.id===s.id)&&(this.outputs=this.outputs.filter(l=>l.id!==s.id),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("remove-output-declaration",this.id),this}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(a=>{const l=z(a,this.project);return l.setParent(this,null),l.initChildren(s),l}),this.initialData.throws&&(this.throws=z(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(s)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.x=s.x||p.x,this.y=s.y||p.y,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await $t.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await $t.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await $t.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await $t.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await $t.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await $t.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.removeContinueStatement(this),this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){var v,b;const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(_=>{const{updated:I,removed:V,added:B}=_.entity.onDetachedDependencyRemoved(this,_.field,a);l.push(...I),p.push(...V),t.push(...B)}),this.outputs.forEach(_=>{const{updated:I,removed:V}=_.remove({ignoreUpstream:!0},a);l.push(...I),p.push(...V)}),this.throws){const{updated:_,removed:I}=this.throws.remove({ignoreUpstream:!0},a);l.push(..._),p.push(...I)}if(!s){const _=this.removeFromParent(a);t.push(..._.added),l.push(..._.updated),p.push(..._.removed),m.push(..._.affected),this.calledBy.forEach(I=>{l.push(I),I.removeCall(this,a)})}return a==null||a.add(this.parent,G.Affected),(v=this.parent)==null||v.breakStatements.forEach(_=>{_.id!==this.id&&(m.push(_),a==null||a.add(_,G.Affected))}),(b=this.parent)==null||b.continueStatements.forEach(_=>{_.id!==this.id&&(m.push(_),a==null||a.add(_,G.Affected))}),a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(s!=null&&s.hasAdded(this.id))return s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:b,added:_}=m.entity.onDetachedDependencyRestored(this,m.field,s);l.push(...v),p.push(...b),a.push(..._)}),this.outputs.forEach(m=>{const{updated:v}=m.restore({},s);l.push(...v)}),this.throws){const{updated:m}=this.throws.restore({},s);l.push(...m)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(m=>{l.push(m),m.addSuccessCall(this,s)}),this.calledByError.forEach(m=>{l.push(m),m.addErrorCall(this,s)}),this.calledByEntry.forEach(m=>{l.push(m),m.addCall(this,s)}),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this}}toFlat(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(s)),...this.calledBy.flatMap(l=>l.toFlat(s)),...this.throws?this.throws.toFlat(s):[]])}toFlatIds(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(s)),...this.calledBy.flatMap(l=>l.toFlatIds(s)),...this.throws?this.throws.toFlatIds(s):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(s=new Set){var a,l;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),outputs:this.outputs.map(p=>p.toJSON(s)),throws:((a=this.throws)==null?void 0:a.toJSON(s))||null,parent:((l=this.parent)==null?void 0:l.toReference())||null})}toJSONClone(s=Ce){var l,p,t,m,v,b,_;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:s.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:s.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:s.seenEntityMaps})),outputs:this.outputs.map(I=>I.toJSONClone({...s,newId:null})),throws:((b=this.throws)==null?void 0:b.toJSONClone({...s,newId:null}))||null,parent:((_=this.parent)==null?void 0:_.toReference({seenEntityMaps:s.seenEntityMaps}))||null})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(t=>t.toReference(s)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference(s)),calledByError:this.calledByError.map(t=>t.toReference(s)),calledByEntry:this.calledByEntry.map(t=>t.toReference(s)),throws:((p=this.throws)==null?void 0:p.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){var l;return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(p=>p.toFlatJSON(s)),...this.calledBy.flatMap(p=>p.toFlatJSON(s)),...((l=this.throws)==null?void 0:l.toFlatJSON(s))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(s=>s.id),calledByError:this.calledByError.map(s=>s.id),calledBySuccess:this.calledBySuccess.map(s=>s.id),parent:this.parent.id}}toFlatGenerationTarget(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(s)),...this.throws?this.throws.toFlatGenerationTarget(s):[]])}clearErrors(){var s;return this.errors=[],this.outputs.forEach(a=>a.clearErrors()),(s=this.throws)==null||s.clearErrors(),this}validate(){const s=cM(this);return this.errors=s,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var B;let t=yr(a,this);const m=this.toJSON(),v=l||P.UUID.uuid();m.outputs=[];const b=v.split("-id"),_=b[b.length-1||0]||v;m.id=v,m.version=P.UUID.uuid(),m.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),m.author=(s==null?void 0:s.author)||"1",m.previousVersion=null,m.deleted=!1;const I=er(m,t);a?I.setParent(a,null):I.setParent(this.parent,null),p&&I.subscribe(),I.initChildren(s),s==null||s.add(I,G.Added);const V=(B=this.outputs)==null?void 0:B.map((K,q)=>K.clone(s,I,_+"-return-declaration-"+q+"-id",p));return I.outputs=V,this.throws&&(I.throws=this.throws.clone(s,I,_+"-throws-id",p)),s==null||s.attemptAutoclose("clone-entity",this.id),I}};g($t,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g($t,"type",f.ContinueStatement),g($t,"USER_MANAGED_PARENT_TYPES",[f.Loop]),g($t,"PARENT_TYPES",[...$t.USER_MANAGED_PARENT_TYPES]),g($t,"MUTABLE_BASE_PROPERTIES",[]),g($t,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g($t,"BASE_PROPERTIES",[...$t.MUTABLE_BASE_PROPERTIES,...$t.INMUTABLE_BASE_PROPERTIES]),g($t,"MUTABLE_META_PROPERTIES",["x","y"]),g($t,"INMUTABLE_META_PROPERTIES",[...$t.INMUTABLE_BASE_PROPERTIES]),g($t,"META_PROPERTIES",[...$t.MUTABLE_META_PROPERTIES,...$t.INMUTABLE_META_PROPERTIES]),g($t,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g($t,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g($t,"UPSTREAM_PROPERTIES",[...$t.MUTABLE_UPSTREAM_PROPERTIES,...$t.INMUTABLE_UPSTREAM_PROPERTIES]),g($t,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),g($t,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g($t,"DOWNSTREAM_PROPERTIES",[...$t.MUTABLE_DOWNSTREAM_PROPERTIES,...$t.INMUTABLE_DOWNSTREAM_PROPERTIES]),g($t,"PROPERTIES",[...$t.META_PROPERTIES,...$t.UPSTREAM_PROPERTIES,...$t.DOWNSTREAM_PROPERTIES]);let Qr=$t;var FT=(u=>(u.Parent="return-statement-parent",u))(FT||{});const tr=class tr extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.ReturnStatement);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"throws",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);this.initialData=s,this.project=a,this.id=s.id,this.x=s.x,this.y=s.y}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l),t=s.calledByEntry.map(I=>{const V=W(I);return a.get(V)}),m=s.calledBySuccess.map(I=>{const V=W(I);return a.get(V)}),v=s.calledByError.map(I=>{const V=W(I);return a.get(V)}),b={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:m,calledByError:v,calledByEntry:t,throws:null,parent:p},_=z(b,a);return _.setParent(p,null),_.initChildren(null),_}static validateGenerationTarget(s,a){let l=JSON.parse(JSON.stringify(s));const p=[],t=Cr(l,{parent:{list:!1,types:br}},a);return l=t.modifiedData,p.push(...t.errors,...ur(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(s){const a=[];return s.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
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.6321",
|
|
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",
|