@fraym/streams 1.0.17 → 1.0.19
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/client/error.js +1 -1
- package/dist/client/subscribe.js +1 -1
- package/package.json +2 -2
package/dist/client/error.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get StreamHandlerError(){return StreamHandlerError},get isRetryableError(){return isRetryableError}});function _assert_this_initialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _call_super(_this,derived,args){derived=_get_prototype_of(derived);return _possible_constructor_return(_this,_is_native_reflect_construct()?Reflect.construct(derived,args||[],_get_prototype_of(_this).constructor):derived.apply(_this,args))}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _construct(Parent,args,Class){if(_is_native_reflect_construct()){_construct=Reflect.construct}else{_construct=function construct(Parent,args,Class){var a=[null];a.push.apply(a,args);var Constructor=Function.bind.apply(Parent,a);var instance=new Constructor;if(Class)_set_prototype_of(instance,Class.prototype);return instance}}return _construct.apply(null,arguments)}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _get_prototype_of(o){_get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _get_prototype_of(o)}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_set_prototype_of(subClass,superClass)}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return!!right[Symbol.hasInstance](left)}else{return left instanceof right}}function _is_native_function(fn){return Function.toString.call(fn).indexOf("[native code]")!==-1}function _possible_constructor_return(self,call){if(call&&(_type_of(call)==="object"||typeof call==="function")){return call}return _assert_this_initialized(self)}function _set_prototype_of(o,p){_set_prototype_of=Object.setPrototypeOf||function setPrototypeOf(o,p){o.__proto__=p;return o};return _set_prototype_of(o,p)}function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}function _wrap_native_super(Class){var _cache=typeof Map==="function"?new Map:undefined;_wrap_native_super=function wrapNativeSuper(Class){if(Class===null||!_is_native_function(Class))return Class;if(typeof Class!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof _cache!=="undefined"){if(_cache.has(Class))return _cache.get(Class);_cache.set(Class,Wrapper)}function Wrapper(){return _construct(Class,arguments,_get_prototype_of(this).constructor)}Wrapper.prototype=Object.create(Class.prototype,{constructor:{value:Wrapper,enumerable:false,writable:true,configurable:true}});return _set_prototype_of(Wrapper,Class)};return _wrap_native_super(Class)}function _is_native_reflect_construct(){try{var result=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(_){}return(_is_native_reflect_construct=function(){return!!result})()}var StreamHandlerError=/*#__PURE__*/function(Error1){"use strict";_inherits(StreamHandlerError,Error1);function StreamHandlerError(error){var shouldRetry=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;_class_call_check(this,StreamHandlerError);var _this;_this=_call_super(this,StreamHandlerError,[_instanceof(error,Error)?error.message:String(error)]),_define_property(_this,"shouldRetry",void 0);_this.name="StreamHandlerError";_this.shouldRetry=shouldRetry;return _this}return StreamHandlerError}(_wrap_native_super(Error));var isRetryableError=function isRetryableError(error){return _instanceof(error,StreamHandlerError)||(typeof error==="undefined"?"undefined":_type_of(error))==="object"&&error!==null&&"shouldRetry"in error&&"message"in error};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get StreamHandlerError(){return StreamHandlerError},get isRetryableError(){return isRetryableError}});function _assert_this_initialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _call_super(_this,derived,args){derived=_get_prototype_of(derived);return _possible_constructor_return(_this,_is_native_reflect_construct()?Reflect.construct(derived,args||[],_get_prototype_of(_this).constructor):derived.apply(_this,args))}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _construct(Parent,args,Class){if(_is_native_reflect_construct()){_construct=Reflect.construct}else{_construct=function construct(Parent,args,Class){var a=[null];a.push.apply(a,args);var Constructor=Function.bind.apply(Parent,a);var instance=new Constructor;if(Class)_set_prototype_of(instance,Class.prototype);return instance}}return _construct.apply(null,arguments)}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _get_prototype_of(o){_get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _get_prototype_of(o)}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_set_prototype_of(subClass,superClass)}function _instanceof(left,right){"@swc/helpers - instanceof";if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return!!right[Symbol.hasInstance](left)}else{return left instanceof right}}function _is_native_function(fn){return Function.toString.call(fn).indexOf("[native code]")!==-1}function _possible_constructor_return(self,call){if(call&&(_type_of(call)==="object"||typeof call==="function")){return call}return _assert_this_initialized(self)}function _set_prototype_of(o,p){_set_prototype_of=Object.setPrototypeOf||function setPrototypeOf(o,p){o.__proto__=p;return o};return _set_prototype_of(o,p)}function _type_of(obj){"@swc/helpers - typeof";return obj&&typeof Symbol!=="undefined"&&obj.constructor===Symbol?"symbol":typeof obj}function _wrap_native_super(Class){var _cache=typeof Map==="function"?new Map:undefined;_wrap_native_super=function wrapNativeSuper(Class){if(Class===null||!_is_native_function(Class))return Class;if(typeof Class!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof _cache!=="undefined"){if(_cache.has(Class))return _cache.get(Class);_cache.set(Class,Wrapper)}function Wrapper(){return _construct(Class,arguments,_get_prototype_of(this).constructor)}Wrapper.prototype=Object.create(Class.prototype,{constructor:{value:Wrapper,enumerable:false,writable:true,configurable:true}});return _set_prototype_of(Wrapper,Class)};return _wrap_native_super(Class)}function _is_native_reflect_construct(){try{var result=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(_){}return(_is_native_reflect_construct=function(){return!!result})()}var StreamHandlerError=/*#__PURE__*/function(Error1){"use strict";_inherits(StreamHandlerError,Error1);function StreamHandlerError(error){var shouldRetry=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;_class_call_check(this,StreamHandlerError);var _this;_this=_call_super(this,StreamHandlerError,[_instanceof(error,Error)?error.message:String(error)]),_define_property(_this,"shouldRetry",void 0);_this.name="StreamHandlerError";_this.shouldRetry=shouldRetry;return _this}return StreamHandlerError}(_wrap_native_super(Error));var isRetryableError=function isRetryableError(error){return _instanceof(error,StreamHandlerError)||(typeof error==="undefined"?"undefined":_type_of(error))==="object"&&error!==null&&"shouldRetry"in error&&"message"in error};
|
package/dist/client/subscribe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get initStream(){return initStream},get newSubscription(){return newSubscription}});var _uuid=require("uuid");var _constants=require("@grpc/grpc-js/build/src/constants");var _error=require("./error");var _event=require("./event");function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return!!right[Symbol.hasInstance](left)}else{return left instanceof right}}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype),d=Object.defineProperty;return d(g,"next",{value:verb(0)}),d(g,"throw",{value:verb(1)}),d(g,"return",{value:verb(2)}),typeof Symbol==="function"&&d(g,Symbol.iterator,{value:function(){return this}}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}var newSubscription=function newSubscription(topics,ignoreUnhandledEvents,parallelTopicProcessing,config,serviceClient){var stream=null;var closed=false;var typeHandlerMap={};var globalHandler=null;var rebuildConnection=function rebuildConnection(currentStream,retries){currentStream.cancel();currentStream.removeAllListeners();setTimeout(function(){stream=null;reconnect(retries)},100)};var reconnect=function reconnect(retries){return _async_to_generator(function(){var newStream,dataFn;return _ts_generator(this,function(_state){switch(_state.label){case 0:newStream=serviceClient.subscribe();newStream.on("end",function(){if(closed){newStream.cancel();return}rebuildConnection(newStream,retries-1)});newStream.on("error",function(err){if(closed){return}if(retries===0||err&&err.code&&err.code===_constants.Status.UNKNOWN){closed=true;throw err}rebuildConnection(newStream,retries-1)});dataFn=function dataFn(data){return _async_to_generator(function(){var _data_payload,_data_payload1,event,typedHandler,err,shouldRetry,errorMessage;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!data.payload||((_data_payload=data.payload)===null||_data_payload===void 0?void 0:_data_payload.$case)==="panic"||((_data_payload1=data.payload)===null||_data_payload1===void 0?void 0:_data_payload1.$case)==="subscribed"){newStream.cancel();return[2]}event=(0,_event.getSubscriptionEvent)(data.payload.event);if(!event){return[2]}if(!event.type){return[2]}_state.label=1;case 1:_state.trys.push([1,7,,8]);typedHandler=typeHandlerMap[event.type];if(!typedHandler)return[3,3];return[4,typedHandler(event)];case 2:_state.sent();return[3,6];case 3:if(!globalHandler)return[3,5];return[4,globalHandler(event)];case 4:_state.sent();return[3,6];case 5:if(ignoreUnhandledEvents){newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream));return[2]}newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream,"no handlers for this event, maybe you forgot to register an event handler",true));return[2];case 6:newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream));return[3,8];case 7:err=_state.sent();shouldRetry=(0,_error.isRetryableError)(err)&&err.shouldRetry;errorMessage=_instanceof(err,Error)?err.message:String(err);newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream,errorMessage,shouldRetry));throw err;case 8:return[2]}})})()};stream=newStream;return[4,initStream(topics,config,parallelTopicProcessing,newStream)];case 1:_state.sent();retries=50;newStream.on("data",dataFn);return[2]}})})()};return{useHandler:function useHandler(type,handler){typeHandlerMap[type]=handler},useHandlerForAllTypes:function useHandlerForAllTypes(handler){globalHandler=handler},start:function start(){reconnect(50)},stop:function stop(){if(stream){stream.cancel();stream=null}closed=true}}};var initStream=function initStream(topics,config,parallelTopicProcessing,stream){return _async_to_generator(function(){return _ts_generator(this,function(_state){return[2,new Promise(function(resolve,reject){stream.write({payload:{$case:"subscribe",subscribe:{metadata:{group:config.groupId,subscriberId:(0,_uuid.v4)(),deploymentId:config.deploymentId.toString(),parallelTopicProcessing:parallelTopicProcessing},topics:topics}}});stream.once("data",function(data){var _data_payload;if(((_data_payload=data.payload)===null||_data_payload===void 0?void 0:_data_payload.$case)!=="subscribed"){reject("connection to streams service was not initialized correctly");return}if(data.payload.subscribed.error){reject("unable to subscribe to streams service: ".concat(data.payload.subscribed.error));return}resolve(stream)})})]})})()};var newHandledRequest=function newHandledRequest(tenantId,topic,stream,error,retry){return{payload:{$case:"handled",handled:{tenantId:tenantId,topic:topic,stream:stream!==null&&stream!==void 0?stream:"",error:error!==null&&error!==void 0?error:"",retry:retry!==null&&retry!==void 0?retry:false}}}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get initStream(){return initStream},get newSubscription(){return newSubscription}});var _uuid=require("uuid");var _constants=require("@grpc/grpc-js/build/src/constants");var _error=require("./error");var _event=require("./event");function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _instanceof(left,right){"@swc/helpers - instanceof";if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return!!right[Symbol.hasInstance](left)}else{return left instanceof right}}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype),d=Object.defineProperty;return d(g,"next",{value:verb(0)}),d(g,"throw",{value:verb(1)}),d(g,"return",{value:verb(2)}),typeof Symbol==="function"&&d(g,Symbol.iterator,{value:function(){return this}}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}var newSubscription=function newSubscription(topics,ignoreUnhandledEvents,parallelTopicProcessing,config,serviceClient){var stream=null;var closed=false;var typeHandlerMap={};var globalHandler=null;var rebuildConnection=function rebuildConnection(currentStream,retries){currentStream.cancel();currentStream.removeAllListeners();setTimeout(function(){stream=null;reconnect(retries)},100)};var reconnect=function reconnect(retries){return _async_to_generator(function(){var newStream,dataFn;return _ts_generator(this,function(_state){switch(_state.label){case 0:newStream=serviceClient.subscribe();newStream.on("end",function(){if(closed){newStream.cancel();return}rebuildConnection(newStream,retries-1)});newStream.on("error",function(err){if(closed){return}if(retries===0||err&&err.code&&err.code===_constants.Status.UNKNOWN){closed=true;throw err}rebuildConnection(newStream,retries-1)});dataFn=function dataFn(data){return _async_to_generator(function(){var _data_payload,_data_payload1,event,typedHandler,err,shouldRetry,errorMessage;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!data.payload||((_data_payload=data.payload)===null||_data_payload===void 0?void 0:_data_payload.$case)==="panic"||((_data_payload1=data.payload)===null||_data_payload1===void 0?void 0:_data_payload1.$case)==="subscribed"){newStream.cancel();return[2]}event=(0,_event.getSubscriptionEvent)(data.payload.event);if(!event){return[2]}if(!event.type){return[2]}_state.label=1;case 1:_state.trys.push([1,7,,8]);typedHandler=typeHandlerMap[event.type];if(!typedHandler)return[3,3];return[4,typedHandler(event)];case 2:_state.sent();return[3,6];case 3:if(!globalHandler)return[3,5];return[4,globalHandler(event)];case 4:_state.sent();return[3,6];case 5:if(ignoreUnhandledEvents){newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream));return[2]}newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream,"no handlers for this event, maybe you forgot to register an event handler",true));return[2];case 6:newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream));return[3,8];case 7:err=_state.sent();shouldRetry=(0,_error.isRetryableError)(err)&&err.shouldRetry;errorMessage=_instanceof(err,Error)?err.message:String(err);newStream.write(newHandledRequest(event.tenantId,event.topic,event.stream,errorMessage,shouldRetry));throw err;case 8:return[2]}})})()};stream=newStream;return[4,initStream(topics,config,parallelTopicProcessing,newStream)];case 1:_state.sent();retries=50;newStream.on("data",dataFn);return[2]}})})()};return{useHandler:function useHandler(type,handler){typeHandlerMap[type]=handler},useHandlerForAllTypes:function useHandlerForAllTypes(handler){globalHandler=handler},start:function start(){reconnect(50)},stop:function stop(){if(stream){stream.cancel();stream=null}closed=true}}};var initStream=function initStream(topics,config,parallelTopicProcessing,stream){return _async_to_generator(function(){return _ts_generator(this,function(_state){return[2,new Promise(function(resolve,reject){stream.write({payload:{$case:"subscribe",subscribe:{metadata:{group:config.groupId,subscriberId:(0,_uuid.v4)(),deploymentId:config.deploymentId.toString(),parallelTopicProcessing:parallelTopicProcessing},topics:topics}}});stream.once("data",function(data){var _data_payload;if(((_data_payload=data.payload)===null||_data_payload===void 0?void 0:_data_payload.$case)!=="subscribed"){reject("connection to streams service was not initialized correctly");return}if(data.payload.subscribed.error){reject("unable to subscribe to streams service: ".concat(data.payload.subscribed.error));return}resolve(stream)})})]})})()};var newHandledRequest=function newHandledRequest(tenantId,topic,stream,error,retry){return{payload:{$case:"handled",handled:{tenantId:tenantId,topic:topic,stream:stream!==null&&stream!==void 0?stream:"",error:error!==null&&error!==void 0?error:"",retry:retry!==null&&retry!==void 0?retry:false}}}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/streams",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/fraym/fraeym",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"main": "dist/index.js",
|
|
23
23
|
"types": "dist/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@fraym/proto": "^1.0.
|
|
25
|
+
"@fraym/proto": "^1.0.19",
|
|
26
26
|
"@grpc/grpc-js": "^1.14.3",
|
|
27
27
|
"dotenv": "^17.3.1",
|
|
28
28
|
"uuid": "11.1.0"
|