@leancodepl/rx-cqrs-client 9.7.2 → 9.7.3

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.
@@ -0,0 +1,4 @@
1
+ (function(_,P){typeof exports=="object"&&typeof module<"u"?P(exports):typeof define=="function"&&define.amd?define(["exports"],P):(_=typeof globalThis<"u"?globalThis:_||self,P(_["@leancodepl/rx-cqrs-client"]={}))})(this,(function(_){"use strict";var P=function(e,r){return P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])},P(e,r)};function q(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");P(e,r);function t(){this.constructor=e}e.prototype=r===null?Object.create(r):(t.prototype=r.prototype,new t)}var H=function(){return H=Object.assign||function(r){for(var t,n=1,i=arguments.length;n<i;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},H.apply(this,arguments)};function Ne(e,r,t,n){function i(o){return o instanceof t?o:new t(function(u){u(o)})}return new(t||(t=Promise))(function(o,u){function a(f){try{s(n.next(f))}catch(d){u(d)}}function c(f){try{s(n.throw(f))}catch(d){u(d)}}function s(f){f.done?o(f.value):i(f.value).then(a,c)}s((n=n.apply(e,r||[])).next())})}function se(e,r){var t={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,u=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return u.next=a(0),u.throw=a(1),u.return=a(2),typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function a(s){return function(f){return c([s,f])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;u&&(u=0,s[0]&&(t=0)),t;)try{if(n=1,i&&(o=s[0]&2?i.return:s[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;switch(i=0,o&&(s=[s[0]&2,o.value]),s[0]){case 0:case 1:o=s;break;case 4:return t.label++,{value:s[1],done:!1};case 5:t.label++,i=s[1],s=[0];continue;case 7:s=t.ops.pop(),t.trys.pop();continue;default:if(o=t.trys,!(o=o.length>0&&o[o.length-1])&&(s[0]===6||s[0]===2)){t=0;continue}if(s[0]===3&&(!o||s[1]>o[0]&&s[1]<o[3])){t.label=s[1];break}if(s[0]===6&&t.label<o[1]){t.label=o[1],o=s;break}if(o&&t.label<o[2]){t.label=o[2],t.ops.push(s);break}o[2]&&t.ops.pop(),t.trys.pop();continue}s=r.call(e,t)}catch(f){s=[6,f],i=0}finally{n=o=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}function D(e){var r=typeof Symbol=="function"&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function V(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),i,o=[],u;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(a){u={error:a}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(u)throw u.error}}return o}function $(e,r,t){if(t||arguments.length===2)for(var n=0,i=r.length,o;n<i;n++)(o||!(n in r))&&(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return e.concat(o||Array.prototype.slice.call(r))}function F(e){return this instanceof F?(this.v=e,this):new F(e)}function Ve(e,r,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(e,r||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",u),i[Symbol.asyncIterator]=function(){return this},i;function u(l){return function(S){return Promise.resolve(S).then(l,d)}}function a(l,S){n[l]&&(i[l]=function(h){return new Promise(function(U,I){o.push([l,h,U,I])>1||c(l,h)})},S&&(i[l]=S(i[l])))}function c(l,S){try{s(n[l](S))}catch(h){y(o[0][3],h)}}function s(l){l.value instanceof F?Promise.resolve(l.value.v).then(f,d):y(o[0][2],l)}function f(l){c("next",l)}function d(l){c("throw",l)}function y(l,S){l(S),o.shift(),o.length&&c(o[0][0],o[0][1])}}function $e(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e[Symbol.asyncIterator],t;return r?r.call(e):(e=typeof D=="function"?D(e):e[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=e[o]&&function(u){return new Promise(function(a,c){u=e[o](u),i(a,c,u.done,u.value)})}}function i(o,u,a,c){Promise.resolve(c).then(function(s){o({value:s,done:a})},u)}}typeof SuppressedError=="function"&&SuppressedError;function v(e){return typeof e=="function"}function X(e){var r=function(n){Error.call(n),n.stack=new Error().stack},t=e(r);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Y=X(function(e){return function(t){e(this),this.message=t?t.length+` errors occurred during unsubscription:
2
+ `+t.map(function(n,i){return i+1+") "+n.toString()}).join(`
3
+ `):"",this.name="UnsubscriptionError",this.errors=t}});function J(e,r){if(e){var t=e.indexOf(r);0<=t&&e.splice(t,1)}}var G=(function(){function e(r){this.initialTeardown=r,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var r,t,n,i,o;if(!this.closed){this.closed=!0;var u=this._parentage;if(u)if(this._parentage=null,Array.isArray(u))try{for(var a=D(u),c=a.next();!c.done;c=a.next()){var s=c.value;s.remove(this)}}catch(h){r={error:h}}finally{try{c&&!c.done&&(t=a.return)&&t.call(a)}finally{if(r)throw r.error}}else u.remove(this);var f=this.initialTeardown;if(v(f))try{f()}catch(h){o=h instanceof Y?h.errors:[h]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var y=D(d),l=y.next();!l.done;l=y.next()){var S=l.value;try{le(S)}catch(h){o=o??[],h instanceof Y?o=$($([],V(o)),V(h.errors)):o.push(h)}}}catch(h){n={error:h}}finally{try{l&&!l.done&&(i=y.return)&&i.call(y)}finally{if(n)throw n.error}}}if(o)throw new Y(o)}},e.prototype.add=function(r){var t;if(r&&r!==this)if(this.closed)le(r);else{if(r instanceof e){if(r.closed||r._hasParent(this))return;r._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(r)}},e.prototype._hasParent=function(r){var t=this._parentage;return t===r||Array.isArray(t)&&t.includes(r)},e.prototype._addParent=function(r){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(r),t):t?[t,r]:r},e.prototype._removeParent=function(r){var t=this._parentage;t===r?this._parentage=null:Array.isArray(t)&&J(t,r)},e.prototype.remove=function(r){var t=this._finalizers;t&&J(t,r),r instanceof e&&r._removeParent(this)},e.EMPTY=(function(){var r=new e;return r.closed=!0,r})(),e})(),ce=G.EMPTY;function fe(e){return e instanceof G||e&&"closed"in e&&v(e.remove)&&v(e.add)&&v(e.unsubscribe)}function le(e){v(e)?e():e.unsubscribe()}var Xe={Promise:void 0},Ye={setTimeout:function(e,r){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,$([e,r],V(t)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function de(e){Ye.setTimeout(function(){throw e})}function he(){}function z(e){e()}var Q=(function(e){q(r,e);function r(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,fe(t)&&t.add(n)):n.destination=Ke,n}return r.create=function(t,n,i){return new K(t,n,i)},r.prototype.next=function(t){this.isStopped||this._next(t)},r.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},r.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(t){this.destination.next(t)},r.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r})(G),Je=(function(){function e(r){this.partialObserver=r}return e.prototype.next=function(r){var t=this.partialObserver;if(t.next)try{t.next(r)}catch(n){N(n)}},e.prototype.error=function(r){var t=this.partialObserver;if(t.error)try{t.error(r)}catch(n){N(n)}else N(r)},e.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(t){N(t)}},e})(),K=(function(e){q(r,e);function r(t,n,i){var o=e.call(this)||this,u;return v(t)||!t?u={next:t??void 0,error:n??void 0,complete:i??void 0}:u=t,o.destination=new Je(u),o}return r})(Q);function N(e){de(e)}function Qe(e){throw e}var Ke={closed:!0,next:he,error:Qe,complete:he},Z=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ze(e){return e}function et(e){return e.length===0?Ze:e.length===1?e[0]:function(t){return e.reduce(function(n,i){return i(n)},t)}}var x=(function(){function e(r){r&&(this._subscribe=r)}return e.prototype.lift=function(r){var t=new e;return t.source=this,t.operator=r,t},e.prototype.subscribe=function(r,t,n){var i=this,o=rt(r)?r:new K(r,t,n);return z(function(){var u=i,a=u.operator,c=u.source;o.add(a?a.call(o,c):c?i._subscribe(o):i._trySubscribe(o))}),o},e.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(t){r.error(t)}},e.prototype.forEach=function(r,t){var n=this;return t=pe(t),new t(function(i,o){var u=new K({next:function(a){try{r(a)}catch(c){o(c),u.unsubscribe()}},error:o,complete:i});n.subscribe(u)})},e.prototype._subscribe=function(r){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(r)},e.prototype[Z]=function(){return this},e.prototype.pipe=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return et(r)(this)},e.prototype.toPromise=function(r){var t=this;return r=pe(r),new r(function(n,i){var o;t.subscribe(function(u){return o=u},function(u){return i(u)},function(){return n(o)})})},e.create=function(r){return new e(r)},e})();function pe(e){var r;return(r=e??Xe.Promise)!==null&&r!==void 0?r:Promise}function tt(e){return e&&v(e.next)&&v(e.error)&&v(e.complete)}function rt(e){return e&&e instanceof Q||tt(e)&&fe(e)}function nt(e){return v(e?.lift)}function R(e){return function(r){if(nt(r))return r.lift(function(t){try{return e(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function A(e,r,t,n,i){return new ot(e,r,t,n,i)}var ot=(function(e){q(r,e);function r(t,n,i,o,u,a){var c=e.call(this,t)||this;return c.onFinalize=u,c.shouldUnsubscribe=a,c._next=n?function(s){try{n(s)}catch(f){t.error(f)}}:e.prototype._next,c._error=o?function(s){try{o(s)}catch(f){t.error(f)}finally{this.unsubscribe()}}:e.prototype._error,c._complete=i?function(){try{i()}catch(s){t.error(s)}finally{this.unsubscribe()}}:e.prototype._complete,c}return r.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},r})(Q),it=X(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ee=(function(e){q(r,e);function r(){var t=e.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return r.prototype.lift=function(t){var n=new ve(this,this);return n.operator=t,n},r.prototype._throwIfClosed=function(){if(this.closed)throw new it},r.prototype.next=function(t){var n=this;z(function(){var i,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var u=D(n.currentObservers),a=u.next();!a.done;a=u.next()){var c=a.value;c.next(t)}}catch(s){i={error:s}}finally{try{a&&!a.done&&(o=u.return)&&o.call(u)}finally{if(i)throw i.error}}}})},r.prototype.error=function(t){var n=this;z(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var i=n.observers;i.length;)i.shift().error(t)}})},r.prototype.complete=function(){var t=this;z(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},r.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(r.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},r.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},r.prototype._innerSubscribe=function(t){var n=this,i=this,o=i.hasError,u=i.isStopped,a=i.observers;return o||u?ce:(this.currentObservers=null,a.push(t),new G(function(){n.currentObservers=null,J(a,t)}))},r.prototype._checkFinalizedStatuses=function(t){var n=this,i=n.hasError,o=n.thrownError,u=n.isStopped;i?t.error(o):u&&t.complete()},r.prototype.asObservable=function(){var t=new x;return t.source=this,t},r.create=function(t,n){return new ve(t,n)},r})(x),ve=(function(e){q(r,e);function r(t,n){var i=e.call(this)||this;return i.destination=t,i.source=n,i}return r.prototype.next=function(t){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,t)},r.prototype.error=function(t){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,t)},r.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},r.prototype._subscribe=function(t){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&i!==void 0?i:ce},r})(ee),ye={now:function(){return(ye.delegate||Date).now()},delegate:void 0},ut=(function(e){q(r,e);function r(t,n,i){t===void 0&&(t=1/0),n===void 0&&(n=1/0),i===void 0&&(i=ye);var o=e.call(this)||this;return o._bufferSize=t,o._windowTime=n,o._timestampProvider=i,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=n===1/0,o._bufferSize=Math.max(1,t),o._windowTime=Math.max(1,n),o}return r.prototype.next=function(t){var n=this,i=n.isStopped,o=n._buffer,u=n._infiniteTimeWindow,a=n._timestampProvider,c=n._windowTime;i||(o.push(t),!u&&o.push(a.now()+c)),this._trimBuffer(),e.prototype.next.call(this,t)},r.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(t),i=this,o=i._infiniteTimeWindow,u=i._buffer,a=u.slice(),c=0;c<a.length&&!t.closed;c+=o?1:2)t.next(a[c]);return this._checkFinalizedStatuses(t),n},r.prototype._trimBuffer=function(){var t=this,n=t._bufferSize,i=t._timestampProvider,o=t._buffer,u=t._infiniteTimeWindow,a=(u?1:2)*n;if(n<1/0&&a<o.length&&o.splice(0,o.length-a),!u){for(var c=i.now(),s=0,f=1;f<o.length&&o[f]<=c;f+=2)s=f;s&&o.splice(0,s+1)}},r})(ee);function at(e){return e&&v(e.schedule)}function st(e){return e[e.length-1]}function ct(e){return at(st(e))?e.pop():void 0}var me=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function be(e){return v(e?.then)}function we(e){return v(e[Z])}function Se(e){return Symbol.asyncIterator&&v(e?.[Symbol.asyncIterator])}function xe(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ft(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Te=ft();function ge(e){return v(e?.[Te])}function Ee(e){return Ve(this,arguments,function(){var t,n,i,o;return se(this,function(u){switch(u.label){case 0:t=e.getReader(),u.label=1;case 1:u.trys.push([1,,9,10]),u.label=2;case 2:return[4,F(t.read())];case 3:return n=u.sent(),i=n.value,o=n.done,o?[4,F(void 0)]:[3,5];case 4:return[2,u.sent()];case 5:return[4,F(i)];case 6:return[4,u.sent()];case 7:return u.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function _e(e){return v(e?.getReader)}function C(e){if(e instanceof x)return e;if(e!=null){if(we(e))return lt(e);if(me(e))return dt(e);if(be(e))return ht(e);if(Se(e))return Oe(e);if(ge(e))return pt(e);if(_e(e))return vt(e)}throw xe(e)}function lt(e){return new x(function(r){var t=e[Z]();if(v(t.subscribe))return t.subscribe(r);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function dt(e){return new x(function(r){for(var t=0;t<e.length&&!r.closed;t++)r.next(e[t]);r.complete()})}function ht(e){return new x(function(r){e.then(function(t){r.closed||(r.next(t),r.complete())},function(t){return r.error(t)}).then(null,de)})}function pt(e){return new x(function(r){var t,n;try{for(var i=D(e),o=i.next();!o.done;o=i.next()){var u=o.value;if(r.next(u),r.closed)return}}catch(a){t={error:a}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}r.complete()})}function Oe(e){return new x(function(r){yt(e,r).catch(function(t){return r.error(t)})})}function vt(e){return Oe(Ee(e))}function yt(e,r){var t,n,i,o;return Ne(this,void 0,void 0,function(){var u,a;return se(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),t=$e(e),c.label=1;case 1:return[4,t.next()];case 2:if(n=c.sent(),!!n.done)return[3,4];if(u=n.value,r.next(u),r.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),n&&!n.done&&(o=t.return)?[4,o.call(t)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return r.complete(),[2]}})})}function L(e,r,t,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=r.schedule(function(){t(),i?e.add(this.schedule(null,n)):this.unsubscribe()},n);if(e.add(o),!i)return o}function Ae(e,r){return r===void 0&&(r=0),R(function(t,n){t.subscribe(A(n,function(i){return L(n,e,function(){return n.next(i)},r)},function(){return L(n,e,function(){return n.complete()},r)},function(i){return L(n,e,function(){return n.error(i)},r)}))})}function je(e,r){return r===void 0&&(r=0),R(function(t,n){n.add(e.schedule(function(){return t.subscribe(n)},r))})}function mt(e,r){return C(e).pipe(je(r),Ae(r))}function bt(e,r){return C(e).pipe(je(r),Ae(r))}function wt(e,r){return new x(function(t){var n=0;return r.schedule(function(){n===e.length?t.complete():(t.next(e[n++]),t.closed||this.schedule())})})}function St(e,r){return new x(function(t){var n;return L(t,r,function(){n=e[Te](),L(t,r,function(){var i,o,u;try{i=n.next(),o=i.value,u=i.done}catch(a){t.error(a);return}u?t.complete():t.next(o)},0,!0)}),function(){return v(n?.return)&&n.return()}})}function Ie(e,r){if(!e)throw new Error("Iterable cannot be null");return new x(function(t){L(t,r,function(){var n=e[Symbol.asyncIterator]();L(t,r,function(){n.next().then(function(i){i.done?t.complete():t.next(i.value)})},0,!0)})})}function xt(e,r){return Ie(Ee(e),r)}function Tt(e,r){if(e!=null){if(we(e))return mt(e,r);if(me(e))return wt(e,r);if(be(e))return bt(e,r);if(Se(e))return Ie(e,r);if(ge(e))return St(e,r);if(_e(e))return xt(e,r)}throw xe(e)}function M(e,r){return r?Tt(e,r):C(e)}function te(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=ct(e);return M(e,t)}function Pe(e,r){var t=v(e)?e:function(){return e},n=function(i){return i.error(t())};return new x(n)}function E(e,r){return R(function(t,n){var i=0;t.subscribe(A(n,function(o){n.next(e.call(r,o,i++))}))})}function gt(e,r,t,n,i,o,u,a){var c=[],s=0,f=0,d=!1,y=function(){d&&!c.length&&!s&&r.complete()},l=function(h){return s<n?S(h):c.push(h)},S=function(h){s++;var U=!1;C(t(h,f++)).subscribe(A(r,function(I){r.next(I)},function(){U=!0},void 0,function(){if(U)try{s--;for(var I=function(){var k=c.shift();u||S(k)};c.length&&s<n;)I();y()}catch(k){r.error(k)}}))};return e.subscribe(A(r,l,function(){d=!0,y()})),function(){}}function j(e,r,t){return t===void 0&&(t=1/0),v(r)?j(function(n,i){return E(function(o,u){return r(n,o,i,u)})(C(e(n,i)))},t):(typeof r=="number"&&(t=r),R(function(n,i){return gt(n,i,e,t)}))}function Re(e){return R(function(r,t){var n=null,i=!1,o;n=r.subscribe(A(t,void 0,void 0,function(u){o=C(e(u,Re(e)(r))),n?(n.unsubscribe(),n=null,o.subscribe(t)):i=!0})),i&&(n.unsubscribe(),n=null,o.subscribe(t))})}function Et(e,r,t,n,i){return function(o,u){var a=t,c=r,s=0;o.subscribe(A(u,function(f){var d=s++;c=a?e(c,f,d):(a=!0,f)},(function(){a&&u.next(c),u.complete()})))}}function Ce(e,r){return R(Et(e,r,arguments.length>=2,!1,!0))}function _t(e,r){return v(r)?j(e,r,1):j(e,1)}function Ot(e){return R(function(r,t){var n,i=!1,o,u=function(){n=r.subscribe(A(t,void 0,void 0,function(a){o||(o=new ee,C(e(o)).subscribe(A(t,function(){return n?u():i=!0}))),o&&o.next(a)})),i&&(n.unsubscribe(),n=null,i=!1,u())};u()})}function At(e){return r=>r.pipe(_t(t=>{const n=new ut;return e(t)({reducer:(i,o)=>n.next(o),initialValue:null}),n.complete(),n}))}function Le(e){switch(e.responseType){case"json":{if("response"in e)return e.response;var r=e;return JSON.parse(r.responseText)}case"document":return e.responseXML;default:{if("response"in e)return e.response;var r=e;return r.responseText}}}var jt=(function(){function e(r,t,n,i){i===void 0&&(i="download_load"),this.originalEvent=r,this.xhr=t,this.request=n,this.type=i;var o=t.status,u=t.responseType;this.status=o??0,this.responseType=u??"";var a=t.getAllResponseHeaders();this.responseHeaders=a?a.split(`
4
+ `).reduce(function(f,d){var y=d.indexOf(": ");return f[d.slice(0,y)]=d.slice(y+2),f},{}):{},this.response=Le(t);var c=r.loaded,s=r.total;this.loaded=c,this.total=s}return e})(),W=X(function(e){return function(t,n,i){this.message=t,this.name="AjaxError",this.xhr=n,this.request=i,this.status=n.status,this.responseType=n.responseType;var o;try{o=Le(n)}catch{o=n.responseText}this.response=o}}),It=(function(){function e(r,t){return W.call(this,"ajax timeout",r,t),this.name="AjaxTimeoutError",this}return e.prototype=Object.create(W.prototype),e})();function Pt(e,r){return O({method:"GET",url:e,headers:r})}function Rt(e,r,t){return O({method:"POST",url:e,body:r,headers:t})}function Ct(e,r){return O({method:"DELETE",url:e,headers:r})}function Lt(e,r,t){return O({method:"PUT",url:e,body:r,headers:t})}function Ut(e,r,t){return O({method:"PATCH",url:e,body:r,headers:t})}var kt=E(function(e){return e.response});function Bt(e,r){return kt(O({method:"GET",url:e,headers:r}))}var O=(function(){var e=function(r){var t=typeof r=="string"?{url:r}:r;return Dt(t)};return e.get=Pt,e.post=Rt,e.delete=Ct,e.put=Lt,e.patch=Ut,e.getJSON=Bt,e})(),qt="upload",Ue="download",re="loadstart",ne="progress",ke="load";function Dt(e){return new x(function(r){var t,n,i=H({async:!0,crossDomain:!1,withCredentials:!1,method:"GET",timeout:0,responseType:"json"},e),o=i.queryParams,u=i.body,a=i.headers,c=i.url;if(!c)throw new TypeError("url is required");if(o){var s;if(c.includes("?")){var f=c.split("?");if(2<f.length)throw new TypeError("invalid url");s=new URLSearchParams(f[1]),new URLSearchParams(o).forEach(function(b,w){return s.set(w,b)}),c=f[0]+"?"+s}else s=new URLSearchParams(o),c=c+"?"+s}var d={};if(a)for(var y in a)a.hasOwnProperty(y)&&(d[y.toLowerCase()]=a[y]);var l=i.crossDomain;!l&&!("x-requested-with"in d)&&(d["x-requested-with"]="XMLHttpRequest");var S=i.withCredentials,h=i.xsrfCookieName,U=i.xsrfHeaderName;if((S||!l)&&h&&U){var I=(n=(t=document?.cookie.match(new RegExp("(^|;\\s*)("+h+")=([^;]*)")))===null||t===void 0?void 0:t.pop())!==null&&n!==void 0?n:"";I&&(d[U]=I)}var k=Ft(u,d),g=H(H({},i),{url:c,headers:d,body:k}),p;p=e.createXHR?e.createXHR():new XMLHttpRequest;{var m=e.progressSubscriber,Be=e.includeDownloadProgress,Kt=Be===void 0?!1:Be,qe=e.includeUploadProgress,Zt=qe===void 0?!1:qe,De=function(b,w){p.addEventListener(b,function(){var T,B=w();(T=m?.error)===null||T===void 0||T.call(m,B),r.error(B)})};De("timeout",function(){return new It(p,g)}),De("abort",function(){return new W("aborted",p,g)});var Fe=function(b,w){return new jt(w,p,g,b+"_"+w.type)},He=function(b,w,T){b.addEventListener(w,function(B){r.next(Fe(T,B))})};Zt&&[re,ne,ke].forEach(function(b){return He(p.upload,b,qt)}),m&&[re,ne].forEach(function(b){return p.upload.addEventListener(b,function(w){var T;return(T=m?.next)===null||T===void 0?void 0:T.call(m,w)})}),Kt&&[re,ne].forEach(function(b){return He(p,b,Ue)});var Me=function(b){var w="ajax error"+(b?" "+b:"");r.error(new W(w,p,g))};p.addEventListener("error",function(b){var w;(w=m?.error)===null||w===void 0||w.call(m,b),Me()}),p.addEventListener(ke,function(b){var w,T,B=p.status;if(B<400){(w=m?.complete)===null||w===void 0||w.call(m);var ze=void 0;try{ze=Fe(Ue,b)}catch(er){r.error(er);return}r.next(ze),r.complete()}else(T=m?.error)===null||T===void 0||T.call(m,b),Me(B)})}var We=g.user,Ge=g.method,ae=g.async;We?p.open(Ge,c,ae,We,g.password):p.open(Ge,c,ae),ae&&(p.timeout=g.timeout,p.responseType=g.responseType),"withCredentials"in p&&(p.withCredentials=g.withCredentials);for(var y in d)d.hasOwnProperty(y)&&p.setRequestHeader(y,d[y]);return k?p.send(k):p.send(),function(){p&&p.readyState!==4&&p.abort()}})}function Ft(e,r){var t;if(!e||typeof e=="string"||Nt(e)||Vt(e)||Mt(e)||Wt(e)||Gt(e)||$t(e))return e;if(zt(e))return e.buffer;if(typeof e=="object")return r["content-type"]=(t=r["content-type"])!==null&&t!==void 0?t:"application/json;charset=utf-8",JSON.stringify(e);throw new TypeError("Unknown body type")}var Ht=Object.prototype.toString;function oe(e,r){return Ht.call(e)==="[object "+r+"]"}function Mt(e){return oe(e,"ArrayBuffer")}function Wt(e){return oe(e,"File")}function Gt(e){return oe(e,"Blob")}function zt(e){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView(e)}function Nt(e){return typeof FormData<"u"&&e instanceof FormData}function Vt(e){return typeof URLSearchParams<"u"&&e instanceof URLSearchParams}function $t(e){return typeof ReadableStream<"u"&&e instanceof ReadableStream}function ie(e,r,t=[]){return{handle:(n,i)=>{let o;for(const a of Array.isArray(n)?n:[n]){const c=e.find(s=>s.ErrorCode===r[a]);if(c){o=i(a,c);break}}let u=t;return o!==void 0&&(u=[...u,o]),ie(e,r,u)},handleAll:(n,i)=>{let o;const u=(Array.isArray(n)?n:[n]).reduce((c,s)=>{const f=e.filter(d=>d.ErrorCode===r[s]);return f.length===0?c:[...c,{errorName:s,errors:f}]},[]);u.length>0&&(o=i(u));let a=t;return o!==void 0&&(a=[...a,o]),ie(e,r,a)},check:(n=>{if(n)return t.reduce(n.reducer,n.initialValue)})}}function Xt(e,r){const t={...r,success:-1,failure:-2},n=e.isSuccess?e.result.WasSuccessful?[{ErrorMessage:"",PropertyName:"",ErrorCode:-1}]:e.result.ValidationErrors:[{ErrorMessage:"",PropertyName:"",ErrorCode:-2}];return ie(n,t)}function ue(e){return r=>r.pipe(Ot(t=>t.pipe(j((n,i)=>i===0&&n.status===401?M(e.invalidateToken()).pipe(j(o=>o?te(o):Pe(()=>n))):Pe(()=>n)))))}function Yt({cqrsEndpoint:e,tokenProvider:r,ajaxOptions:t,tokenHeader:n="Authorization"}){return{createQuery(i){const o=(u,a)=>O({...t,headers:{[n]:a,"Content-Type":"application/json"},url:`${e}/query/${i}`,method:"POST",responseType:"json",body:u});return r?u=>M(r.getToken()).pipe(j(a=>o(u,a).pipe(ue(r))),E(({response:a})=>a)):u=>o(u).pipe(E(({response:a})=>a))},createOperation(i){const o=(u,a)=>O({...t,headers:{Authorization:a,"Content-Type":"application/json"},url:`${e}/operation/${i}`,method:"POST",responseType:"json",body:u});return r?u=>M(r.getToken()).pipe(j(a=>o(u,a).pipe(ue(r))),E(({response:a})=>a)):u=>o(u).pipe(E(({response:a})=>a))},createCommand(i,o){const u=(c,s)=>O({...t,headers:{Authorization:s,"Content-Type":"application/json"},url:`${e}/command/${i}`,method:"POST",responseType:"json",body:c});function a(c){return r?M(r.getToken()).pipe(j(s=>u(c,s).pipe(ue(r))),E(({response:s})=>s)):u(c).pipe(E(({response:s})=>s))}return a.handle=c=>a(c).pipe(E(s=>({isSuccess:!0,result:s})),Re(s=>s instanceof W&&s.status===422?te({isSuccess:!0,result:s.response}):te({isSuccess:!1,error:s})),E(s=>Xt(s,o))),a}}}function Jt(){return e=>e.pipe(Ce((r,t)=>r&&t,!0))}function Qt(){return e=>e.pipe(Ce((r,t)=>({...r,...t}),{}))}_.handleCommandResponse=At,_.mkCqrsClient=Yt,_.reduceBoolean=Jt,_.reduceObject=Qt,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,4 @@
1
+ import { MonoTypeOperatorFunction } from 'rxjs';
2
+ import { TokenProvider } from '@leancodepl/cqrs-client-base';
3
+ export default function authGuard<T>(tokenProvider: TokenProvider): MonoTypeOperatorFunction<T>;
4
+ //# sourceMappingURL=authGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authGuard.d.ts","sourceRoot":"","sources":["../../src/lib/authGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,wBAAwB,EAA8B,MAAM,MAAM,CAAA;AAGjF,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAgB9F"}
@@ -1,5 +1,5 @@
1
- import { OperatorFunction } from "rxjs";
2
- import type { ReducerDescription, ValidationErrorsHandler } from "@leancodepl/validation";
1
+ import { OperatorFunction } from 'rxjs';
2
+ import { ReducerDescription, ValidationErrorsHandler } from '@leancodepl/validation';
3
3
  /**
4
4
  * Handles command responses with RxJS operators for validation error processing.
5
5
  *
@@ -20,3 +20,4 @@ import type { ReducerDescription, ValidationErrorsHandler } from "@leancodepl/va
20
20
  * ```
21
21
  */
22
22
  export declare function handleCommandResponse<TErrorCodes extends Record<string, number>, THandlerResult>(handlerFunc: (handler: ValidationErrorsHandler<TErrorCodes, never>) => (reducer: ReducerDescription<THandlerResult, any>) => any): OperatorFunction<ValidationErrorsHandler<TErrorCodes, never>, THandlerResult>;
23
+ //# sourceMappingURL=handleCommandResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleCommandResponse.d.ts","sourceRoot":"","sources":["../../src/lib/handleCommandResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAiB,MAAM,MAAM,CAAA;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAEzF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,EAC9F,WAAW,EAAE,CACX,OAAO,EAAE,uBAAuB,CAAC,WAAW,EAAE,KAAK,CAAC,KACjD,CAAC,OAAO,EAAE,kBAAkB,CAAC,cAAc,EAAE,GAAG,CAAC,KAAK,GAAG,GAC7D,gBAAgB,CAAC,uBAAuB,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,cAAc,CAAC,CAgB/E"}
@@ -1,5 +1,5 @@
1
- import { AjaxConfig } from "rxjs/ajax";
2
- import { CommandResult, TokenProvider } from "@leancodepl/cqrs-client-base";
1
+ import { AjaxConfig } from 'rxjs/ajax';
2
+ import { CommandResult, TokenProvider } from '@leancodepl/cqrs-client-base';
3
3
  /**
4
4
  * Creates RxJS-based CQRS client for reactive command and query operations.
5
5
  *
@@ -25,15 +25,16 @@ export declare function mkCqrsClient({ cqrsEndpoint, tokenProvider, ajaxOptions,
25
25
  ajaxOptions?: Omit<AjaxConfig, "body" | "headers" | "method" | "responseType" | "url">;
26
26
  tokenHeader?: string;
27
27
  }): {
28
- createQuery<TQuery, TResult>(type: string): (dto: TQuery) => import("rxjs").Observable<TResult>;
29
- createOperation<TOperation, TResult>(type: string): (dto: TOperation) => import("rxjs").Observable<TResult>;
28
+ createQuery<TQuery, TResult>(type: string): (dto: TQuery) => import('rxjs').Observable<TResult>;
29
+ createOperation<TOperation, TResult>(type: string): (dto: TOperation) => import('rxjs').Observable<TResult>;
30
30
  createCommand<TCommand, TErrorCodes extends {
31
31
  [name: string]: number;
32
32
  }>(type: string, errorCodesMap: TErrorCodes): {
33
- (dto: TCommand): import("rxjs").Observable<CommandResult<TErrorCodes>>;
34
- handle(dto: TCommand): import("rxjs").Observable<import("@leancodepl/validation").ValidationErrorsHandler<TErrorCodes & {
33
+ (dto: TCommand): import('rxjs').Observable<CommandResult<TErrorCodes>>;
34
+ handle(dto: TCommand): import('rxjs').Observable<import('@leancodepl/validation').ValidationErrorsHandler<TErrorCodes & {
35
35
  readonly success: -1;
36
36
  readonly failure: -2;
37
37
  }, never>>;
38
38
  };
39
39
  };
40
+ //# sourceMappingURL=mkCqrsClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mkCqrsClient.d.ts","sourceRoot":"","sources":["../../src/lib/mkCqrsClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,UAAU,EAAa,MAAM,WAAW,CAAA;AAEvD,OAAO,EAAe,aAAa,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAIxF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAA6B,GAC9B,EAAE;IACD,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,WAAW,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,cAAc,GAAG,KAAK,CAAC,CAAA;IACtF,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;gBAEe,MAAM,EAAE,OAAO,QAAQ,MAAM,SAexB,MAAM;oBASP,UAAU,EAAE,OAAO,QAAQ,MAAM,SAehC,UAAU;kBASb,QAAQ,EAAE,WAAW,SAAS;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,QAAQ,MAAM,iBAAiB,WAAW;cAc3F,QAAQ;oBAWP,QAAQ;;;;;EA4BjC"}
@@ -1,4 +1,4 @@
1
- import { OperatorFunction } from "rxjs";
1
+ import { OperatorFunction } from 'rxjs';
2
2
  /**
3
3
  * Reduces boolean values in RxJS streams using logical AND operation.
4
4
  *
@@ -17,3 +17,4 @@ import { OperatorFunction } from "rxjs";
17
17
  * ```
18
18
  */
19
19
  export declare function reduceBoolean(): OperatorFunction<boolean, boolean>;
20
+ //# sourceMappingURL=reduceBoolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduceBoolean.d.ts","sourceRoot":"","sources":["../../src/lib/reduceBoolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAU,MAAM,MAAM,CAAA;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,IAAI,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAElE"}
@@ -1,4 +1,4 @@
1
- import { OperatorFunction } from "rxjs";
1
+ import { OperatorFunction } from 'rxjs';
2
2
  type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
3
3
  /**
4
4
  * Reduces object values in RxJS streams by merging properties.
@@ -19,3 +19,4 @@ type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x
19
19
  */
20
20
  export declare function reduceObject<T>(): OperatorFunction<T, Partial<UnionToIntersection<T>>>;
21
21
  export {};
22
+ //# sourceMappingURL=reduceObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduceObject.d.ts","sourceRoot":"","sources":["../../src/lib/reduceObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAU,MAAM,MAAM,CAAA;AAE/C,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;AAE7G;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAEtF"}
package/package.json CHANGED
@@ -1,10 +1,22 @@
1
1
  {
2
2
  "name": "@leancodepl/rx-cqrs-client",
3
- "version": "9.7.2",
3
+ "version": "9.7.3",
4
4
  "license": "Apache-2.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
5
17
  "dependencies": {
6
- "@leancodepl/cqrs-client-base": "9.7.2",
7
- "@leancodepl/validation": "9.7.2",
18
+ "@leancodepl/cqrs-client-base": "9.7.3",
19
+ "@leancodepl/validation": "9.7.3",
8
20
  "rxjs": ">=7.0.0"
9
21
  },
10
22
  "devDependencies": {
@@ -15,7 +27,7 @@
15
27
  "registry": "https://registry.npmjs.org/"
16
28
  },
17
29
  "engines": {
18
- "node": ">=18.0.0"
30
+ "node": ">=22.0.0"
19
31
  },
20
32
  "repository": {
21
33
  "type": "git",
@@ -39,16 +51,9 @@
39
51
  "url": "https://leancode.co"
40
52
  },
41
53
  "sideEffects": false,
42
- "exports": {
43
- "./package.json": "./package.json",
44
- ".": {
45
- "module": "./index.esm.js",
46
- "types": "./index.d.ts",
47
- "import": "./index.cjs.mjs",
48
- "default": "./index.cjs.js"
49
- }
50
- },
51
- "module": "./index.esm.js",
52
- "main": "./index.cjs.js",
53
- "types": "./index.d.ts"
54
+ "files": [
55
+ "dist",
56
+ "CHANGELOG.md",
57
+ "!**/*.tsbuildinfo"
58
+ ]
54
59
  }
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;
package/index.cjs.js DELETED
@@ -1,185 +0,0 @@
1
- 'use strict';
2
-
3
- var rxjs = require('rxjs');
4
- var operators = require('rxjs/operators');
5
- var ajax = require('rxjs/ajax');
6
- var validation = require('@leancodepl/validation');
7
-
8
- /**
9
- * Handles command responses with RxJS operators for validation error processing.
10
- *
11
- * Creates an operator that processes validation error handlers and transforms them
12
- * into the desired result type using a reducer pattern.
13
- *
14
- * @param handlerFunc - Function that processes validation error handlers
15
- * @returns RxJS operator function for handling command responses
16
- * @example
17
- * ```typescript
18
- * import { handleCommandResponse } from '@leancodepl/rx-cqrs-client';
19
- *
20
- * const handler = handleCommandResponse((handle) =>
21
- * handle('success', () => 'Success!')
22
- * .handle('failure', () => 'Failed!')
23
- * .check()
24
- * );
25
- * ```
26
- */ function handleCommandResponse(handlerFunc) {
27
- return (source)=>source.pipe(operators.concatMap((handler)=>{
28
- const subj = new rxjs.ReplaySubject();
29
- handlerFunc(handler)({
30
- reducer: (prev, cur)=>subj.next(cur),
31
- initialValue: null
32
- });
33
- subj.complete();
34
- return subj;
35
- }));
36
- }
37
-
38
- function authGuard(tokenProvider) {
39
- return (response)=>response.pipe(operators.retryWhen((errors$)=>errors$.pipe(operators.mergeMap((error, i)=>{
40
- if (i === 0 && error.status === 401) {
41
- return rxjs.from(tokenProvider.invalidateToken()).pipe(operators.mergeMap((success)=>success ? rxjs.of(success) : rxjs.throwError(()=>error)));
42
- }
43
- return rxjs.throwError(()=>error);
44
- }))));
45
- }
46
-
47
- /**
48
- * Creates RxJS-based CQRS client for reactive command and query operations.
49
- *
50
- * Provides observable-based methods for CQRS operations with automatic authentication,
51
- * retry logic, and error handling.
52
- *
53
- * @param cqrsEndpoint - Base URL for CQRS API endpoints
54
- * @param tokenProvider - Optional token provider for authentication
55
- * @param ajaxOptions - Optional RxJS Ajax configuration options
56
- * @param tokenHeader - Header name for authentication token (default: "Authorization")
57
- * @returns Object with `createQuery`, `createOperation`, and `createCommand` observable factories
58
- * @example
59
- * ```typescript
60
- * const client = mkCqrsClient({
61
- * cqrsEndpoint: 'https://api.example.com',
62
- * tokenProvider: { getToken: () => Promise.resolve('token') }
63
- * });
64
- * ```
65
- */ function mkCqrsClient({ cqrsEndpoint, tokenProvider, ajaxOptions, tokenHeader = "Authorization" }) {
66
- return {
67
- createQuery (type) {
68
- const queryCall = (dto, token)=>ajax.ajax({
69
- ...ajaxOptions,
70
- headers: {
71
- [tokenHeader]: token,
72
- "Content-Type": "application/json"
73
- },
74
- url: `${cqrsEndpoint}/query/${type}`,
75
- method: "POST",
76
- responseType: "json",
77
- body: dto
78
- });
79
- if (tokenProvider) {
80
- return (dto)=>rxjs.from(tokenProvider.getToken()).pipe(operators.mergeMap((token)=>queryCall(dto, token).pipe(authGuard(tokenProvider))), operators.map(({ response })=>response));
81
- }
82
- return (dto)=>queryCall(dto).pipe(operators.map(({ response })=>response));
83
- },
84
- createOperation (type) {
85
- const operationCall = (dto, token)=>ajax.ajax({
86
- ...ajaxOptions,
87
- headers: {
88
- Authorization: token,
89
- "Content-Type": "application/json"
90
- },
91
- url: `${cqrsEndpoint}/operation/${type}`,
92
- method: "POST",
93
- responseType: "json",
94
- body: dto
95
- });
96
- if (tokenProvider) {
97
- return (dto)=>rxjs.from(tokenProvider.getToken()).pipe(operators.mergeMap((token)=>operationCall(dto, token).pipe(authGuard(tokenProvider))), operators.map(({ response })=>response));
98
- }
99
- return (dto)=>operationCall(dto).pipe(operators.map(({ response })=>response));
100
- },
101
- createCommand (type, errorCodesMap) {
102
- const commandCall = (dto, token)=>ajax.ajax({
103
- ...ajaxOptions,
104
- headers: {
105
- Authorization: token,
106
- "Content-Type": "application/json"
107
- },
108
- url: `${cqrsEndpoint}/command/${type}`,
109
- method: "POST",
110
- responseType: "json",
111
- body: dto
112
- });
113
- function call(dto) {
114
- if (tokenProvider) {
115
- return rxjs.from(tokenProvider.getToken()).pipe(operators.mergeMap((token)=>commandCall(dto, token).pipe(authGuard(tokenProvider))), operators.map(({ response })=>response));
116
- }
117
- return commandCall(dto).pipe(operators.map(({ response })=>response));
118
- }
119
- call.handle = (dto)=>call(dto).pipe(operators.map((result)=>({
120
- isSuccess: true,
121
- result
122
- })), rxjs.catchError((e)=>{
123
- if (e instanceof ajax.AjaxError && e.status === 422) {
124
- return rxjs.of({
125
- isSuccess: true,
126
- result: e.response
127
- });
128
- }
129
- return rxjs.of({
130
- isSuccess: false,
131
- error: e
132
- });
133
- }), operators.map((response)=>validation.handleResponse(response, errorCodesMap)));
134
- return call;
135
- }
136
- };
137
- }
138
-
139
- /**
140
- * Reduces boolean values in RxJS streams using logical AND operation.
141
- *
142
- * Creates an operator that combines multiple boolean values into a single result
143
- * by applying logical AND. Returns true only if all values are true.
144
- *
145
- * @returns RxJS operator function that reduces boolean values
146
- * @example
147
- * ```typescript
148
- * import { of } from 'rxjs';
149
- * import { reduceBoolean } from '@leancodepl/rx-cqrs-client';
150
- *
151
- * of(true, true, false).pipe(reduceBoolean()).subscribe(result => {
152
- * console.log(result); // false
153
- * });
154
- * ```
155
- */ function reduceBoolean() {
156
- return (source)=>source.pipe(rxjs.reduce((prev, cur)=>prev && cur, true));
157
- }
158
-
159
- /**
160
- * Reduces object values in RxJS streams by merging properties.
161
- *
162
- * Creates an operator that combines multiple objects into a single result
163
- * by spreading properties. Later objects override earlier ones.
164
- *
165
- * @returns RxJS operator function that reduces object values
166
- * @example
167
- * ```typescript
168
- * import { of } from 'rxjs';
169
- * import { reduceObject } from '@leancodepl/rx-cqrs-client';
170
- *
171
- * of({ a: 1 }, { b: 2 }, { a: 3 }).pipe(reduceObject()).subscribe(result => {
172
- * console.log(result); // { a: 3, b: 2 }
173
- * });
174
- * ```
175
- */ function reduceObject() {
176
- return (source)=>source.pipe(rxjs.reduce((prev, cur)=>({
177
- ...prev,
178
- ...cur
179
- }), {}));
180
- }
181
-
182
- exports.handleCommandResponse = handleCommandResponse;
183
- exports.mkCqrsClient = mkCqrsClient;
184
- exports.reduceBoolean = reduceBoolean;
185
- exports.reduceObject = reduceObject;
package/index.cjs.mjs DELETED
@@ -1,2 +0,0 @@
1
- export * from './index.cjs.js';
2
- export { _default as default } from './index.cjs.default.js';
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
package/index.esm.js DELETED
@@ -1,180 +0,0 @@
1
- import { ReplaySubject, from, of, throwError, catchError, reduce } from 'rxjs';
2
- import { concatMap, retryWhen, mergeMap, map } from 'rxjs/operators';
3
- import { AjaxError, ajax } from 'rxjs/ajax';
4
- import { handleResponse } from '@leancodepl/validation';
5
-
6
- /**
7
- * Handles command responses with RxJS operators for validation error processing.
8
- *
9
- * Creates an operator that processes validation error handlers and transforms them
10
- * into the desired result type using a reducer pattern.
11
- *
12
- * @param handlerFunc - Function that processes validation error handlers
13
- * @returns RxJS operator function for handling command responses
14
- * @example
15
- * ```typescript
16
- * import { handleCommandResponse } from '@leancodepl/rx-cqrs-client';
17
- *
18
- * const handler = handleCommandResponse((handle) =>
19
- * handle('success', () => 'Success!')
20
- * .handle('failure', () => 'Failed!')
21
- * .check()
22
- * );
23
- * ```
24
- */ function handleCommandResponse(handlerFunc) {
25
- return (source)=>source.pipe(concatMap((handler)=>{
26
- const subj = new ReplaySubject();
27
- handlerFunc(handler)({
28
- reducer: (prev, cur)=>subj.next(cur),
29
- initialValue: null
30
- });
31
- subj.complete();
32
- return subj;
33
- }));
34
- }
35
-
36
- function authGuard(tokenProvider) {
37
- return (response)=>response.pipe(retryWhen((errors$)=>errors$.pipe(mergeMap((error, i)=>{
38
- if (i === 0 && error.status === 401) {
39
- return from(tokenProvider.invalidateToken()).pipe(mergeMap((success)=>success ? of(success) : throwError(()=>error)));
40
- }
41
- return throwError(()=>error);
42
- }))));
43
- }
44
-
45
- /**
46
- * Creates RxJS-based CQRS client for reactive command and query operations.
47
- *
48
- * Provides observable-based methods for CQRS operations with automatic authentication,
49
- * retry logic, and error handling.
50
- *
51
- * @param cqrsEndpoint - Base URL for CQRS API endpoints
52
- * @param tokenProvider - Optional token provider for authentication
53
- * @param ajaxOptions - Optional RxJS Ajax configuration options
54
- * @param tokenHeader - Header name for authentication token (default: "Authorization")
55
- * @returns Object with `createQuery`, `createOperation`, and `createCommand` observable factories
56
- * @example
57
- * ```typescript
58
- * const client = mkCqrsClient({
59
- * cqrsEndpoint: 'https://api.example.com',
60
- * tokenProvider: { getToken: () => Promise.resolve('token') }
61
- * });
62
- * ```
63
- */ function mkCqrsClient({ cqrsEndpoint, tokenProvider, ajaxOptions, tokenHeader = "Authorization" }) {
64
- return {
65
- createQuery (type) {
66
- const queryCall = (dto, token)=>ajax({
67
- ...ajaxOptions,
68
- headers: {
69
- [tokenHeader]: token,
70
- "Content-Type": "application/json"
71
- },
72
- url: `${cqrsEndpoint}/query/${type}`,
73
- method: "POST",
74
- responseType: "json",
75
- body: dto
76
- });
77
- if (tokenProvider) {
78
- return (dto)=>from(tokenProvider.getToken()).pipe(mergeMap((token)=>queryCall(dto, token).pipe(authGuard(tokenProvider))), map(({ response })=>response));
79
- }
80
- return (dto)=>queryCall(dto).pipe(map(({ response })=>response));
81
- },
82
- createOperation (type) {
83
- const operationCall = (dto, token)=>ajax({
84
- ...ajaxOptions,
85
- headers: {
86
- Authorization: token,
87
- "Content-Type": "application/json"
88
- },
89
- url: `${cqrsEndpoint}/operation/${type}`,
90
- method: "POST",
91
- responseType: "json",
92
- body: dto
93
- });
94
- if (tokenProvider) {
95
- return (dto)=>from(tokenProvider.getToken()).pipe(mergeMap((token)=>operationCall(dto, token).pipe(authGuard(tokenProvider))), map(({ response })=>response));
96
- }
97
- return (dto)=>operationCall(dto).pipe(map(({ response })=>response));
98
- },
99
- createCommand (type, errorCodesMap) {
100
- const commandCall = (dto, token)=>ajax({
101
- ...ajaxOptions,
102
- headers: {
103
- Authorization: token,
104
- "Content-Type": "application/json"
105
- },
106
- url: `${cqrsEndpoint}/command/${type}`,
107
- method: "POST",
108
- responseType: "json",
109
- body: dto
110
- });
111
- function call(dto) {
112
- if (tokenProvider) {
113
- return from(tokenProvider.getToken()).pipe(mergeMap((token)=>commandCall(dto, token).pipe(authGuard(tokenProvider))), map(({ response })=>response));
114
- }
115
- return commandCall(dto).pipe(map(({ response })=>response));
116
- }
117
- call.handle = (dto)=>call(dto).pipe(map((result)=>({
118
- isSuccess: true,
119
- result
120
- })), catchError((e)=>{
121
- if (e instanceof AjaxError && e.status === 422) {
122
- return of({
123
- isSuccess: true,
124
- result: e.response
125
- });
126
- }
127
- return of({
128
- isSuccess: false,
129
- error: e
130
- });
131
- }), map((response)=>handleResponse(response, errorCodesMap)));
132
- return call;
133
- }
134
- };
135
- }
136
-
137
- /**
138
- * Reduces boolean values in RxJS streams using logical AND operation.
139
- *
140
- * Creates an operator that combines multiple boolean values into a single result
141
- * by applying logical AND. Returns true only if all values are true.
142
- *
143
- * @returns RxJS operator function that reduces boolean values
144
- * @example
145
- * ```typescript
146
- * import { of } from 'rxjs';
147
- * import { reduceBoolean } from '@leancodepl/rx-cqrs-client';
148
- *
149
- * of(true, true, false).pipe(reduceBoolean()).subscribe(result => {
150
- * console.log(result); // false
151
- * });
152
- * ```
153
- */ function reduceBoolean() {
154
- return (source)=>source.pipe(reduce((prev, cur)=>prev && cur, true));
155
- }
156
-
157
- /**
158
- * Reduces object values in RxJS streams by merging properties.
159
- *
160
- * Creates an operator that combines multiple objects into a single result
161
- * by spreading properties. Later objects override earlier ones.
162
- *
163
- * @returns RxJS operator function that reduces object values
164
- * @example
165
- * ```typescript
166
- * import { of } from 'rxjs';
167
- * import { reduceObject } from '@leancodepl/rx-cqrs-client';
168
- *
169
- * of({ a: 1 }, { b: 2 }, { a: 3 }).pipe(reduceObject()).subscribe(result => {
170
- * console.log(result); // { a: 3, b: 2 }
171
- * });
172
- * ```
173
- */ function reduceObject() {
174
- return (source)=>source.pipe(reduce((prev, cur)=>({
175
- ...prev,
176
- ...cur
177
- }), {}));
178
- }
179
-
180
- export { handleCommandResponse, mkCqrsClient, reduceBoolean, reduceObject };
package/src/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { handleCommandResponse } from "./lib/handleCommandResponse";
2
- export { mkCqrsClient } from "./lib/mkCqrsClient";
3
- export { reduceBoolean } from "./lib/reduceBoolean";
4
- export { reduceObject } from "./lib/reduceObject";
@@ -1,3 +0,0 @@
1
- import { MonoTypeOperatorFunction } from "rxjs";
2
- import { TokenProvider } from "@leancodepl/cqrs-client-base";
3
- export default function authGuard<T>(tokenProvider: TokenProvider): MonoTypeOperatorFunction<T>;