UNPKG

flownote

Version:

FlowNote lets developers create, organize, and reason about event-oriented applications with a simple flow-based language.

1 lines 17.6 kB
(window.webpackJsonpFlowNote=window.webpackJsonpFlowNote||[]).push([[0],{136:function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(n,e,t){const i=new o.default(n);return{Expression:i.Expression,FlowTypes:i.FlowTypes,NodeTypes:i.NodeTypes,PathTypes:i.PathTypes,FlowDefinition:(n,e,t,o,r,s,a,l,c,d)=>i.FlowDefinition(e,o,s,l,d),NodeDefinition:(n,e,t,o,r)=>i.NodeDefinition(e,t,r),Actions:n=>i.Actions(n),Path:(n,e,t)=>i.Path(n,e,t),NonemptyListOf:(n,e,t)=>i.NonemptyListOf(n,e,t),EmptyListOf:()=>[],Import:(n,t,o,r)=>i.Import(t,e,r),Nodes:n=>i.Nodes(n),Milestone:(n,e)=>i.Milestone(n),Node:n=>i.Node(n),WaitFor:(n,e,t)=>i.WaitFor(n,t),NodeBase:n=>i.NodeBase(n),SilentNode:(n,e)=>i.SilentNode(n),IdentityNode:(n,e,t)=>i.IdentityNode(n,t),StandardNode:n=>i.StandardNode(n),Channel:n=>i.Channel(n),ErrorChannel:(n,e,t,o)=>i.ErrorChannel(e,t),PlainChannel:(n,e,t)=>i.PlainChannel(e),NamedChannel:(n,e,t,o)=>i.NamedChannel(e,t),Properties:(n,e,t)=>i.Properties(e),Property:(n,e,t)=>i.Property(n,t),HttpMethods:n=>i.HttpMethods(n),Axiom:n=>i.Axiom(n,t),label:n=>i.label(n),string:(n,e,t)=>i.string(e),_terminal:()=>this.primitiveValue,alnum:n=>n.sourceString,digit:n=>n.sourceString,number:n=>i.number(n),fraction:(n,e,t)=>i.fraction(n,e,t),whole:n=>i.whole(n),space:n=>i.space(n),comment:n=>i.comment(n),multiLineComment:(n,e,t)=>i.multiLineComment(e),singleLineComment:(n,e)=>i.singleLineComment(n,e)}};var i,o=(i=t(138))&&i.__esModule?i:{default:i}},137:function(n,e,t){"use strict";var i,o=(i=t(138))&&i.__esModule?i:{default:i};n.exports=function(n,e){const t=new o.default(n);return{Expression:t.Expression,FlowTypes:t.FlowTypes,NodeTypes:t.NodeTypes,PathTypes:t.PathTypes,LinguisticFlowDefinition:(n,e,i,o,r,s,a,l,c,d,u)=>t.FlowDefinition(n,o,s,l,u),LinguisticNodeDefinition:(n,e,i,o)=>t.NodeDefinition(n,{},o),LinguisticActionsPlural:(n,e,t)=>{},LinguisticActionsSingular:n=>{},LinguisticActions:n=>{},NonemptyListOf:t.NonemptyListOf,LinguisticPath:t.Path,LinguisticPathSeparator:(n,e)=>e.eval(),Import:(n,e,i,o,r)=>t.Import(i,r),LinguisticNodes:t.Nodes,LinguisticMilestone:t.Milestone,LinguisticNode:t.Node,LinguisticWaitsFor:(n,e,i)=>t.WaitsFor(n,i),LinguisticNodeBase:t.NodeBase,LinguisticSilentNode:(n,e)=>t.SilentNode(e),LinguisticIdentityNode:(n,e,i,o)=>t.IdentityNode(n,i),LinguisticStandardNode:t.StandardNode,Concept:t.Concept,LinguisticChannel:t.Channel,LinguisticErrorChannel:(n,e,i,o)=>t.ErrorChannel(e,i),LinguisticPlainChannel:(n,e,i)=>t.PlainChannel(e),LinguisticNamedChannel:(n,e,i,o)=>t.NamedChannel(e,i),Properties:(n,e,i)=>t.Properties(e),Property:(n,e,i)=>t.Property(n,i),HttpMethods:t.HttpMethods,label:t.label,string:(n,e,i)=>t.string(e),_terminal:()=>this.primitiveValue,number:t.number,fraction:t.fraction,whole:t.whole,space:t.space,comment:t.comment,multiLineComment:t.multiLineComment,singleLineComment:t.singleLineComment}}},138:function(n,e,t){"use strict";(function(n){Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var i=d(t(7)),o=d(t(27)),r=d(t(41)),s=d(t(141)),a=d(t(39)),l=d(t(40)),c=d(t(13));function d(n){return n&&n.__esModule?n:{default:n}}const u=t(28),p=t(142);e.default=class{constructor(n){this.application=n,this.nodeFactories={},this.nodeAliases={}}getNodeInstance(n){const e=this.nodeFactories[n]||{tags:[],actions:[]};return new a.default(this.application,void 0,n,void 0,e.tags,e.actions)}FlowTypes(n){return n.eval()}NodeTypes(n){return n.eval()}PathTypes(n){return n.eval()}Expression(n){return n.eval()}FlowDefinition(n,e,t,i,o){const r=e.eval(),s="/"+t.eval().join("/");if(this.application.getFlowByHttp(r,s))throw new Error(`Flow definition already exists for the ${r} ${s} endpoint.`);const l=new c.default(this.application,void 0,n.eval(),i.eval(),void 0,r,s,void 0),d=o.eval(),u=d[0];let p=d[0];for(var f=1,h=d.length;f<h;f++){const n=d[f];if(void 0!==n){if(p instanceof a.default){const n=p.hasMilestone();n&&(p=n)}p.connect(n),p=n}}l.connect(u),this.application.registerFlow(l)}NodeDefinition(n,e,t){const i=n.eval();if(this.nodeAliases[i])return this.nodeAliases[i];if(void 0!==this.nodeFactories[i])throw new Error(`Node definition already exists for the ${i}.`);this.nodeFactories[i]={tags:[],config:e.eval(),actions:t.eval()}}Actions(n){const e=n.eval(),t=[];return e.forEach(n=>{if(void 0!==n){const e=this.application.requireAction(n,new Function("return function () {\n // @TODO Fill out this stub\n }")());t.push(e)}}),t}Path(n,e,t){const i=n.eval(),o=e.eval(),r=t.eval();let s=o;return r.forEach(n=>{if(void 0!==n){if(s instanceof a.default){const n=s.hasMilestone();n&&(s=n)}s.connect(n),s=n}}),i.connect(o),i}NonemptyListOf(n,e,t){const i=n.eval(),o=n.ctorName;if(void 0===i)return[];if("Nodes"===o){const n=e.eval(),o=t.eval(),a=[i];for(var r=0,s=n.length;r<s;r++)a.push(n[r]),a.push(o[r]);return a}if("Property"===o)return i.concat(t.eval());if("label"===o||"Axiom"===o)return[i].concat(t.eval());throw new Error("Unknown ctorName: "+o)}Import(e,i,o){const r=e.eval();if(r.indexOf("//")>-1);else{const e=r.substr(r.lastIndexOf(".")+1).toLowerCase();if("js"===e||"mjs"===e){let e=t(143)(`${n.cwd()}/${r}`);e.default&&(e=e.default);const i=o.eval()[0];if(!i)throw new Error(`Importing ${r} requires a namespace`);this.application.actionGenerators.push(e.toString()),e.call(this.application,t(140)).forEach(n=>{this.application.registerAction(`${i}.${n.name}`,n)})}else if("flow"===e){const e=o.eval()[0];if(!e)throw new Error(`Importing ${r} requires a namespace`);const t=u.readFileSync(`${n.cwd()}/${r}`).toString();i.compile(t,e)}else{const e=t(147)(`${n.cwd()}/node_modules/${r}/package.json`).main||"index.js";let o=t(148)(`${n.cwd()}/node_modules/${r}/${e}`);o.default&&(o=o.default),this.application.actionGenerators.push(o.toString()),o.call(this.application,t(140)).forEach(n=>{this.application.registerAction(`${r}.${n.name}`,n)});const s=p.dirName(`${n.cwd()}/node_modules/${r}/${e}`),a=u.readFileSync(`${s}/index.flow`).toString();i.compile(a,r)}}}Nodes(n){return n.eval()}LinguisticNodes(n){return n.eval()}Milestone(n){const e=n.eval(),t=new o.default(this.application,void 0,"Plain",void 0,[]),i=new l.default(this.application,void 0,"Milestone","fcfs",[],[]);return i.config.silent=e.config.silent,e.connect(t),t.connect(i),e}LinguisticMilestone(n){return new l.default(this.application,void 0,"Milestone","fcfs",[],[])}Node(n){return n.eval()}WaitFor(n,e){const t=n.eval(),o=e.eval(),r=new i.default(`waitFor${o}`,async function(){await this.waitFor(o)},this.application);return t.addAction(r,t.actions.length-1),t}NodeBase(n){return n.eval()}SilentNode(n){const e=n.eval();if(this.nodeAliases[e.name])throw new Error("Cannot modify labeled a Path root.");return e.config.silent=!0,e}IdentityNode(n,e){const t=n.eval(),i=e.eval();return this.nodeAliases[i]||(this.nodeAliases[i]=t),this.nodeAliases[i]}StandardNode(n){const e=n.eval();return this.nodeAliases[e]?this.nodeAliases[e]:this.getNodeInstance(e)}Concept(n){const e=[];return n.forEach(n=>{void 0!==n&&e.push(n.eval())}),e.join(" ")}Channel(n){return n.eval()}ErrorChannel(n,e){const t=n.eval(),i=e.eval();return new r.default(this.application,void 0,t,void 0,[t],i.retry,i.retryDelay,[])}PlainChannel(n){const e=n.eval();return new o.default(this.application,void 0,"Plain",void 0,[],e.retry,e.retryDelay,[])}NamedChannel(n,e){const t=n.eval(),i=e.eval();return new s.default(this.application,void 0,t,void 0,[t],i.retry,i.retryDelay,[])}Properties(n){const e={};return n.eval().forEach(n=>{void 0!==n&&(e[n[0]]=n[1])}),e}Property(n,e){return[n.eval(),e.eval()]}HttpMethods(n){return n.eval()}Axiom(n,e){return e?`${e}.${n.eval().join(".")}`:n.eval().join(".")}label(n){return n.eval().join("")}string(n){return n.sourceString}number(n){return n.eval()}fraction(n,e,t){const i=n.eval(),o="0."+t.eval();return Number(i)+Number(o)}whole(n){return Number(n.eval())}space(n){return n.eval()}comment(n){return n.eval()}multiLineComment(n){return n.eval()}singleLineComment(n,e){return e.eval()}}}).call(this,t(6))},139:function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;e.default=function(n){const{Action:e}=n("../src/index");return[new e("extractClickData",function(){this.set("click",this.get("click"))}),new e("extractPlayerId",function(){this.set("playerId",this.get("playerId"))}),new e("getXYCoordsFromClickData",function(){this.set("clickX",this.get("click").x),this.set("clickY",this.get("click").y),this.dispatch("Coordinates")}),new e("getPlayerById",function(){this.set("player",{id:this.get("playerId"),name:"Alice",x:10,y:12})}),new e("detectPlayerMovementEvents",function(){(this.get("events")||[]).forEach(n=>{"move"===n.type&&this.set("pendingMove",n)})}),new e("movePlayer",function(){const n=this.get("player");n.x+=this.get("clickX"),n.y+=this.get("clickY")}),new e("dispatchPlayerMovementEvents",function(){this.dispatch("playerMoved")}),new e("sendBoundaryError",function(){this.dispatch("BoundaryError")}),new e("getBroadcastMessage",function(){this.set("broadcastMessage","Player Moved")}),new e("getRoomByPlayerId",function(){this.set("broadcastRoomId",1)}),new e("broadcastToRoom",function(){this.dispatch(`broadcast:${this.get("broadcastRoomId")}`,this.get("broadcastMessage"))})]}},140:function(n,e){function t(n){var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}t.keys=function(){return[]},t.resolve=t,n.exports=t,t.id=140},141:function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var i,o=(i=t(3))&&i.__esModule?i:{default:i};e.default=class extends o.default{constructor(n,e,t,i,o=[],r,s,a=[]){const l=n.requireAction("gotoNodeFromNamedChannel",function(){this.dispatch("StandardNode")});super(n,e,t,i,o,r,s,a.concat([l]))}}},142:function(n,e,t){(function(n){function t(n,e){for(var t=0,i=n.length-1;i>=0;i--){var o=n[i];"."===o?n.splice(i,1):".."===o?(n.splice(i,1),t++):t&&(n.splice(i,1),t--)}if(e)for(;t--;t)n.unshift("..");return n}var i=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,o=function(n){return i.exec(n).slice(1)};function r(n,e){if(n.filter)return n.filter(e);for(var t=[],i=0;i<n.length;i++)e(n[i],i,n)&&t.push(n[i]);return t}e.resolve=function(){for(var e="",i=!1,o=arguments.length-1;o>=-1&&!i;o--){var s=o>=0?arguments[o]:n.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(e=s+"/"+e,i="/"===s.charAt(0))}return(i?"/":"")+(e=t(r(e.split("/"),function(n){return!!n}),!i).join("/"))||"."},e.normalize=function(n){var i=e.isAbsolute(n),o="/"===s(n,-1);return(n=t(r(n.split("/"),function(n){return!!n}),!i).join("/"))||i||(n="."),n&&o&&(n+="/"),(i?"/":"")+n},e.isAbsolute=function(n){return"/"===n.charAt(0)},e.join=function(){var n=Array.prototype.slice.call(arguments,0);return e.normalize(r(n,function(n,e){if("string"!=typeof n)throw new TypeError("Arguments to path.join must be strings");return n}).join("/"))},e.relative=function(n,t){function i(n){for(var e=0;e<n.length&&""===n[e];e++);for(var t=n.length-1;t>=0&&""===n[t];t--);return e>t?[]:n.slice(e,t-e+1)}n=e.resolve(n).substr(1),t=e.resolve(t).substr(1);for(var o=i(n.split("/")),r=i(t.split("/")),s=Math.min(o.length,r.length),a=s,l=0;l<s;l++)if(o[l]!==r[l]){a=l;break}var c=[];for(l=a;l<o.length;l++)c.push("..");return(c=c.concat(r.slice(a))).join("/")},e.sep="/",e.delimiter=":",e.dirname=function(n){var e=o(n),t=e[0],i=e[1];return t||i?(i&&(i=i.substr(0,i.length-1)),t+i):"."},e.basename=function(n,e){var t=o(n)[2];return e&&t.substr(-1*e.length)===e&&(t=t.substr(0,t.length-e.length)),t},e.extname=function(n){return o(n)[3]};var s="b"==="ab".substr(-1)?function(n,e,t){return n.substr(e,t)}:function(n,e,t){return e<0&&(e=n.length+e),n.substr(e,t)}}).call(this,t(6))},143:function(n,e,t){var i={"./":26,"./default-semantics":136,"./default-semantics.js":136,"./default.ohm":144,"./english-semantics":137,"./english-semantics.js":137,"./english.ohm":145,"./generator":138,"./generator.js":138,"./index":26,"./index.js":26,"./semantics":38,"./semantics.js":38,"./test.flow":146,"./testActions":139,"./testActions.js":139};function o(n){var e=r(n);return t(e)}function r(n){if(!t.o(i,n)){var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}return i[n]}o.keys=function(){return Object.keys(i)},o.resolve=r,n.exports=o,o.id=143},144:function(n,e,t){"use strict";t.r(e),e.default='FlowNote {\n Expression\n = NodeTypes\n | FlowTypes\n | Import \n | PathTypes\n | comment\n | EmptyListOf<Nodes, Channel>\n\n FlowTypes\n = FlowDefinition\n NodeTypes\n = NodeDefinition\n PathTypes\n = Path\n\n FlowDefinition = "flow" Axiom "(" HttpMethods "/" ListOf<label, "/"> ")" Properties? "=" NonemptyListOf<Nodes, Channel>\n\n NodeDefinition = "node" Axiom Properties? "=" Actions\n\n Actions = ListOf<Axiom, ",">\n\n Path = StandardNode Channel NonemptyListOf<Nodes, Channel>\n\n Import = "import" string ("as" Axiom)?\n\n Nodes\n = WaitFor\n | Node\n\n WaitFor = Node "..." Axiom\n\n Node\n = IdentityNode\n | NodeBase\n\n IdentityNode = NodeBase "#" Axiom\n\n NodeBase\n = Milestone\n | SilentNode\n | StandardNode\n\n Milestone \n = StandardNode "*"\n | SilentNode "*"\n\n SilentNode = StandardNode "$"\n\n StandardNode = Axiom\n \n Channel\n = ErrorChannel\n | NamedChannel\n | PlainChannel\n\n ErrorChannel = "-" label Properties? "!"\n NamedChannel = "-" label Properties? ">"\n PlainChannel = "-" Properties? ">"\n\n Properties = "{" ListOf<Property, ","> "}"\n Property = label ":" Axiom\n\n HttpMethods\n = "GET"\n | "POST"\n | "PUT"\n | "DELETE"\n | "OPTIONS"\n | "HEAD"\n\n Axiom = NonemptyListOf<label, ".">\n label = alnum+\n string (a string literal) = "\\"" (~"\\"" ~"\\n" any)* "\\""\n number (a number literal)\n = fraction\n | whole\n fraction = digit* "." digit+\n whole = digit+\n space += comment\n comment\n = multiLineComment\n | singleLineComment\n multiLineComment = "/*" (~"*/" any)* "*/"\n singleLineComment = "//" (~"\\n" any)*\n}\n'},145:function(n,e,t){"use strict";t.r(e),e.default='FlowNote {\n Expression\n = NodeTypes\n | FlowTypes\n | PathTypes\n | Import\n | EmptyListOf<Nodes, Channel>\n\n FlowTypes\n = LinguisticFlowDefinition\n NodeTypes\n = LinguisticNodeDefinition\n PathTypes\n = LinguisticPath\n\n LinguisticFlowDefinition = Concept "Flow" "(" HttpMethods "/" ListOf<label, "/"> ")" Properties? "is" NonemptyListOf<LinguisticNodes, LinguisticPathSeparator>\n\n LinguisticNodeDefinition = Concept "Node" "is" LinguisticActions\n\n LinguisticActionsPlural = ListOf<Concept, ","> "and" Concept\n LinguisticActionsSingular = Concept\n LinguisticActions\n = LinguisticActionsPlural\n | LinguisticActionsSingular\n\n LinguisticPath = LinguisticStandardNode LinguisticChannel NonemptyListOf<LinguisticNodes, LinguisticPathSeparator>\n\n LinguisticPathSeparator = "that" LinguisticChannel\n\n Import = "import" "\\"" label "."? label? "\\""\n\n LinguisticNodes\n = LinguisticMilestone\n | LinguisticNode\n\n LinguisticMilestone = LinguisticNode "then commits"\n\n LinguisticNode\n = LinguisticWaitFor\n | LinguisticNodeBase\n\n LinguisticWaitFor = LinguisticNodeBase "but waits for" LinguisticStandardNode\n\n LinguisticNodeBase\n = LinguisticSilentNode\n | LinguisticIdentityNode\n | LinguisticStandardNode\n LinguisticSilentNode = "a silent" LinguisticStandardNode\n LinguisticIdentityNode = LinguisticStandardNode "(as" Concept ")"\n LinguisticStandardNode = Concept\n\n Concept = NonemptyListOf<label, space>\n\n LinguisticChannel\n = LinguisticErrorChannel\n | LinguisticPlainChannel\n | LinguisticNamedChannel\n\n LinguisticErrorChannel = "errors with" Concept Properties? "to"\n LinguisticPlainChannel = "connects" Properties? "to"\n LinguisticNamedChannel = "connects with" Concept Properties? "to"\n\n Properties = "{" ListOf<Property, ","> "}"\n Property = label ":" label\n\n HttpMethods\n = "GET"\n | "POST"\n | "PUT"\n | "DELETE"\n | "OPTIONS"\n | "HEAD"\n\n label = (alnum|"_")+\n string (a string literal) = "\\"" (~"\\"" ~"\\n" any)* "\\""\n number (a number literal)\n = fraction\n | whole\n fraction = digit* "." digit+\n whole = digit+\n space += comment\n comment\n = multiLineComment\n | singleLineComment\n multiLineComment = "/*" (~"*/" any)* "*/"\n singleLineComment = "//" (~"\\n" any)*\n}\n'},146:function(n,e,t){"use strict";t.r(e),e.default='import "compiler/testActions.js" as FlowNote\n\nnode getClick = FlowNote.extractClickData, FlowNote.extractPlayerId\nnode extractXY = FlowNote.getXYCoordsFromClickData\nnode movePlayer = FlowNote.getPlayerById, FlowNote.detectPlayerMovementEvents, FlowNote.movePlayer, FlowNote.dispatchPlayerMovementEvents\nnode displayBoundaryError = FlowNote.getPlayerById, FlowNote.sendBoundaryError\nnode notifyRoom = FlowNote.getBroadcastMessage, FlowNote.getRoomByPlayerId, FlowNote.broadcastToRoom\n\nflow click(GET /click) = getClick$ -> extractXY#clickBranch\n\nclickBranch -Coordinates{ retry: 3 }> movePlayer*#move\n\nclickBranch -BoundaryError! displayBoundaryError\n\nclickBranch -> notifyRoom ... move\n'},147:function(n,e){function t(n){var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}t.keys=function(){return[]},t.resolve=t,n.exports=t,t.id=147},148:function(n,e){function t(n){var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}t.keys=function(){return[]},t.resolve=t,n.exports=t,t.id=148}}]);