UNPKG

flume-js

Version:

a library for defining applications as a set of inputs and transformations

2 lines 6.57 kB
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["flume-js"]=t():n["flume-js"]=t()}(this,(function(){return function(n){var t={};function r(e){if(t[e])return t[e].exports;var u=t[e]={i:e,l:!1,exports:{}};return n[e].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var u in n)r.d(e,u,function(t){return n[t]}.bind(null,u));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p="",r(r.s=2)}([function(n,t){var r=u("flume:nil",null),e=Object.prototype.hasOwnProperty;function u(n,t){return new i(n,t)}function o(n){return{transform:d({"*":p},n)}}function i(n,t){this.type=n,this.value=t}function f(){this.defType="input"}function c(n){var t,r;this.defType="transform",this.init=(t=n.init,r=y,void 0===t?r:t),this.transform=n.transform}function a(n,t,r,e){var u;this.graph=n,this.def=t,this.child=r,this.index=e,this.handle={input:h,transform:v}[(u=this).def.defType](u)}function s(n,t,r,e){var u=t.length-1;if(u<0)return[];for(u&&(r=new a(n,l(t[u]),r,e));--u>0;)r=new a(n,l(t[u]),r,0);return function(n,t,r){e=t,t=Array.isArray(e)?e:[e];var e;var u,o=[],i=-1,c=t.length;for(;++i<c;)if(u=t[i],Array.isArray(u))o.push.apply(o,s(n,u,r,i));else{if(!(u instanceof f))throw new Error("Expected input or array but got "+x(u));o.push(new a(n,u,r,i))}return o}(n,t[0],r)}function l(n){if("function"==typeof n)n={transform:{"flume:value":n}};else if("function"==typeof(n||0).transform)n=d(n,{transform:{"flume:value":n.transform}});else if("object"!==x((n||0).transform))throw new Error("Expected function or object matching transform shape but got "+x(n));return new c(n)}function p(n,t){return{state:t}}function h(n){return function(t,r){n.child.handle([t],n,n,r)}}function v(n){var t=[],r=!1,o=null,i=n.def.init(),f=w((function(){var t=n.def.transform,r=t[o.msg.type]||t["*"];return r?r(i,o.msg.value,{source:o.source.def,parent:o.parent.def,dispatch:n.graph.dispatch}):{value:o.msg}}));return function(n,t,r,e){for(var u=-1,o=(n=n.map(b)).length-1,i={source:r,parent:t};++u<o;)c(d(i,{msg:n[u],end:y}));o>-1&&c(d(i,{msg:n[o],end:e}))};function c(n){t.push(n),r||a()}function a(){(o=t.shift())&&(r=!0,f().then(P).then(l,p))}function s(t){var e=o;r=!1,o=null,n.child?n.child.handle(t,n,e.source,e.end):e.end(),a()}function l(n){n=function(n,t){var r,u=e.call(t,"state");e.call(t,"value")?r=[t.value]:e.call(t,"values")?r=t.values:u&&(r=[t.state]);return{values:r,state:u?t.state:n}}(i,n),i=n.state,s(n.values)}function p(t){if(!n.child)throw new _(t);s([u("flume:error",t)])}}function d(){for(var n,t={},r=Array.prototype.slice.call(arguments),u=-1,o=r.length;++u<o;)for(var i in n=r[u])e.call(n,i)&&(t[i]=n[i]);return t}function y(){return null}function m(n){return n}function g(n){throw n}function b(n){return n instanceof i?n:u("flume:value",n)}function x(n){return null!==n?typeof n:"null"}function w(n){return function(){try{var t=n.apply(this,arguments);return j(t)}catch(n){if(n instanceof _)throw n.error;return O(n)}}}function j(n){return S(n)?n:A(n)}function A(n){return new E(n,!1)}function O(n){return new E(n,!0)}function P(n){return Array.isArray(n)&&n.filter(S).length>0?function(n){var t=[],r=n.length,e=-1,u=-1,o=A(null);for(;++e<r;)o=o.then(i);return o.then((function(){return t}));function i(){return j(n[++u]).then(f)}function f(n){t.push(n)}}(n):j(n)}function S(n){return!!(n||0).then}function _(n){this.error=n}function E(n,t){this.value=n,this.isFailure=t}E.prototype.then=w((function(n,t){return this.isFailure?(t||g).call(this,this.value):(n||m).call(this,this.value)})),n.exports={create:function(n){var t={dispatch:function(n,r,e){var u=function(n,t){var r,e=[],u=n.length,o=-1;for(;++o<u;)(r=n[o]).def===t&&e.push(r);return e}(t.inputs,n),o=u.length,i=-1;e=function(n,t){var r=0;return function(){++r>=n&&t.apply(null,arguments)}}(o,e||y);for(;++i<o;)u[i].handle(r,e);return t}};return t.inputs=s(t,n),t},input:function(){return new f},message:u,trap:o,except:function(n){return o({"flume:error":n})},nil:r,conj:d,maybeAsync:w,resolveSeq:P}},function(n,t){n.exports=function(n){return{value:n}}},function(n,t,r){var e=r(0);n.exports=e.conj(e,{map:r(3),reduce:r(4),filter:r(6),sink:r(8),strsplit:r(9),bindInputs:r(10)})},function(n,t,r){var e=r(0).maybeAsync,u=r(1);n.exports=function(n){return n=e(n),function(t,r,e){return n(r,e).then(u)}}},function(n,t,r){var e=r(0).maybeAsync,u=r(5);function o(n){if("function"==typeof n)return n;if(Array.isArray(n))return function(n){var t=f;"function"==typeof n[n.length-1]&&(t=n[n.length-1],n=n.slice(0,-1));return function(r,e,u){for(var o,i=u.source,f=-1,c=n.length;++f<c;)if((o=n[f])[0]===i)return o[1](r,e,u);return t(r,e,u)}}(n);throw new Error("Unsupported reducer type given to reduce(): "+typeof n)}function i(){return null}function f(n,t){return t}n.exports=function(n,t){return arguments.length<2&&(t=n,n=i),t=e(o(t)),{init:n,transform:r};function r(n,r,e){return t(n,r,e).then(u)}}},function(n,t){n.exports=function(n){return{state:n}}},function(n,t,r){var e=r(0),u=e.nil,o=e.resolveSeq,i=r(7),f=r(1);function c(n){return n[0]?n[1]:u}n.exports=function(n){return n=n||i,function(t,r,e){return o([n(r,e),r]).then(c).then(f)}}},function(n,t){n.exports=function(n){return n}},function(n,t,r){var e=r(0).maybeAsync,u=r(1);n.exports=function(n,t){return t=e(t),{init:n,transform:function(n,r,e){return t(n,r,e).then(u)}}}},function(n,t){function r(){return""}n.exports=function(n){return{init:r,transform:function(t,r){var e=(t+r).split(n);return{state:e.slice(-1),values:e.slice(0,-1)}}}}},function(n,t,r){var e=r(0).conj,u=Object.prototype.hasOwnProperty;n.exports=function(n,t){return arguments.length<2&&(t=n,n=e),function(e,u,o){return{state:e=e||r(t,o.dispatch),value:n(u,e)}};function r(n,t){var r={};for(var e in n)u.call(n,e)&&(r[e]=o(n[e],t));return r}function o(n,t){return function(r){t(n,r)}}}}])})); //# sourceMappingURL=flume-js.js.map