New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@baklavajs/core

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@baklavajs/core - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

dist/src/connection.d.ts

2

dist/index.js

@@ -16,2 +16,2 @@ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("BaklavaJS",[],t):"object"==typeof exports?exports.BaklavaJS=t():e.BaklavaJS=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(o,i,function(t){return e[t]}.bind(null,i));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);

***************************************************************************** */
var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function i(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function r(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,i,r=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(e){i={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}var a,u=function(){function e(){this.listeners=new Map}return e.prototype.addListener=function(e,t){this.listeners.set(e,t)},e.prototype.removeListener=function(e){this.listeners.has(e)&&this.listeners.delete(e)},e.prototype.emit=function(e){this.listeners.forEach(function(t){return t(e)})},e}(),c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.prototype.emit=function(e){var t,n;try{for(var o=r(Array.from(this.listeners.values())),i=o.next();!i.done;i=o.next()){if(!1===(0,i.value)(e))return!0}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return!1},t}(u),f=function(){function e(){this.tapMap=new Map,this.taps=[]}return e.prototype.tap=function(e,t){this.tapMap.has(e)&&this.untap(e),this.tapMap.set(e,t),this.taps.push(t)},e.prototype.untap=function(e){if(this.tapMap.has(e)){var t=this.tapMap.get(e);this.tapMap.delete(e);var n=this.taps.indexOf(t);n>=0&&this.taps.splice(n,1)}},e}(),p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.prototype.execute=function(e){var t,n,o=e;try{for(var i=r(this.taps),s=i.next();!s.done;s=i.next()){o=(0,s.value)(o)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return o},t}(f),d=0;function h(){return(Date.now()+d++).toString()}!function(e){e[e.NONE=0]="NONE",e[e.ALLOWED=1]="ALLOWED",e[e.FORBIDDEN=2]="FORBIDDEN"}(a||(a={}));var l=function(){function e(e,t){if(this.isInDanger=!1,this.destructed=!1,this.events={destruct:new u},!e||!t)throw new Error("Cannot initialize connection with null/undefined for 'from' or 'to' values");this.id=h(),this.from=e,this.to=t,this.from.connectionCount++,this.to.connectionCount++}return e.prototype.destruct=function(){this.events.destruct.emit(),this.from.connectionCount--,this.to.connectionCount--,this.destructed=!0},e}(),v=function(){return function(e,t){if(!e||!t)throw new Error("Cannot initialize connection with null/undefined for 'from' or 'to' values");this.id=h(),this.from=e,this.to=t}}(),y=function(){function e(){this._plugins=new Set,this._nodes=[],this._connections=[],this._nodeTypes=new Map,this._nodeCategories=new Map([["default",[]]]),this.events={beforeRegisterNodeType:new c,registerNodeType:new u,beforeAddNode:new c,addNode:new u,beforeRemoveNode:new c,removeNode:new u,beforeAddConnection:new c,addConnection:new u,checkConnection:new c,beforeRemoveConnection:new c,removeConnection:new u,beforeUsePlugin:new c,usePlugin:new u},this.hooks={save:new p,load:new p}}return Object.defineProperty(e.prototype,"nodes",{get:function(){return this._nodes},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){return this._connections},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nodeTypes",{get:function(){return this._nodeTypes},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nodeCategories",{get:function(){return this._nodeCategories},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"plugins",{get:function(){return this._plugins},enumerable:!0,configurable:!0}),e.prototype.registerNodeType=function(e,t,n){void 0===n&&(n="default"),this.events.beforeRegisterNodeType.emit({typeName:e,type:t,category:n})||(this._nodeTypes.set(e,t),this.nodeCategories.has(n)||this._nodeCategories.set(n,[]),this.nodeCategories.get(n).push(e),this.events.registerNodeType.emit({typeName:e,type:t,category:n}))},e.prototype.addNode=function(e){if(!this.events.beforeAddNode.emit(e))return e.registerEditor(this),this._nodes.push(e),this.events.addNode.emit(e),e},e.prototype.removeNode=function(e){var t=this;if(this.nodes.includes(e)){if(this.events.beforeRemoveNode.emit(e))return;this.connections.filter(function(t){return t.from.parent===e||t.to.parent===e}).forEach(function(e){return t.removeConnection(e)}),this._nodes.splice(this.nodes.indexOf(e),1),this.events.removeNode.emit(e)}},e.prototype.addConnection=function(e,t){var n=this,o=this.checkConnection(e,t);if(o&&!this.events.beforeAddConnection.emit({from:e,to:t})){this.connections.filter(function(e){return e.to===o.to}).forEach(function(e){return n.removeConnection(e)});var i=new l(o.from,o.to);return this._connections.push(i),this.events.addConnection.emit(i),i}},e.prototype.removeConnection=function(e){if(this.connections.includes(e)){if(this.events.beforeRemoveConnection.emit(e))return;e.destruct(),this._connections.splice(this.connections.indexOf(e),1),this.events.removeConnection.emit(e)}},e.prototype.checkConnection=function(e,t){if(!e||!t)return!1;if(e.parent===t.parent)return!1;if(e.isInput&&!t.isInput){var n=e;e=t,t=n}return!(e.isInput||!t.isInput)&&(!this.events.checkConnection.emit({from:e,to:t})&&new v(e,t))},e.prototype.load=function(e){for(var t,n,o,i,s=this.connections.length-1;s>=0;s--)this.removeConnection(this.connections[s]);for(s=this.nodes.length-1;s>=0;s--)this.removeNode(this.nodes[s]);try{for(var a=r(e.nodes),u=a.next();!u.done;u=a.next()){var c=u.value,f=this.nodeTypes.get(c.type);if(f){var p=new f;this.addNode(p),p.load(c)}else console.warn("Node type "+c.type+" is not registered")}}catch(e){t={error:e}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}try{for(var d=r(e.connections),h=d.next();!h.done;h=d.next()){var l=h.value,v=this.findNodeInterface(l.from),y=this.findNodeInterface(l.to);v?y?this.addConnection(v,y):console.warn("Could not find interface with id "+l.to):console.warn("Could not find interface with id "+l.from)}}catch(e){o={error:e}}finally{try{h&&!h.done&&(i=d.return)&&i.call(d)}finally{if(o)throw o.error}}this.hooks.load.execute(e)},e.prototype.save=function(){var e={nodes:this.nodes.map(function(e){return e.save()}),connections:this.connections.map(function(e){return{id:e.id,from:e.from.id,to:e.to.id}})};return this.hooks.save.execute(e)},e.prototype.use=function(e){return!this.events.beforeUsePlugin.emit(e)&&(this._plugins.add(e),e.register(this),this.events.usePlugin.emit(e),!0)},e.prototype.findNodeInterface=function(e){var t,n,o,i;try{for(var s=r(this.nodes),a=s.next();!a.done;a=s.next()){var u=a.value;try{for(var c=r(u.interfaces.keys()),f=c.next();!f.done;f=c.next()){var p=f.value;if(u.interfaces.get(p).id===e)return u.interfaces.get(p)}}catch(e){o={error:e}}finally{try{f&&!f.done&&(i=c.return)&&i.call(c)}finally{if(o)throw o.error}}}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e}(),m=function(){function e(e,t){this.events={setConnectionCount:new u,beforeSetValue:new c,setValue:new u},this.hooks={load:new p,save:new p},this._connectionCount=0,this._value=null,this.parent=e,this.isInput=t,this.id="ni_"+h()}return Object.defineProperty(e.prototype,"connectionCount",{get:function(){return this._connectionCount},set:function(e){this._connectionCount=e,this.events.setConnectionCount.emit(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this.events.beforeSetValue.emit(e)||(this._value=e,this.events.setValue.emit(e))},enumerable:!0,configurable:!0}),e.prototype.load=function(e){this.id=e.id,this.value=e.value,this.hooks.load.execute(e)},e.prototype.save=function(){var e={id:this.id,value:this.value};return this.hooks.save.execute(e)},e}(),b=function(){function e(e,t,n){this.events={beforeSetValue:new c,setValue:new u},this.optionComponent=e,this.sidebarComponent=n,this._value=t}return Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this.events.beforeSetValue.emit(e)||(this._value=e,this.events.setValue.emit(e))},enumerable:!0,configurable:!0}),e}(),w=function(){function e(){this.id="node_"+h(),this.interfaces=new Map,this.options=new Map,this.state={},this.events={beforeAddInterface:new c,addInterface:new u,beforeRemoveInterface:new c,removeInterface:new u,beforeAddOption:new c,addOption:new u,beforeRemoveOption:new c,removeOption:new u,update:new u},this.hooks={load:new p,save:new p}}return Object.defineProperty(e.prototype,"inputInterfaces",{get:function(){var e={};return this.interfaces.forEach(function(t,n){t.isInput&&(e[n]=t)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outputInterfaces",{get:function(){var e={};return this.interfaces.forEach(function(t,n){t.isInput||(e[n]=t)}),e},enumerable:!0,configurable:!0}),e.prototype.load=function(e){var t=this;this.id=e.id,this.name=e.name,this.state=e.state,e.options.forEach(function(e){var n=s(e,2),o=n[0],i=n[1];t.options.has(o)&&(t.options.get(o).value=i)}),e.interfaces.forEach(function(e){var n=s(e,2),o=n[0],i=n[1];t.interfaces.has(o)&&t.interfaces.get(o).load(i)}),this.hooks.load.execute(e)},e.prototype.save=function(){var e={type:this.type,id:this.id,name:this.name,options:Array.from(this.options.entries()).map(function(e){var t=s(e,2);return[t[0],t[1].value]}),state:this.state,interfaces:Array.from(this.interfaces.entries()).map(function(e){var t=s(e,2);return[t[0],t[1].save()]})};return this.hooks.save.execute(e)},e.prototype.calculate=function(){},e.prototype.addInputInterface=function(e,t,n,o){var i=this;if(!this.events.beforeAddInterface.emit({name:e,isInput:!0,option:t,defaultValue:n})){var r=this.addInterface(!0,e,t);return r.events.setValue.addListener(this,function(){return i.events.update.emit({name:e,interface:r})}),r.value=n,Object.entries(o||{}).forEach(function(e){var t=s(e,2),n=t[0],o=t[1];r[n]=o}),this.events.addInterface.emit(r),r}},e.prototype.addOutputInterface=function(e,t){if(!this.events.beforeAddInterface.emit({name:e,isInput:!1})){var n=this.addInterface(!1,e);return Object.entries(t||{}).forEach(function(e){var t=s(e,2),o=t[0],i=t[1];n[o]=i}),this.events.addInterface.emit(n),n}},e.prototype.removeInterface=function(e){var t=this,n=this.getInterface(e);if(n){if(this.events.beforeRemoveInterface.emit(n))return;if(n.connectionCount>0){if(!this.editorInstance)throw new Error("Interface is connected, but no editor instance is specified. Unable to delete interface");this.editorInstance.connections.filter(function(e){return e.from===n||e.to===n}).forEach(function(e){t.editorInstance.removeConnection(e)})}this.interfaces.delete(e),this.events.removeInterface.emit(n)}},e.prototype.addOption=function(e,t,n,o,i){var r=this;if(void 0===n&&(n=null),!this.events.beforeAddOption.emit({name:e,component:t,defaultValue:n,sidebarComponent:o})){var a=new b(t,n,o);return Object.entries(i||{}).forEach(function(e){var t=s(e,2),n=t[0],o=t[1];a[n]=o}),a.events.setValue.addListener(this,function(){r.events.update.emit({name:e,option:a})}),this.options.set(e,a),this.events.addOption.emit({name:e,option:a}),a}},e.prototype.removeOption=function(e){if(this.options.has(e)){var t=this.options.get(e);if(this.events.beforeRemoveOption.emit({name:e,option:t}))return;this.options.delete(e),this.events.removeOption.emit({name:e,option:t})}},e.prototype.getInterface=function(e){if(!this.interfaces.has(e))throw new Error("No interface named '"+e+"'");return this.interfaces.get(e)},e.prototype.getOptionValue=function(e){if(!this.options.has(e))throw new Error("No option named '"+e+"'");return this.options.get(e).value},e.prototype.setOptionValue=function(e,t){if(!this.options.has(e))throw new Error("No option named '"+e+"'");this.options.get(e).value=t},e.prototype.registerEditor=function(e){this.editorInstance=e},e.prototype.addInterface=function(e,t,n){var o=new m(this,e);return o.option=n,this.interfaces.set(t,o),o},e}();function g(e){return"function"==typeof e?e():e}var C=function(){function e(e){this.name="",this.intfs=[],this.options=new Map,this.name=e}return e.prototype.build=function(){return e=this.name,t=this.intfs,n=this.options,o=this.calcFunction,function(a){function u(){var o,i,u=a.call(this)||this;u.type=e,u.name=e;try{for(var c=r(t),f=c.next();!f.done;f=c.next()){var p=f.value;p.isInput?u.addInputInterface(p.name,p.option,g(p.defaultValue),p.additionalProperties):u.addOutputInterface(p.name,p.additionalProperties)}}catch(e){o={error:e}}finally{try{f&&!f.done&&(i=c.return)&&i.call(c)}finally{if(o)throw o.error}}return Array.from(n.entries()).forEach(function(e){var t=s(e,2),n=t[0],o=t[1];u.addOption(n,o.optionComponent,g(o.value),o.sidebarComponent)}),u}return i(u,a),u.prototype.calculate=function(){if(o)return o.call(this,this)},u}(w);var e,t,n,o},e.prototype.addInputInterface=function(e,t,n,o){return this.checkDefaultValue(n),this.intfs.push({isInput:!0,name:e,option:t,defaultValue:n,additionalProperties:o}),this},e.prototype.addOutputInterface=function(e,t){return this.intfs.push({isInput:!1,name:e,additionalProperties:t}),this},e.prototype.addOption=function(e,t,n,o,i){return this.checkDefaultValue(n),this.options.set(e,{value:n,optionComponent:t,sidebarComponent:o}),this},e.prototype.onCalculate=function(e){return this.calcFunction=e,this},e.prototype.checkDefaultValue=function(e){if("object"==typeof e)throw new Error("If the default value is an object, provide a generator function instead of the object")},e}();n.d(t,"BaklavaEvent",function(){return u}),n.d(t,"PreventableBaklavaEvent",function(){return c}),n.d(t,"Hook",function(){return f}),n.d(t,"SequentialHook",function(){return p}),n.d(t,"TemporaryConnectionState",function(){return a}),n.d(t,"Connection",function(){return l}),n.d(t,"DummyConnection",function(){return v}),n.d(t,"Editor",function(){return y}),n.d(t,"Node",function(){return w}),n.d(t,"NodeBuilder",function(){return C}),n.d(t,"NodeInterface",function(){return m}),n.d(t,"NodeOption",function(){return b})}])});
var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function i(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function r(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,i,r=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(e){i={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}var a=function(){function e(){this.listeners=new Map}return e.prototype.addListener=function(e,t){this.listeners.set(e,t)},e.prototype.removeListener=function(e){this.listeners.has(e)&&this.listeners.delete(e)},e.prototype.emit=function(e){this.listeners.forEach(function(t){return t(e)})},e}(),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.prototype.emit=function(e){var t,n;try{for(var o=r(Array.from(this.listeners.values())),i=o.next();!i.done;i=o.next()){if(!1===(0,i.value)(e))return!0}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return!1},t}(a),c=function(){function e(){this.tapMap=new Map,this.taps=[]}return e.prototype.tap=function(e,t){this.tapMap.has(e)&&this.untap(e),this.tapMap.set(e,t),this.taps.push(t)},e.prototype.untap=function(e){if(this.tapMap.has(e)){var t=this.tapMap.get(e);this.tapMap.delete(e);var n=this.taps.indexOf(t);n>=0&&this.taps.splice(n,1)}},e}(),f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.prototype.execute=function(e){var t,n,o=e;try{for(var i=r(this.taps),s=i.next();!s.done;s=i.next()){o=(0,s.value)(o)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return o},t}(c),p=0;function d(){return(Date.now()+p++).toString()}var h=function(){function e(e,t){if(this.isInDanger=!1,this.destructed=!1,this.events={destruct:new a},!e||!t)throw new Error("Cannot initialize connection with null/undefined for 'from' or 'to' values");this.id=d(),this.from=e,this.to=t,this.from.connectionCount++,this.to.connectionCount++}return e.prototype.destruct=function(){this.events.destruct.emit(),this.from.connectionCount--,this.to.connectionCount--,this.destructed=!0},e}(),l=function(){return function(e,t){if(!e||!t)throw new Error("Cannot initialize connection with null/undefined for 'from' or 'to' values");this.id=d(),this.from=e,this.to=t}}(),v=function(){function e(){this._plugins=new Set,this._nodes=[],this._connections=[],this._nodeTypes=new Map,this._nodeCategories=new Map([["default",[]]]),this.events={beforeRegisterNodeType:new u,registerNodeType:new a,beforeAddNode:new u,addNode:new a,beforeRemoveNode:new u,removeNode:new a,beforeAddConnection:new u,addConnection:new a,checkConnection:new u,beforeRemoveConnection:new u,removeConnection:new a,beforeUsePlugin:new u,usePlugin:new a},this.hooks={save:new f,load:new f}}return Object.defineProperty(e.prototype,"nodes",{get:function(){return this._nodes},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){return this._connections},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nodeTypes",{get:function(){return this._nodeTypes},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nodeCategories",{get:function(){return this._nodeCategories},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"plugins",{get:function(){return this._plugins},enumerable:!0,configurable:!0}),e.prototype.registerNodeType=function(e,t,n){void 0===n&&(n="default"),this.events.beforeRegisterNodeType.emit({typeName:e,type:t,category:n})||(this._nodeTypes.set(e,t),this.nodeCategories.has(n)||this._nodeCategories.set(n,[]),this.nodeCategories.get(n).push(e),this.events.registerNodeType.emit({typeName:e,type:t,category:n}))},e.prototype.addNode=function(e){if(!this.events.beforeAddNode.emit(e))return e.registerEditor(this),this._nodes.push(e),this.events.addNode.emit(e),e},e.prototype.removeNode=function(e){var t=this;if(this.nodes.includes(e)){if(this.events.beforeRemoveNode.emit(e))return;this.connections.filter(function(t){return t.from.parent===e||t.to.parent===e}).forEach(function(e){return t.removeConnection(e)}),this._nodes.splice(this.nodes.indexOf(e),1),this.events.removeNode.emit(e)}},e.prototype.addConnection=function(e,t){var n=this,o=this.checkConnection(e,t);if(o&&!this.events.beforeAddConnection.emit({from:e,to:t})){this.connections.filter(function(e){return e.to===o.to}).forEach(function(e){return n.removeConnection(e)});var i=new h(o.from,o.to);return this._connections.push(i),this.events.addConnection.emit(i),i}},e.prototype.removeConnection=function(e){if(this.connections.includes(e)){if(this.events.beforeRemoveConnection.emit(e))return;e.destruct(),this._connections.splice(this.connections.indexOf(e),1),this.events.removeConnection.emit(e)}},e.prototype.checkConnection=function(e,t){if(!e||!t)return!1;if(e.parent===t.parent)return!1;if(e.isInput&&!t.isInput){var n=e;e=t,t=n}return!(e.isInput||!t.isInput)&&(!this.events.checkConnection.emit({from:e,to:t})&&new l(e,t))},e.prototype.load=function(e){for(var t,n,o,i,s=this.connections.length-1;s>=0;s--)this.removeConnection(this.connections[s]);for(s=this.nodes.length-1;s>=0;s--)this.removeNode(this.nodes[s]);try{for(var a=r(e.nodes),u=a.next();!u.done;u=a.next()){var c=u.value,f=this.nodeTypes.get(c.type);if(f){var p=new f;this.addNode(p),p.load(c)}else console.warn("Node type "+c.type+" is not registered")}}catch(e){t={error:e}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}try{for(var d=r(e.connections),h=d.next();!h.done;h=d.next()){var l=h.value,v=this.findNodeInterface(l.from),y=this.findNodeInterface(l.to);v?y?this.addConnection(v,y):console.warn("Could not find interface with id "+l.to):console.warn("Could not find interface with id "+l.from)}}catch(e){o={error:e}}finally{try{h&&!h.done&&(i=d.return)&&i.call(d)}finally{if(o)throw o.error}}this.hooks.load.execute(e)},e.prototype.save=function(){var e={nodes:this.nodes.map(function(e){return e.save()}),connections:this.connections.map(function(e){return{id:e.id,from:e.from.id,to:e.to.id}})};return this.hooks.save.execute(e)},e.prototype.use=function(e){return!this.events.beforeUsePlugin.emit(e)&&(this._plugins.add(e),e.register(this),this.events.usePlugin.emit(e),!0)},e.prototype.findNodeInterface=function(e){var t,n,o,i;try{for(var s=r(this.nodes),a=s.next();!a.done;a=s.next()){var u=a.value;try{for(var c=r(u.interfaces.keys()),f=c.next();!f.done;f=c.next()){var p=f.value;if(u.interfaces.get(p).id===e)return u.interfaces.get(p)}}catch(e){o={error:e}}finally{try{f&&!f.done&&(i=c.return)&&i.call(c)}finally{if(o)throw o.error}}}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e}(),y=function(){function e(e,t){this.events={setConnectionCount:new a,beforeSetValue:new u,setValue:new a},this.hooks={load:new f,save:new f},this._connectionCount=0,this._value=null,this.parent=e,this.isInput=t,this.id="ni_"+d()}return Object.defineProperty(e.prototype,"connectionCount",{get:function(){return this._connectionCount},set:function(e){this._connectionCount=e,this.events.setConnectionCount.emit(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this.events.beforeSetValue.emit(e)||(this._value=e,this.events.setValue.emit(e))},enumerable:!0,configurable:!0}),e.prototype.load=function(e){this.id=e.id,this.value=e.value,this.hooks.load.execute(e)},e.prototype.save=function(){var e={id:this.id,value:this.value};return this.hooks.save.execute(e)},e}(),m=function(){function e(e,t,n){this.events={beforeSetValue:new u,setValue:new a},this.optionComponent=e,this.sidebarComponent=n,this._value=t}return Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this.events.beforeSetValue.emit(e)||(this._value=e,this.events.setValue.emit(e))},enumerable:!0,configurable:!0}),e}(),b=function(){function e(){this.id="node_"+d(),this.interfaces=new Map,this.options=new Map,this.state={},this.events={beforeAddInterface:new u,addInterface:new a,beforeRemoveInterface:new u,removeInterface:new a,beforeAddOption:new u,addOption:new a,beforeRemoveOption:new u,removeOption:new a,update:new a},this.hooks={load:new f,save:new f}}return Object.defineProperty(e.prototype,"inputInterfaces",{get:function(){var e={};return this.interfaces.forEach(function(t,n){t.isInput&&(e[n]=t)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"outputInterfaces",{get:function(){var e={};return this.interfaces.forEach(function(t,n){t.isInput||(e[n]=t)}),e},enumerable:!0,configurable:!0}),e.prototype.load=function(e){var t=this;this.id=e.id,this.name=e.name,this.state=e.state,e.options.forEach(function(e){var n=s(e,2),o=n[0],i=n[1];t.options.has(o)&&(t.options.get(o).value=i)}),e.interfaces.forEach(function(e){var n=s(e,2),o=n[0],i=n[1];t.interfaces.has(o)&&t.interfaces.get(o).load(i)}),this.hooks.load.execute(e)},e.prototype.save=function(){var e={type:this.type,id:this.id,name:this.name,options:Array.from(this.options.entries()).map(function(e){var t=s(e,2);return[t[0],t[1].value]}),state:this.state,interfaces:Array.from(this.interfaces.entries()).map(function(e){var t=s(e,2);return[t[0],t[1].save()]})};return this.hooks.save.execute(e)},e.prototype.calculate=function(){},e.prototype.addInputInterface=function(e,t,n,o){var i=this;if(!this.events.beforeAddInterface.emit({name:e,isInput:!0,option:t,defaultValue:n})){var r=this.addInterface(!0,e,t);return r.events.setValue.addListener(this,function(){return i.events.update.emit({name:e,interface:r})}),r.value=n,Object.entries(o||{}).forEach(function(e){var t=s(e,2),n=t[0],o=t[1];r[n]=o}),this.events.addInterface.emit(r),r}},e.prototype.addOutputInterface=function(e,t){if(!this.events.beforeAddInterface.emit({name:e,isInput:!1})){var n=this.addInterface(!1,e);return Object.entries(t||{}).forEach(function(e){var t=s(e,2),o=t[0],i=t[1];n[o]=i}),this.events.addInterface.emit(n),n}},e.prototype.removeInterface=function(e){var t=this,n=this.getInterface(e);if(n){if(this.events.beforeRemoveInterface.emit(n))return;if(n.connectionCount>0){if(!this.editorInstance)throw new Error("Interface is connected, but no editor instance is specified. Unable to delete interface");this.editorInstance.connections.filter(function(e){return e.from===n||e.to===n}).forEach(function(e){t.editorInstance.removeConnection(e)})}this.interfaces.delete(e),this.events.removeInterface.emit(n)}},e.prototype.addOption=function(e,t,n,o,i){var r=this;if(void 0===n&&(n=null),!this.events.beforeAddOption.emit({name:e,component:t,defaultValue:n,sidebarComponent:o})){var a=new m(t,n,o);return Object.entries(i||{}).forEach(function(e){var t=s(e,2),n=t[0],o=t[1];a[n]=o}),a.events.setValue.addListener(this,function(){r.events.update.emit({name:e,option:a})}),this.options.set(e,a),this.events.addOption.emit({name:e,option:a}),a}},e.prototype.removeOption=function(e){if(this.options.has(e)){var t=this.options.get(e);if(this.events.beforeRemoveOption.emit({name:e,option:t}))return;this.options.delete(e),this.events.removeOption.emit({name:e,option:t})}},e.prototype.getInterface=function(e){if(!this.interfaces.has(e))throw new Error("No interface named '"+e+"'");return this.interfaces.get(e)},e.prototype.getOptionValue=function(e){if(!this.options.has(e))throw new Error("No option named '"+e+"'");return this.options.get(e).value},e.prototype.setOptionValue=function(e,t){if(!this.options.has(e))throw new Error("No option named '"+e+"'");this.options.get(e).value=t},e.prototype.registerEditor=function(e){this.editorInstance=e},e.prototype.addInterface=function(e,t,n){var o=new y(this,e);return o.option=n,this.interfaces.set(t,o),o},e}();function w(e){return"function"==typeof e?e():e}var g=function(){function e(e){this.type="",this.name="",this.intfs=[],this.options=new Map,this.type=e,this.name=e}return e.prototype.build=function(){return e=this.type,t=this.name,n=this.intfs,o=this.options,a=this.calcFunction,function(u){function c(){var i,a,c=u.call(this)||this;c.type=e,c.name=t;try{for(var f=r(n),p=f.next();!p.done;p=f.next()){var d=p.value;d.isInput?c.addInputInterface(d.name,d.option,w(d.defaultValue),d.additionalProperties):c.addOutputInterface(d.name,d.additionalProperties)}}catch(e){i={error:e}}finally{try{p&&!p.done&&(a=f.return)&&a.call(f)}finally{if(i)throw i.error}}return Array.from(o.entries()).forEach(function(e){var t=s(e,2),n=t[0],o=t[1];c.addOption(n,o.optionComponent,w(o.value),o.sidebarComponent,o.additionalProperties)}),c}return i(c,u),c.prototype.calculate=function(){if(a)return a.call(this,this)},c}(b);var e,t,n,o,a},e.prototype.setName=function(e){return this.name=e,this},e.prototype.addInputInterface=function(e,t,n,o){return this.checkDefaultValue(n),this.intfs.push({isInput:!0,name:e,option:t,defaultValue:n,additionalProperties:o}),this},e.prototype.addOutputInterface=function(e,t){return this.intfs.push({isInput:!1,name:e,additionalProperties:t}),this},e.prototype.addOption=function(e,t,n,o,i){return this.checkDefaultValue(n),this.options.set(e,{value:n,optionComponent:t,sidebarComponent:o,additionalProperties:i}),this},e.prototype.onCalculate=function(e){return this.calcFunction=e,this},e.prototype.checkDefaultValue=function(e){if("object"==typeof e)throw new Error("If the default value is an object, provide a generator function instead of the object")},e}();n.d(t,"BaklavaEvent",function(){return a}),n.d(t,"PreventableBaklavaEvent",function(){return u}),n.d(t,"Hook",function(){return c}),n.d(t,"SequentialHook",function(){return f}),n.d(t,"Connection",function(){return h}),n.d(t,"DummyConnection",function(){return l}),n.d(t,"Editor",function(){return v}),n.d(t,"Node",function(){return b}),n.d(t,"NodeBuilder",function(){return g}),n.d(t,"NodeInterface",function(){return y}),n.d(t,"NodeOption",function(){return m})}])});
{
"name": "@baklavajs/core",
"version": "1.0.8",
"version": "1.1.0",
"description": "Core logic of BaklavaJS",

@@ -42,3 +42,3 @@ "author": "newcat <freddy.wagner@web.de>",

},
"gitHead": "b48cd421883a80c3fe30e6b7eedf0f239f7ce97a"
"gitHead": "296bc88bd2436f7ef47a59a02bbeeb8c53653b33"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc