UNPKG

@hotmeshio/hotmesh

Version:

Serverless Workflow

1 lines 10 kB
'use strict';const A=b;(function(c,d){const z=b,e=c();while(!![]){try{const f=-parseInt(z(0x16a))/0x1*(-parseInt(z(0x118))/0x2)+-parseInt(z(0x111))/0x3*(-parseInt(z(0x142))/0x4)+-parseInt(z(0x17d))/0x5+-parseInt(z(0x143))/0x6*(-parseInt(z(0x159))/0x7)+parseInt(z(0x175))/0x8+parseInt(z(0x17b))/0x9+-parseInt(z(0x129))/0xa;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x28e63));Object[A(0x10e)](exports,'__esModule',{'value':!0x0}),exports[A(0x13f)]=void 0x0;const enums_1=require('../../modules/enums'),key_1=require('../../modules/key'),utils_1=require(A(0x164)),telemetry_1=require('../telemetry'),stream_1=require('../../types/stream');function b(c,d){const e=a();return b=function(f,g){f=f-0x10d;let h=e[f];return h;},b(c,d);}class Router{constructor(c,d,f){const B=A;this[B(0x123)]=0x0,this[B(0x114)]=0x0,this[B(0x134)]={},this['currentTimerId']=null,this[B(0x158)]=null,this[B(0x11e)]=null,this[B(0x154)]=!0x1,this[B(0x124)]=null,this[B(0x12e)]=c[B(0x12e)],this[B(0x116)]=c[B(0x116)],this[B(0x14b)]=c[B(0x14b)],this['topic']=c[B(0x136)],this[B(0x119)]=d,this[B(0x123)]=c[B(0x123)],this['reclaimDelay']=c[B(0x127)]||enums_1[B(0x150)],this[B(0x168)]=c[B(0x168)]||enums_1[B(0x163)],this[B(0x16f)]=f,this[B(0x13d)]=c['readonly']||!0x1,this['resetThrottleState']();}[A(0x120)](){const C=A;this['sleepPromiseResolve']=null,this['innerPromiseResolve']=null,this[C(0x154)]=!0x1,this[C(0x124)]=null;}async[A(0x13a)](c,d){const D=A;try{await this[D(0x119)][D(0x16d)](c,d);}catch(f){this[D(0x16f)][D(0x11b)](D(0x14a),{'stream':c,'group':d});}}async[A(0x165)](c,d,f){const E=A,g=d?.[E(0x170)]||E(0x162);this['counts'][g]=(this[E(0x134)][g]||0x0)+0x1;const h=this['stream']['mintKey'](key_1[E(0x15e)][E(0x15c)],{'topic':c});return(await this['stream'][E(0x155)](h,[JSON['stringify'](d)],{'transaction':f}))[0x0];}async['customSleep'](){const F=A;if(0x0===this[F(0x123)])return;if(this['isSleeping'])return;this[F(0x154)]=!0x0;const c=Date['now']();await new Promise(async d=>{const H=F;this['sleepPromiseResolve']=d;let f=Date['now']()-c;for(;f<this['throttle'];)await new Promise(g=>{const G=b;this['innerPromiseResolve']=g,this[G(0x124)]=setTimeout(g,this[G(0x123)]-f);}),f=Date[H(0x133)]()-c;this[H(0x120)](),d();});}async[A(0x137)](c,d,f,g){const I=A;if(this[I(0x13d)])return void this[I(0x16f)][I(0x13c)](I(0x126),{'group':d,'consumer':f,'stream':c});this['logger'][I(0x13c)](I(0x14d),{'group':d,'consumer':f,'stream':c}),Router[I(0x11c)][I(0x178)](this),this[I(0x10d)]=!0x0,await this[I(0x13a)](c,d);let h=Date[I(0x133)]();void 0x0===this[I(0x141)]&&(this[I(0x141)]=!0x1);const j=async()=>{const J=I;if(await this[J(0x157)](),this[J(0x14f)](d,f,c))return;if(this['isPaused']())return void setImmediate(j['bind'](this));const k=enums_1['HMSH_BLOCK_TIME_MS']+Math[J(0x12b)](enums_1[J(0x117)]*Math[J(0x169)]());try{let m=[];if(m=this[J(0x141)]?await this[J(0x119)][J(0x137)](c,d,f,{'blockTimeout':k,'enableBackoff':!0x1,'maxRetries':0x1}):await this[J(0x119)][J(0x137)](c,d,f,{'blockTimeout':k,'enableBackoff':!0x0,'initialBackoff':enums_1['INITIAL_STREAM_BACKOFF'],'maxBackoff':enums_1['MAX_STREAM_BACKOFF'],'maxRetries':enums_1['MAX_STREAM_RETRIES']}),this[J(0x14f)](d,f,c))return;if(this[J(0x14e)]())return void setImmediate(j[J(0x140)](this));if(m[J(0x15a)]>0x0){this['hasReachedMaxBackoff']=!0x1;for(const q of m)await this[J(0x122)](c,d,q['id'],q[J(0x16b)],g);const p=Date['now']();if(this[J(0x119)]['getProviderSpecificFeatures']()['supportsRetry']&&p-h>this['reclaimDelay']){h=p;const v=await this[J(0x119)][J(0x121)](c,d,{'consumerName':f,'minIdleTime':this[J(0x127)],'limit':enums_1[J(0x11a)]});for(const w of v)await this[J(0x122)](c,d,w['id'],w[J(0x16b)],g);}setImmediate(j[J(0x140)](this));}else this[J(0x141)]?await(l=enums_1[J(0x179)],new Promise(x=>setTimeout(x,l))):this['hasReachedMaxBackoff']=!0x0,setImmediate(j[J(0x140)](this));}catch(x){if(this[J(0x10d)]&&J(0x172)!==process['env']['NODE_ENV']){this[J(0x16f)]['error'](J(0x17c),{'error':x,'stream':c,'group':d,'consumer':f}),this[J(0x114)]++;const y=Math[J(0x167)](enums_1[J(0x138)]*0x2**this[J(0x114)],enums_1[J(0x160)]);setTimeout(j[J(0x140)](this),y);}}var l;};j['call'](this);}[A(0x161)](c){const K=A;return Array[K(0x15b)](c)&&Array['isArray'](c[0x0]);}[A(0x14e)](){const L=A;return this[L(0x123)]===enums_1['MAX_DELAY'];}[A(0x14f)](c,d,f){const M=A;return this[M(0x10d)]||this[M(0x16f)][M(0x13c)]('router-stream-stopped',{'group':c,'consumer':d,'stream':f}),!this[M(0x10d)];}async[A(0x122)](c,d,f,g,h){const N=A;let j,k;this[N(0x16f)][N(0x11b)](N(0x147),{'group':d,'stream':c,'id':f});try{k=new telemetry_1[(N(0x12f))](this[N(0x12e)]),k['startStreamSpan'](g,this[N(0x14b)]),j=await this[N(0x152)](g,c,f,h[N(0x140)](this)),j?.[N(0x139)]===stream_1[N(0x13b)][N(0x12d)]&&k['setStreamError'](N(0x176)+(j[N(0x170)]||enums_1[N(0x146)])),this[N(0x114)]=0x0;}catch(m){this[N(0x16f)][N(0x131)](N(0x16c),{'group':d,'stream':c,'id':f,'err':m}),k[N(0x132)](m[N(0x13e)]);}const l=await this[N(0x130)](g,j);k[N(0x171)]({'app.worker.mid':l}),await this[N(0x128)](c,d,f),k[N(0x144)](),this[N(0x16f)][N(0x11b)](N(0x174),{'group':d,'stream':c,'id':f});}async[A(0x152)](c,d,f,g){const O=A;let h;try{h=await g(c);}catch(i){this['logger']['error'](O(0x173),{'error':i,'input':c,'stack':i[O(0x135)],'message':i['message'],'name':i[O(0x156)],'stream':d,'id':f}),h=this[O(0x11d)](c,i);}return h;}async[A(0x128)](c,d,f){const P=A;await this[P(0x119)]['ackAndDelete'](c,d,[f]);}async['publishResponse'](c,d){const Q=A;if(d&&Q(0x145)==typeof d){if(Q(0x131)===d['status']){const [f,g]=this[Q(0x148)](c,d);if(f)return await(0x0,utils_1[Q(0x17a)])(g),await this[Q(0x165)](c[Q(0x112)][Q(0x136)],{'data':c[Q(0x16b)],'metadata':{...c[Q(0x112)],'try':(c['metadata'][Q(0x113)]||0x0)+0x1},'policies':c[Q(0x177)]});d=this[Q(0x125)](c,d);}else'object'!=typeof d[Q(0x112)]?d['metadata']={...c['metadata'],'guid':(0x0,utils_1[Q(0x116)])()}:d['metadata']['guid']=(0x0,utils_1[Q(0x116)])();return d['type']=stream_1['StreamDataType']['RESPONSE'],await this[Q(0x165)](null,d);}}[A(0x148)](c,d){const R=A,f=c[R(0x177)]?.['retry'],g=d[R(0x170)][R(0x12c)](),h=f?.[g],j=h?.[0x0],k=Math[R(0x167)](c[R(0x112)][R(0x113)]||0x0,enums_1[R(0x151)]);return j>k?[!0x0,Math[R(0x115)](0xa,k+0x1)]:[!0x1,0x0];}[A(0x11d)](c,d){const S=A,f={};return'string'==typeof d['message']?f[S(0x13e)]=d[S(0x13e)]:f['message']=enums_1['HMSH_STATUS_UNKNOWN'],S(0x11f)==typeof d[S(0x135)]&&(f['stack']=d[S(0x135)]),'string'==typeof d['name']&&(f[S(0x156)]=d[S(0x156)]),{'status':S(0x131),'code':enums_1['HMSH_CODE_UNKNOWN'],'metadata':{...c['metadata'],'guid':(0x0,utils_1['guid'])()},'data':f};}['structureUnacknowledgedError'](c){const T=A,d=enums_1[T(0x110)],f={'message':T(0x153),'code':d},g={'metadata':{...c[T(0x112)],'guid':(0x0,utils_1['guid'])()},'status':stream_1[T(0x13b)][T(0x12d)],'code':d,'data':f};return delete g[T(0x112)][T(0x136)],g;}[A(0x125)](c,d){const U=A,f=d[U(0x16b)]?.[U(0x13e)]?d['data']?.['message'][U(0x12c)]():enums_1[U(0x14c)],g=d[U(0x170)]||d[U(0x16b)]?.[U(0x170)],h=isNaN(g)?enums_1[U(0x146)]:parseInt(g[U(0x12c)]()),j=d[U(0x16b)]?.[U(0x135)]?d[U(0x16b)]?.['stack'][U(0x12c)]():void 0x0,k={'message':f,'code':h,'stack':j};return'object'==typeof d[U(0x16b)]?.[U(0x131)]&&(k['error']={...d[U(0x16b)][U(0x131)]}),{'status':stream_1[U(0x13b)][U(0x12d)],'code':h,'stack':j,'metadata':{...c[U(0x112)],'guid':(0x0,utils_1[U(0x116)])()},'data':k};}static async['stopConsuming'](){const V=A;for(const c of[...Router['instances']])c['stopConsuming']();await(0x0,utils_1[V(0x17a)])(0x2*enums_1[V(0x117)]);}async[A(0x10f)](){const W=A;this['shouldConsume']=!0x1,this[W(0x16f)][W(0x13c)](W(0x12a),this[W(0x136)]?{'topic':this[W(0x136)]}:void 0x0),this['cancelThrottle']();}[A(0x15f)](){const X=A;this[X(0x124)]&&clearTimeout(this[X(0x124)]),this['resetThrottleState']();}[A(0x16e)](c){const Y=A;if(!Number[Y(0x166)](c)||c<0x0||c>enums_1[Y(0x149)])throw new Error(Y(0x15d)+enums_1[Y(0x149)]+'\x20ms;\x20send\x20-1\x20to\x20throttle\x20indefinitely');const d=c<this[Y(0x123)];this[Y(0x123)]=c,d&&(this[Y(0x124)]&&clearTimeout(this[Y(0x124)]),this[Y(0x11e)]&&this['innerPromiseResolve']());}}function a(){const Z=['createConsumerGroup','setThrottle','logger','code','setStreamAttributes','test','stream-call-function-error','stream-read-one-end','1883480VAeAUN','Function\x20Status\x20Code\x20','policies','add','MAX_STREAM_BACKOFF','sleepFor','659151lpZXDl','router-stream-error','1254465tQgJqp','shouldConsume','defineProperty','stopConsuming','HMSH_CODE_UNACKED','3HmeOjp','metadata','try','errorCount','pow','guid','HMSH_BLOCK_TIME_MS','1048dgwSQu','stream','HMSH_XPENDING_COUNT','debug','instances','structureUnhandledError','innerPromiseResolve','string','resetThrottleState','retryMessages','consumeOne','throttle','sleepTimout','structureError','router-stream-readonly','reclaimDelay','ackAndDelete','2681460WCowQS','router-stream-stopping','round','toString','ERROR','appId','TelemetryService','publishResponse','error','setStreamError','now','counts','stack','topic','consumeMessages','HMSH_GRADUATED_INTERVAL_MS','status','createGroup','StreamStatus','info','readonly','message','Router','bind','hasReachedMaxBackoff','201044dUswUC','28698HItIWc','endStreamSpan','object','HMSH_CODE_UNKNOWN','stream-read-one','shouldRetry','MAX_DELAY','router-stream-group-exists','role','HMSH_STATUS_UNKNOWN','router-stream-starting','isPaused','isStopped','HMSH_XCLAIM_DELAY_MS','HMSH_MAX_RETRIES','execStreamLeg','stream\x20message\x20max\x20delivery\x20count\x20exceeded','isSleeping','publishMessages','name','customSleep','sleepPromiseResolve','287WdjpPY','length','isArray','STREAMS','Throttle\x20must\x20be\x20a\x20non-negative\x20integer\x20and\x20not\x20exceed\x20','KeyType','cancelThrottle','HMSH_MAX_TIMEOUT_MS','isStreamMessage','200','HMSH_XCLAIM_COUNT','../../modules/utils','publishMessage','isInteger','min','reclaimCount','random','251seOZhN','data','stream-read-one-error'];a=function(){return Z;};return a();}exports['Router']=Router,Router[A(0x11c)]=new Set();