@elyx-code/project-logic-tree 0.0.6226 → 0.0.6227
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 +2 -39
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39386,13 +39386,7 @@ Specifically for break statements the parent needs to always be the 'loop' entit
|
|
|
39386
39386
|
throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);
|
|
39387
39387
|
return this.initialData.calledByEntry.forEach((d) => {
|
|
39388
39388
|
const o = _(d), l = this.project.get(o);
|
|
39389
|
-
|
|
39390
|
-
`Break-statement with id '${this.id}' has a 'calledByEntry' with an invalid reference. No referenced entity id found.`
|
|
39391
|
-
), l || console.warn(
|
|
39392
|
-
`Break-statement with id '${this.id}' has a 'calledByEntry' entity with id '${o}' that is not found in the project.`
|
|
39393
|
-
), l && (this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8" && console.warn(
|
|
39394
|
-
`Break-statement with id '${this.id}' adding 'calledByEntry' entity with id '${o}'`
|
|
39395
|
-
), this.addEntryCaller(l, null), e.push(l));
|
|
39389
|
+
l && (this.addEntryCaller(l, null), e.push(l));
|
|
39396
39390
|
}), this.initialData.calledBySuccess.forEach((d) => {
|
|
39397
39391
|
const o = _(d), l = this.project.get(
|
|
39398
39392
|
o
|
|
@@ -39505,38 +39499,7 @@ Specifically for break statements the parent needs to always be the 'loop' entit
|
|
|
39505
39499
|
"add-entry-caller"
|
|
39506
39500
|
)
|
|
39507
39501
|
), r = !1) {
|
|
39508
|
-
|
|
39509
|
-
this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8" && (console.warn(
|
|
39510
|
-
`Break-statement with id '${this.id}' already has an entry point with id '${e.id}', skipping adding it.`
|
|
39511
|
-
), console.warn("this: ", this), console.warn("shallow: ", this.toShallowJSON()));
|
|
39512
|
-
else {
|
|
39513
|
-
if (this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8" && (console.warn(
|
|
39514
|
-
`Break-statement with id '${this.id}' pushing caller entity to 'calledByEntry' array.`
|
|
39515
|
-
), console.warn("caller: ", e), console.warn("this: ", this), console.warn("shallow: ", this.toShallowJSON())), this.calledByEntry.push(e), this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8") {
|
|
39516
|
-
console.warn(
|
|
39517
|
-
`Break-statement change-set BEFORE adding entry point with id '${e.id}'`
|
|
39518
|
-
), console.warn("changeSet: ", t);
|
|
39519
|
-
const s = t == null ? void 0 : t.get(
|
|
39520
|
-
"e4f5b0c0-df48-43de-8f4c-afec0b161ee8"
|
|
39521
|
-
);
|
|
39522
|
-
console.warn("changeSetVersion: ", s);
|
|
39523
|
-
}
|
|
39524
|
-
if (t == null || t.add(this, A.Updated), this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8") {
|
|
39525
|
-
console.warn(
|
|
39526
|
-
`Break-statement change-set AFTER adding entry point with id '${e.id}'`
|
|
39527
|
-
), console.warn("changeSet: ", t);
|
|
39528
|
-
const s = t == null ? void 0 : t.get(
|
|
39529
|
-
"e4f5b0c0-df48-43de-8f4c-afec0b161ee8"
|
|
39530
|
-
);
|
|
39531
|
-
console.warn("changeSetVersion: ", s);
|
|
39532
|
-
}
|
|
39533
|
-
r && (this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8" && (console.warn(
|
|
39534
|
-
`Break-statement with id '${this.id}' recalculating scope after adding entry point with id '${e.id}'`
|
|
39535
|
-
), console.warn("this: ", this), console.warn("shallow: ", this.toShallowJSON())), H(this, t), this.id === "e4f5b0c0-df48-43de-8f4c-afec0b161ee8" && (console.warn(
|
|
39536
|
-
`Break-statement with id '${this.id}' AFTER scope recalculation`
|
|
39537
|
-
), console.warn("this: ", this), console.warn("shallow: ", this.toShallowJSON())));
|
|
39538
|
-
}
|
|
39539
|
-
return t == null || t.attemptAutoclose("add-entry-caller", this.id), this;
|
|
39502
|
+
return this.calledByEntry.find((s) => s.id === e.id) || (this.calledByEntry.push(e), t == null || t.add(this, A.Updated), r && H(this, t)), t == null || t.attemptAutoclose("add-entry-caller", this.id), this;
|
|
39540
39503
|
}
|
|
39541
39504
|
removeCaller(e, t = this.project.addChangeSet(
|
|
39542
39505
|
new E(
|
package/dist/index.umd.cjs
CHANGED
|
@@ -86,7 +86,7 @@ ${Jd(t)}`,issue:null}));else{const u=t.events.find(y=>y.implements.id===e.implem
|
|
|
86
86
|
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Gd.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],d=[];return Object.values(this.detachedDependents).forEach(o=>{const l=o.entity.afterAllChildrenInitialized(e);t.push(...l.updated),i.push(...l.added),s.push(...l.removed),d.push(...l.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],d=[],o=[],l=[];return{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],d=[],o=[],l=[];return{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],i=[],s=[],d=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const d=_(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${kt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${kt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=_(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${kt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}else throw new Error(`${kt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],d=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=V(t,this.project);if(i.addEntryCaller(this,null),i.type===n.ReturnStatement){const s=Et(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e));return i}),this.implements=V(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await Pe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),d.push(...I)}),this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),di(this).forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:y,added:c}=l.entity.onDetachedDependencyRestored(this,l.field,e);i.push(...u),s.push(...y),t.push(...c)}),this.inputs.forEach(l=>{const{updated:u}=l.restore({},e);i.push(...u)}),di(this).forEach(l=>{const{updated:u}=l.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=di(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,d,o,l;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),calls:this.calls.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=f1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=di(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,d=!1){var P;let o=mt(t,this);const l=this.toJSON(),u=i||m.UUID.uuid();l.inputs=[];const y=u.split("-id"),c=y[y.length-1||0]||u;l.id=u,l.version=m.UUID.uuid(),l.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),l.author=(e==null?void 0:e.author)||"1",l.previousVersion=null,l.deleted=!1;const I=nt(l,o);t?I.setParent(t,null):I.setParent(this.parent,null),s&&I.subscribe(),I.initChildren(e),e==null||e.add(I,b.Added);const E=(P=this.inputs)==null?void 0:P.map((C,M)=>C.clone(e,I,c+"-argument-declaration-"+M+"-id",s));return I.inputs=E,d?(di(this).map((C,M)=>C.clone(e,I,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),I):(e==null||e.attemptAutoclose("clone-entity",this.id),I)}getVariableInstances(){return Ye(this).filter(i=>i.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Pe,"type",n.GlobalEvent),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES]),f(Pe,"MUTABLE_BASE_PROPERTIES",["description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let kr=Pe;function y1(r){var s;const a=A5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(d=>d.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const MJ=Object.freeze(Object.defineProperty({__proto__:null,validate:y1},Symbol.toStringTag,{value:"Module"}));var _c=(r=>(r.Parent="parent",r))(_c||{});const xe=class xe extends dt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.BreakStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),d=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),o=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),l=e.calledByError.map(c=>{const I=_(c);return t.get(I)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:s},y=V(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],d=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=d.modifiedData,s.push(...d.errors,...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
87
87
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
88
88
|
You shouldn't have to manually update a 'parent' property.
|
|
89
|
-
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],d=[];return Object.values(this.detachedDependents).forEach(o=>{const l=o.entity.afterAllChildrenInitialized(e);t.push(...l.updated),i.push(...l.added),s.push(...l.removed),d.push(...l.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),d.push(...y),o.push(...c)}return{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),d.push(...y),o.push(...c)}return{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],i=[],s=[],d=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const d=_(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${d}' 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(d=>{const o=_(d),l=this.project.get(o);o||console.warn(`Break-statement with id '${this.id}' has a 'calledByEntry' with an invalid reference. No referenced entity id found.`),l||console.warn(`Break-statement with id '${this.id}' has a 'calledByEntry' entity with id '${o}' that is not found in the project.`),l&&(this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"&&console.warn(`Break-statement with id '${this.id}' adding 'calledByEntry' entity with id '${o}'`),this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=_(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=_(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],d=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){if(this.calledByEntry.find(s=>s.id===e.id))this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"&&(console.warn(`Break-statement with id '${this.id}' already has an entry point with id '${e.id}', skipping adding it.`),console.warn("this: ",this),console.warn("shallow: ",this.toShallowJSON()));else{if(this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"&&(console.warn(`Break-statement with id '${this.id}' pushing caller entity to 'calledByEntry' array.`),console.warn("caller: ",e),console.warn("this: ",this),console.warn("shallow: ",this.toShallowJSON())),this.calledByEntry.push(e),this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"){console.warn(`Break-statement change-set BEFORE adding entry point with id '${e.id}'`),console.warn("changeSet: ",t);const s=t==null?void 0:t.get("e4f5b0c0-df48-43de-8f4c-afec0b161ee8");console.warn("changeSetVersion: ",s)}if(t==null||t.add(this,b.Updated),this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"){console.warn(`Break-statement change-set AFTER adding entry point with id '${e.id}'`),console.warn("changeSet: ",t);const s=t==null?void 0:t.get("e4f5b0c0-df48-43de-8f4c-afec0b161ee8");console.warn("changeSetVersion: ",s)}i&&(this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"&&(console.warn(`Break-statement with id '${this.id}' recalculating scope after adding entry point with id '${e.id}'`),console.warn("this: ",this),console.warn("shallow: ",this.toShallowJSON())),K(this,t),this.id==="e4f5b0c0-df48-43de-8f4c-afec0b161ee8"&&(console.warn(`Break-statement with id '${this.id}' AFTER scope recalculation`),console.warn("this: ",this),console.warn("shallow: ",this.toShallowJSON())))}return t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:y,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);i.push(...u),s.push(...y),d.push(...c)}),this.outputs.forEach(l=>{const{updated:u,removed:y}=l.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:l,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...l),s.push(...u)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(l=>{i.push(l),l.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:l,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...l),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);i.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=J){var i,s,d,o,l,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=y1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let d=mt(t,this);const o=this.toJSON(),l=i||m.UUID.uuid();o.outputs=[];const u=l.split("-id"),y=u[u.length-1||0]||l;o.id=l,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(xe,"type",n.BreakStatement),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Zr=xe;function Mc(r){var d,o;const a=s5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate()),r.outputs.forEach(l=>l.validate()),(d=r.error)==null||d.validate(),(o=r.body)==null||o.validate();const s=[...Ir(r)];return He(r.errors,s)}function NJ(r){return Mc(r)}const LJ=Object.freeze(Object.defineProperty({__proto__:null,validate:Mc,validateListLoop:NJ},Symbol.toStringTag,{value:"Module"}));function h1(r){const a=TD(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return He(r.errors,i)}const UJ=Object.freeze(Object.defineProperty({__proto__:null,validate:h1},Symbol.toStringTag,{value:"Module"}));var m1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(m1||{});const we=class we extends dt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"implementation",null);f(this,"parent",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=_(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},d=V(s,t);return i&&d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],d=bt(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=d.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const l=o,y=Zt(l).filter(c=>!c.interactive);if(y.length){let c=y.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(y.map(I=>x(I,I.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(y[0],y[0].project)}").`;c+=`
|
|
89
|
+
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],d=[];return Object.values(this.detachedDependents).forEach(o=>{const l=o.entity.afterAllChildrenInitialized(e);t.push(...l.updated),i.push(...l.added),s.push(...l.removed),d.push(...l.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),d.push(...y),o.push(...c)}return{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),d.push(...y),o.push(...c)}return{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],i=[],s=[],d=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const d=_(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${d}' 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(d=>{const o=_(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=_(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=_(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],d=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:y,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);i.push(...u),s.push(...y),d.push(...c)}),this.outputs.forEach(l=>{const{updated:u,removed:y}=l.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:l,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...l),s.push(...u)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(l=>{i.push(l),l.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:l,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...l),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);i.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=J){var i,s,d,o,l,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=y1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let d=mt(t,this);const o=this.toJSON(),l=i||m.UUID.uuid();o.outputs=[];const u=l.split("-id"),y=u[u.length-1||0]||l;o.id=l,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(xe,"type",n.BreakStatement),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Zr=xe;function Mc(r){var d,o;const a=s5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate()),r.outputs.forEach(l=>l.validate()),(d=r.error)==null||d.validate(),(o=r.body)==null||o.validate();const s=[...Ir(r)];return He(r.errors,s)}function NJ(r){return Mc(r)}const LJ=Object.freeze(Object.defineProperty({__proto__:null,validate:Mc,validateListLoop:NJ},Symbol.toStringTag,{value:"Module"}));function h1(r){const a=TD(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return He(r.errors,i)}const UJ=Object.freeze(Object.defineProperty({__proto__:null,validate:h1},Symbol.toStringTag,{value:"Module"}));var m1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(m1||{});const we=class we extends dt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"implementation",null);f(this,"parent",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=_(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},d=V(s,t);return i&&d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],d=bt(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=d.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const l=o,y=Zt(l).filter(c=>!c.interactive);if(y.length){let c=y.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(y.map(I=>x(I,I.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(y[0],y[0].project)}").`;c+=`
|
|
90
90
|
${en}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:c,issue:null}))}}else if(o&&o.type===n.DataType){const l=o;l.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
91
91
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
92
92
|
${Hi({describe_entity:l.entity.id})}
|
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.6227",
|
|
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",
|