@graphql-box/worker-client 3.2.0 → 3.3.2

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.
@@ -1,2 +1,2 @@
1
- import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";import e from"@babel/runtime/helpers/objectWithoutProperties";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/classCallCheck";import n from"@babel/runtime/helpers/createClass";import o from"@babel/runtime/helpers/defineProperty";import a from"@babel/runtime/helpers/applyDecoratedDescriptor";import s from"lodash/isPlainObject";import c from"lodash/castArray";import i from"@babel/runtime/regenerator";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.map.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.promise.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import{QUERY as u,SUBSCRIPTION as p}from"@graphql-box/core";import{hashRequest as h,EventAsyncIterator as l,rehydrateCacheMetadata as b,dehydrateCacheMetadata as f}from"@graphql-box/helpers";import m from"eventemitter3";import{v1 as d}from"uuid";import{handleMessage as g}from"@cachemap/core-worker";import{forAwaitEach as v,isAsyncIterable as y}from"iterall";var x,w,j,_="request_executed";function O(){return function(r,n,o){var a,s=o.value;s&&(o.value=(a=t(i.mark((function r(){var n,o,a,c=this,u=arguments;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=u.length,o=new Array(n),a=0;a<n;a++)o[a]=u[a];return r.prev=1,r.abrupt("return",new Promise(function(){var r=t(i.mark((function t(r){var n,a,u,p,h,l,b;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=o[2],a=n.debugManager,u=e(n,["debugManager"]),a){t.next=8;break}return t.t0=r,t.next=5,s.apply(c,o);case 5:return t.t1=t.sent,(0,t.t0)(t.t1),t.abrupt("return");case 8:return p=a.now(),t.next=11,s.apply(c,o);case 11:h=t.sent,l=a.now(),b=l-p,r(h),a.emit("request_executed",{context:u,options:o[1],request:o[0],result:h,stats:{duration:b,endTime:l,startTime:p}});case 16:case"end":return t.stop()}}),t)})));return function(e){return r.apply(this,arguments)}}()));case 5:return r.prev=5,r.t0=r.catch(1),r.abrupt("return",Promise.reject(r.t0));case 8:case"end":return r.stop()}}),r,null,[[1,5]])}))),function(){return a.apply(this,arguments)}))}}function k(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function q(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?k(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):k(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var M=(x=O(),w=O(),a((j=function(){function a(n){var c,u=this;r(this,a),o(this,"_cache",void 0),o(this,"_debugManager",void 0),o(this,"_eventEmitter",void 0),o(this,"_pending",new Map),o(this,"_worker",void 0),o(this,"_onMessage",(c=t(i.mark((function t(r){var n,o,a,c,p,h,l,f,m;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.data,s(n)){t.next=3;break}return t.abrupt("return");case 3:if(a=(o=n).context,c=o.method,p=o.result,"graphqlBox"===o.type&&s(p)){t.next=6;break}return t.abrupt("return");case 6:if(h=p._cacheMetadata,l=e(p,["_cacheMetadata"]),f=q(q({},l),{},{requestID:a.boxID}),h&&(f._cacheMetadata=b(h)),"request"!==c){t.next=16;break}if(m=u._pending.get(a.boxID)){t.next=13;break}return t.abrupt("return");case 13:m.resolve(f),t.next=17;break;case 16:("subscribe"===c||a.hasDeferOrStream)&&u._eventEmitter.emit(a.boxID,f);case 17:case"end":return t.stop()}}),t)}))),function(e){return c.apply(this,arguments)}));var p=[];if(s(n)||p.push(new TypeError("@graphql-box/client expected options to ba a plain object.")),n.cache||p.push(new TypeError("@graphql-box/client expected options.cache.")),n.worker||p.push(new TypeError("@graphql-box/client expected options.worker.")),p.length)throw p;this._cache=n.cache,this._debugManager=n.debugManager?n.debugManager():null,this._eventEmitter=new m,this._worker=n.worker,this._addEventListener()}var f,g,v,y;return n(a,[{key:"cache",get:function(){return this._cache}},{key:"request",value:(y=t(i.mark((function e(t){var r,n,o=arguments;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=o.length>1&&void 0!==o[1]?o[1]:{},n=o.length>2&&void 0!==o[2]?o[2]:{},e.abrupt("return",this._request(t,r,this._getRequestContext(u,t,n)));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"subscribe",value:(v=t(i.mark((function e(t){var r,n=arguments;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",this._subscribe(t,r,this._getRequestContext(p,t)));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"_addEventListener",value:function(){this._worker.addEventListener("message",this._onMessage)}},{key:"_getRequestContext",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return q({boxID:d(),debugManager:this._debugManager,fieldTypeMap:new Map,operation:e,operationName:"",queryFiltered:!1,request:t,whitelistHash:h(t)},r)}},{key:"_request",value:(g=t(i.mark((function e(t,r,n){var o,s=this;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,n.hasDeferOrStream){e.next=3;break}return e.abrupt("return",new Promise((function(e){s._worker.postMessage({context:a._getMessageContext(n),method:"request",options:r,request:t,type:"graphqlBox"}),s._pending.set(n.boxID,{resolve:e})})));case 3:return this._worker.postMessage({context:a._getMessageContext(n),method:"request",options:r,request:t,type:"graphqlBox"}),o=new l(this._eventEmitter,n.boxID),e.abrupt("return",o.getIterator());case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",{errors:c(e.t0)});case 11:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e,t,r){return g.apply(this,arguments)})},{key:"_subscribe",value:(f=t(i.mark((function e(t,r,n){var o;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,this._worker.postMessage({context:a._getMessageContext(n),method:"subscribe",options:r,request:t,type:"graphqlBox"}),o=new l(this._eventEmitter,n.boxID),e.abrupt("return",o.getIterator());case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return",{errors:c(e.t0)});case 9:case"end":return e.stop()}}),e,this,[[0,6]])}))),function(e,t,r){return f.apply(this,arguments)})}],[{key:"_getMessageContext",value:function(e){var t=e.boxID,r=e.hasDeferOrStream;return{boxID:t,hasDeferOrStream:void 0!==r&&r}}}]),a}()).prototype,"_request",[x],Object.getOwnPropertyDescriptor(j.prototype,"_request"),j.prototype),a(j.prototype,"_subscribe",[w],Object.getOwnPropertyDescriptor(j.prototype,"_subscribe"),j.prototype),j);function D(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function P(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?D(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):D(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var E=self,I=E.addEventListener,C=E.postMessage;function B(){return(B=t(i.mark((function t(r,n,o,a,s){var c,u,p,h,l;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.request(r,o,a);case 2:if(c=t.sent,y(c)){t.next=9;break}return p=(u=c)._cacheMetadata,h=e(u,["_cacheMetadata"]),l=P({},h),p&&(l._cacheMetadata=f(p)),C({context:a,method:n,result:l,type:"graphqlBox"}),t.abrupt("return");case 9:v(c,(function(t){var r=t._cacheMetadata,o=P({},e(t,["_cacheMetadata"]));r&&(o._cacheMetadata=f(r)),C({context:a,method:n,result:o,type:"graphqlBox"})}));case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function S(){return(S=t(i.mark((function t(r,n,o,a,s){var c;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.subscribe(r,o,a);case 2:c=t.sent,y(c)?v(c,(function(t){var r=t._cacheMetadata,o=P({},e(t,["_cacheMetadata"]));r&&(o._cacheMetadata=f(r)),C({context:a,method:n,result:o,type:"graphqlBox"})})):C({context:a,method:n,result:void 0,type:"graphqlBox"});case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function T(e,t){var r=e,n=r.context,o=r.method,a=r.options,s=r.request;"request"===o?function(e,t,r,n,o){B.apply(this,arguments)}(s,o,a,n,t):"subscribe"===o&&function(e,t,r,n,o){S.apply(this,arguments)}(s,o,a,n,t)}function L(e){return R.apply(this,arguments)}function R(){return(R=t(i.mark((function e(t){var r,n;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=function(e){var t=e.data;if(s(t)){var n=t.type;"graphqlBox"===n?T(t,r):"cachemap"===n&&r.cache&&g(t,r.cache)}},r=t.client,I("message",n);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}export default M;export{_ as REQUEST_EXECUTED,L as registerWorker};
1
+ import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";import e from"@babel/runtime/helpers/objectWithoutProperties";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/classCallCheck";import n from"@babel/runtime/helpers/createClass";import o from"@babel/runtime/helpers/defineProperty";import a from"@babel/runtime/helpers/applyDecoratedDescriptor";import s from"lodash/isPlainObject";import c from"lodash/castArray";import i from"@babel/runtime/regenerator";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.map.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.promise.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import{QUERY as u,SUBSCRIPTION as p}from"@graphql-box/core";import{hashRequest as h,EventAsyncIterator as l,deserializeErrors as b,rehydrateCacheMetadata as f,dehydrateCacheMetadata as m,serializeErrors as d}from"@graphql-box/helpers";import g from"eventemitter3";import{v1 as v}from"uuid";import{handleMessage as y}from"@cachemap/core-worker";import{forAwaitEach as x,isAsyncIterable as w}from"iterall";var j,_,O,k="request_executed";function q(){return function(r,n,o){var a,s=o.value;s&&(o.value=(a=t(i.mark((function r(){var n,o,a,c=this,u=arguments;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=u.length,o=new Array(n),a=0;a<n;a++)o[a]=u[a];return r.prev=1,r.abrupt("return",new Promise(function(){var r=t(i.mark((function t(r){var n,a,u,p,h,l,b;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=o[2],a=n.debugManager,u=e(n,["debugManager"]),a){t.next=8;break}return t.t0=r,t.next=5,s.apply(c,o);case 5:return t.t1=t.sent,(0,t.t0)(t.t1),t.abrupt("return");case 8:return p=a.now(),t.next=11,s.apply(c,o);case 11:h=t.sent,l=a.now(),b=l-p,r(h),a.emit("request_executed",{context:u,options:o[1],request:o[0],result:h,stats:{duration:b,endTime:l,startTime:p}});case 16:case"end":return t.stop()}}),t)})));return function(e){return r.apply(this,arguments)}}()));case 5:return r.prev=5,r.t0=r.catch(1),r.abrupt("return",Promise.reject(r.t0));case 8:case"end":return r.stop()}}),r,null,[[1,5]])}))),function(){return a.apply(this,arguments)}))}}function M(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function D(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?M(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):M(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var P=(j=q(),_=q(),a((O=function(){function a(n){var c,u=this;r(this,a),o(this,"_cache",void 0),o(this,"_debugManager",void 0),o(this,"_eventEmitter",void 0),o(this,"_pending",new Map),o(this,"_worker",void 0),o(this,"_onMessage",(c=t(i.mark((function t(r){var n,o,a,c,p,h,l,m,d;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.data,s(n)){t.next=3;break}return t.abrupt("return");case 3:if(a=(o=n).context,c=o.method,p=o.result,"graphqlBox"===o.type&&s(p)){t.next=6;break}return t.abrupt("return");case 6:if(h=p._cacheMetadata,l=e(p,["_cacheMetadata"]),m=b(D(D({},l),{},{requestID:a.boxID})),h&&(m._cacheMetadata=f(h)),"request"!==c){t.next=16;break}if(d=u._pending.get(a.boxID)){t.next=13;break}return t.abrupt("return");case 13:d.resolve(m),t.next=17;break;case 16:("subscribe"===c||a.hasDeferOrStream)&&u._eventEmitter.emit(a.boxID,m);case 17:case"end":return t.stop()}}),t)}))),function(e){return c.apply(this,arguments)}));var p=[];if(s(n)||p.push(new TypeError("@graphql-box/client expected options to ba a plain object.")),n.cache||p.push(new TypeError("@graphql-box/client expected options.cache.")),n.worker||p.push(new TypeError("@graphql-box/client expected options.worker.")),p.length)throw p;this._cache=n.cache,this._debugManager=n.debugManager?n.debugManager():null,this._eventEmitter=new g,this._worker=n.worker,this._addEventListener()}var m,d,y,x;return n(a,[{key:"cache",get:function(){return this._cache}},{key:"request",value:(x=t(i.mark((function e(t){var r,n,o=arguments;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=o.length>1&&void 0!==o[1]?o[1]:{},n=o.length>2&&void 0!==o[2]?o[2]:{},e.abrupt("return",this._request(t,r,this._getRequestContext(u,t,n)));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"subscribe",value:(y=t(i.mark((function e(t){var r,n=arguments;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",this._subscribe(t,r,this._getRequestContext(p,t)));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"_addEventListener",value:function(){this._worker.addEventListener("message",this._onMessage)}},{key:"_getRequestContext",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return D({boxID:v(),debugManager:this._debugManager,fieldTypeMap:new Map,operation:e,operationName:"",queryFiltered:!1,request:t,whitelistHash:h(t)},r)}},{key:"_request",value:(d=t(i.mark((function e(t,r,n){var o,s=this;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,n.hasDeferOrStream){e.next=3;break}return e.abrupt("return",new Promise((function(e){s._worker.postMessage({context:a._getMessageContext(n),method:"request",options:r,request:t,type:"graphqlBox"}),s._pending.set(n.boxID,{resolve:e})})));case 3:return this._worker.postMessage({context:a._getMessageContext(n),method:"request",options:r,request:t,type:"graphqlBox"}),o=new l(this._eventEmitter,n.boxID),e.abrupt("return",o.getIterator());case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",{errors:c(e.t0)});case 11:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e,t,r){return d.apply(this,arguments)})},{key:"_subscribe",value:(m=t(i.mark((function e(t,r,n){var o;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,this._worker.postMessage({context:a._getMessageContext(n),method:"subscribe",options:r,request:t,type:"graphqlBox"}),o=new l(this._eventEmitter,n.boxID),e.abrupt("return",o.getIterator());case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return",{errors:c(e.t0)});case 9:case"end":return e.stop()}}),e,this,[[0,6]])}))),function(e,t,r){return m.apply(this,arguments)})}],[{key:"_getMessageContext",value:function(e){var t=e.boxID,r=e.hasDeferOrStream;return{boxID:t,hasDeferOrStream:void 0!==r&&r}}}]),a}()).prototype,"_request",[j],Object.getOwnPropertyDescriptor(O.prototype,"_request"),O.prototype),a(O.prototype,"_subscribe",[_],Object.getOwnPropertyDescriptor(O.prototype,"_subscribe"),O.prototype),O);function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function I(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?E(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):E(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var C=self,B=C.addEventListener,S=C.postMessage;function T(){return(T=t(i.mark((function t(r,n,o,a,s){var c,u,p,h,l;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.request(r,o,a);case 2:if(c=t.sent,w(c)){t.next=9;break}return p=(u=c)._cacheMetadata,h=e(u,["_cacheMetadata"]),l=I({},h),p&&(l._cacheMetadata=m(p)),S({context:a,method:n,result:d(l),type:"graphqlBox"}),t.abrupt("return");case 9:x(c,(function(t){var r=t._cacheMetadata,o=I({},e(t,["_cacheMetadata"]));r&&(o._cacheMetadata=m(r)),S({context:a,method:n,result:d(o),type:"graphqlBox"})}));case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function L(){return(L=t(i.mark((function t(r,n,o,a,s){var c;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.subscribe(r,o,a);case 2:if(c=t.sent,w(c)){t.next=6;break}return S({context:a,method:n,result:d(c),type:"graphqlBox"}),t.abrupt("return");case 6:x(c,(function(t){var r=t._cacheMetadata,o=I({},e(t,["_cacheMetadata"]));r&&(o._cacheMetadata=m(r)),S({context:a,method:n,result:d(o),type:"graphqlBox"})}));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function R(e,t){var r=e,n=r.context,o=r.method,a=r.options,s=r.request;"request"===o?function(e,t,r,n,o){T.apply(this,arguments)}(s,o,a,n,t):"subscribe"===o&&function(e,t,r,n,o){L.apply(this,arguments)}(s,o,a,n,t)}function A(e){return F.apply(this,arguments)}function F(){return(F=t(i.mark((function e(t){var r,n;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=function(e){var t=e.data;if(s(t)){var n=t.type;"graphqlBox"===n?R(t,r):"cachemap"===n&&r.cache&&y(t,r.cache)}},r=t.client,B("message",n);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}export default P;export{k as REQUEST_EXECUTED,A as registerWorker};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../worker-client/src/consts/index.ts","../worker-client/src/debug/log-request/index.ts","../worker-client/src/main/index.ts","../worker-client/src/register-worker/index.ts"],"sourcesContent":["export const REQUEST_EXECUTED = \"request_executed\";\n\nexport const REQUEST = \"request\";\nexport const SUBSCRIBE = \"subscribe\";\n\nexport const MESSAGE = \"message\";\n\nexport const GRAPHQL_BOX = \"graphqlBox\";\nexport const CACHEMAP = \"cachemap\";\n","import { RequestContext } from \"@graphql-box/core\";\nimport { REQUEST_EXECUTED } from \"../../consts\";\n\nexport default function logRequest() {\n return (\n _target: any,\n _propertyName: string,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>,\n ): void => {\n const method = descriptor.value;\n if (!method) return;\n\n descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {\n try {\n return new Promise(async resolve => {\n const { debugManager, ...otherContext } = args[2] as RequestContext;\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const startTime = debugManager.now();\n const result = await method.apply(this, args);\n const endTime = debugManager.now();\n const duration = endTime - startTime;\n resolve(result);\n\n debugManager.emit(REQUEST_EXECUTED, {\n context: otherContext,\n options: args[1],\n request: args[0],\n result,\n stats: { duration, endTime, startTime },\n });\n });\n } catch (error) {\n return Promise.reject(error);\n }\n };\n };\n}\n","import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ boxID, hasDeferOrStream = false }: RequestContext): MessageContext {\n return { boxID, hasDeferOrStream };\n }\n\n private _cache: WorkerCachemap;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\n\n constructor(options: UserOptions) {\n const errors: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ? options.debugManager() : null;\n this._eventEmitter = new EventEmitter();\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): WorkerCachemap {\n return this._cache;\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n boxID: uuid(),\n debugManager: this._debugManager,\n fieldTypeMap: new Map(),\n operation,\n operationName: \"\",\n queryFiltered: false,\n request,\n whitelistHash: hashRequest(request),\n ...context,\n };\n }\n\n private _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) return;\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = { ...otherProps, requestID: context.boxID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === REQUEST) {\n const pending = this._pending.get(context.boxID);\n\n if (!pending) {\n return;\n }\n\n pending.resolve(response);\n } else if (method === SUBSCRIBE || context.hasDeferOrStream) {\n this._eventEmitter.emit(context.boxID, response);\n }\n };\n\n @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\n try {\n if (!context.hasDeferOrStream) {\n return new Promise((resolve: PendingResolver) => {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.boxID, { resolve });\n });\n }\n\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n\n @logRequest()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n","import { handleMessage as handleCachemapMessage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (isAsyncIterable(subscribeResult)) {\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n if (_cacheMetadata) result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n } else {\n postMessage({ context, method, result: undefined, type: GRAPHQL_BOX });\n }\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) return;\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"names":["REQUEST_EXECUTED","logRequest","_target","_propertyName","descriptor","method","value","args","Promise","resolve","debugManager","otherContext","apply","_this","startTime","now","result","endTime","duration","emit","context","options","request","stats","reject","WorkerClient","Map","data","_isPlainObject","type","_cacheMetadata","otherProps","response","requestID","boxID","rehydrateCacheMetadata","pending","_pending","get","hasDeferOrStream","_eventEmitter","errors","push","TypeError","cache","worker","length","_cache","_debugManager","EventEmitter","_worker","_addEventListener","this","_request","_getRequestContext","QUERY","_subscribe","SUBSCRIPTION","addEventListener","_onMessage","operation","uuid","fieldTypeMap","operationName","queryFiltered","whitelistHash","hashRequest","_this2","postMessage","_getMessageContext","set","eventAsyncIterator","EventAsyncIterator","getIterator","_castArray","self","client","requestResult","isAsyncIterable","dehydrateCacheMetadata","forAwaitEach","subscribe","subscribeResult","undefined","handleMessage","handleRequest","handleSubscription","registerWorker","onMessage","handleCachemapMessage"],"mappings":"+2CAAaA,EAAmB,mBCGjB,SAASC,WACf,SACLC,EACAC,EACAC,SAEMC,EAASD,EAAWE,MACrBD,IAELD,EAAWE,mBAAQ,wHAAkCC,2BAAAA,4CAE1C,IAAIC,mCAAQ,WAAMC,yFACmBF,EAAK,GAAvCG,IAAAA,aAAiBC,wBAEpBD,8BACHD,WAAcJ,EAAOO,MAAMC,EAAMN,6EAI7BO,EAAYJ,EAAaK,gBACVV,EAAOO,MAAMC,EAAMN,WAAlCS,SACAC,EAAUP,EAAaK,MACvBG,EAAWD,EAAUH,EAC3BL,EAAQO,GAERN,EAAaS,KD5BS,mBC4Bc,CAClCC,QAAST,EACTU,QAASd,EAAK,GACde,QAASf,EAAK,GACdS,OAAAA,EACAO,MAAO,CAAEL,SAAAA,EAAUD,QAAAA,EAASH,UAAAA,kKAIzBN,QAAQgB,urBClBFC,KAoGlBxB,MAgCAA,+BAzHWoB,kIAHuB,IAAIK,+DA+DlB,sGAASC,IAAAA,KACvBC,EAAcD,uDAEXP,KAAkCO,GAAlCP,QAASf,IAAAA,OAAQW,IAAAA,OFtFF,iBEsFUa,MAEJD,EAAcZ,uDAInCc,EAAkCd,EAAlCc,eAAmBC,IAAef,sBACpCgB,SAAoCD,OAAYE,UAAWb,EAAQc,QAErEJ,IACFE,EAASF,eAAiBK,EAAuBL,IFrGhC,YEwGfzB,sBACI+B,EAAUvB,EAAKwB,SAASC,IAAIlB,EAAQc,0DAM1CE,EAAQ3B,QAAQuB,4BF9GG,cE+GV3B,GAAwBe,EAAQmB,mBACzC1B,EAAK2B,cAAcrB,KAAKC,EAAQc,MAAOF,iGApFnCS,EAAsB,MAEvBb,EAAcP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,OAAQgB,IAAAA,QAASC,IAAAA,QH9Db,YGgEjBjB,8CACFgF,CAAc/D,EAASjB,EAAQgB,EAASD,EAASwD,GHhE5B,cGiEZvE,+CACTiF,CAAmBhE,EAASjB,EAAQgB,EAASD,EAASwD,YAI5BW,oEAAf,oBACJC,iEAAAA,kBAAY7D,IAAAA,QACdC,EAAcD,QAEXE,EAASF,EAATE,KHtEe,eGwEnBA,EACFuD,EAAczD,EAAMiD,GHxEF,aGyET/C,GAAqB+C,EAAOhC,OACrC6C,EAAsB9D,EAAMiD,EAAOhC,SATMgC,IAAAA,OAa7ClB,EHjFqB,UGiFK8B"}
1
+ {"version":3,"file":"index.js","sources":["../worker-client/src/consts/index.ts","../worker-client/src/debug/log-request/index.ts","../worker-client/src/main/index.ts","../worker-client/src/register-worker/index.ts"],"sourcesContent":["export const REQUEST_EXECUTED = \"request_executed\";\n\nexport const REQUEST = \"request\";\nexport const SUBSCRIBE = \"subscribe\";\n\nexport const MESSAGE = \"message\";\n\nexport const GRAPHQL_BOX = \"graphqlBox\";\nexport const CACHEMAP = \"cachemap\";\n","import { RequestContext } from \"@graphql-box/core\";\nimport { REQUEST_EXECUTED } from \"../../consts\";\n\nexport default function logRequest() {\n return (\n _target: any,\n _propertyName: string,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>,\n ): void => {\n const method = descriptor.value;\n if (!method) return;\n\n descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {\n try {\n return new Promise(async resolve => {\n const { debugManager, ...otherContext } = args[2] as RequestContext;\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const startTime = debugManager.now();\n const result = await method.apply(this, args);\n const endTime = debugManager.now();\n const duration = endTime - startTime;\n resolve(result);\n\n debugManager.emit(REQUEST_EXECUTED, {\n context: otherContext,\n options: args[1],\n request: args[0],\n result,\n stats: { duration, endTime, startTime },\n });\n });\n } catch (error) {\n return Promise.reject(error);\n }\n };\n };\n}\n","import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ boxID, hasDeferOrStream = false }: RequestContext): MessageContext {\n return { boxID, hasDeferOrStream };\n }\n\n private _cache: WorkerCachemap;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\n\n constructor(options: UserOptions) {\n const errors: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ? options.debugManager() : null;\n this._eventEmitter = new EventEmitter();\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): WorkerCachemap {\n return this._cache;\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n boxID: uuid(),\n debugManager: this._debugManager,\n fieldTypeMap: new Map(),\n operation,\n operationName: \"\",\n queryFiltered: false,\n request,\n whitelistHash: hashRequest(request),\n ...context,\n };\n }\n\n private _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = deserializeErrors({ ...otherProps, requestID: context.boxID });\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === REQUEST) {\n const pending = this._pending.get(context.boxID);\n\n if (!pending) {\n return;\n }\n\n pending.resolve(response);\n } else if (method === SUBSCRIBE || context.hasDeferOrStream) {\n this._eventEmitter.emit(context.boxID, response);\n }\n };\n\n @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\n try {\n if (!context.hasDeferOrStream) {\n return new Promise((resolve: PendingResolver) => {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.boxID, { resolve });\n });\n }\n\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n\n @logRequest()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n","import { handleMessage as handleCachemapMessage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata, serializeErrors } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (!isAsyncIterable(subscribeResult)) {\n postMessage({ context, method, result: serializeErrors(subscribeResult as MaybeRequestResult), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"names":["REQUEST_EXECUTED","logRequest","_target","_propertyName","descriptor","method","value","args","Promise","resolve","debugManager","otherContext","apply","_this","startTime","now","result","endTime","duration","emit","context","options","request","stats","reject","WorkerClient","Map","data","_isPlainObject","type","_cacheMetadata","otherProps","response","deserializeErrors","requestID","boxID","rehydrateCacheMetadata","pending","_pending","get","hasDeferOrStream","_eventEmitter","errors","push","TypeError","cache","worker","length","_cache","_debugManager","EventEmitter","_worker","_addEventListener","this","_request","_getRequestContext","QUERY","_subscribe","SUBSCRIPTION","addEventListener","_onMessage","operation","uuid","fieldTypeMap","operationName","queryFiltered","whitelistHash","hashRequest","_this2","postMessage","_getMessageContext","set","eventAsyncIterator","EventAsyncIterator","getIterator","_castArray","self","client","requestResult","isAsyncIterable","dehydrateCacheMetadata","serializeErrors","forAwaitEach","subscribe","subscribeResult","handleMessage","handleRequest","handleSubscription","registerWorker","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B,EAASD,EAASyD,YAI5BW,oEAAf,oBACJC,iEAAAA,kBAAY9D,IAAAA,QACdC,EAAcD,QAIXE,EAASF,EAATE,KH7Ee,eG+EnBA,EACFwD,EAAc1D,EAAMkD,GH/EF,aGgFThD,GAAqBgD,EAAOhC,OACrC6C,EAAsB/D,EAAMkD,EAAOhC,SAXMgC,IAAAA,OAe7ClB,EHxFqB,UGwFK8B"}
@@ -1,32 +1,32 @@
1
1
  -----------------------------
2
2
  Rollup File Analysis
3
3
  -----------------------------
4
- bundle size: 21.255 KB
5
- original size: 11.192 KB
4
+ bundle size: 21.484 KB
5
+ original size: 11.348 KB
6
6
  code reduction: 0 %
7
7
  module count: 6
8
8
 
9
- ██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░
9
+ █████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░
10
10
  file: /src/main/index.ts
11
- bundle space: 52.38 %
12
- rendered size: 11.133 KB
13
- original size: 5.051 KB
11
+ bundle space: 51.91 %
12
+ rendered size: 11.152 KB
13
+ original size: 5.103 KB
14
14
  code reduction: 0 %
15
15
  dependents: 1
16
16
  - /src/index.ts
17
17
 
18
18
  ██████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
19
19
  file: /src/register-worker/index.ts
20
- bundle space: 28.96 %
21
- rendered size: 6.156 KB
22
- original size: 3.217 KB
20
+ bundle space: 29.63 %
21
+ rendered size: 6.366 KB
22
+ original size: 3.377 KB
23
23
  code reduction: 0 %
24
24
  dependents: 1
25
25
  - /src/index.ts
26
26
 
27
27
  ████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
28
28
  file: /src/debug/log-request/index.ts
29
- bundle space: 17.81 %
29
+ bundle space: 17.62 %
30
30
  rendered size: 3.786 KB
31
31
  original size: 1.244 KB
32
32
  code reduction: 0 %
@@ -35,7 +35,7 @@ dependents: 1
35
35
 
36
36
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
37
37
  file: /src/consts/index.ts
38
- bundle space: 0.85 %
38
+ bundle space: 0.84 %
39
39
  rendered size: 180 Bytes
40
40
  original size: 238 Bytes
41
41
  code reduction: 24.37 %
@@ -49,7 +49,7 @@ dependents: 4
49
49
  file: /src/defs/index.ts
50
50
  bundle space: 0 %
51
51
  rendered size: 0 Byte
52
- original size: 1.276 KB
52
+ original size: 1.22 KB
53
53
  code reduction: 100 %
54
54
  dependents: 1
55
55
  - /src/index.ts
@@ -51,7 +51,10 @@ let WorkerClient = (_dec = (0, _logRequest.default)(), _dec2 = (0, _logRequest.d
51
51
  (0, _defineProperty2.default)(this, "_onMessage", async ({
52
52
  data
53
53
  }) => {
54
- if (!(0, _isPlainObject2.default)(data)) return;
54
+ if (!(0, _isPlainObject2.default)(data)) {
55
+ return;
56
+ }
57
+
55
58
  const {
56
59
  context,
57
60
  method,
@@ -67,9 +70,9 @@ let WorkerClient = (_dec = (0, _logRequest.default)(), _dec2 = (0, _logRequest.d
67
70
  _cacheMetadata,
68
71
  ...otherProps
69
72
  } = result;
70
- const response = { ...otherProps,
73
+ const response = (0, _helpers.deserializeErrors)({ ...otherProps,
71
74
  requestID: context.boxID
72
- };
75
+ });
73
76
 
74
77
  if (_cacheMetadata) {
75
78
  response._cacheMetadata = (0, _helpers.rehydrateCacheMetadata)(_cacheMetadata);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/main/index.ts"],"names":["WorkerClient","_getMessageContext","boxID","hasDeferOrStream","constructor","options","Map","data","context","method","result","type","GRAPHQL_BOX","_cacheMetadata","otherProps","response","requestID","REQUEST","pending","_pending","get","resolve","SUBSCRIBE","_eventEmitter","emit","errors","push","TypeError","cache","worker","length","_cache","_debugManager","debugManager","EventEmitter","_worker","_addEventListener","request","_request","_getRequestContext","QUERY","subscribe","_subscribe","SUBSCRIPTION","addEventListener","MESSAGE","_onMessage","operation","fieldTypeMap","operationName","queryFiltered","whitelistHash","Promise","postMessage","set","eventAsyncIterator","Event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B,WAAb,CAAyB;AACvB7C,QAAAA,OAAO,EAAER,YAAY,CAACC,kBAAb,CAAgCO,OAAhC,CADc;AAEvBC,QAAAA,MAAM,EAAEQ,eAFe;AAGvBZ,QAAAA,OAHuB;AAIvBgC,QAAAA,OAJuB;AAKvB1B,QAAAA,IAAI,EAAEC;AALiB,OAAzB;;AAQA,YAAM2C,kBAAkB,GAAG,IAAIC,2BAAJ,CAA2C,KAAKjC,aAAhD,EAA+Df,OAAO,CAACN,KAAvE,CAA3B;AACA,aAAOqD,kBAAkB,CAACE,WAAnB,EAAP;AACD,KAzBD,CAyBE,OAAOC,KAAP,EAAc;AACd,aAAO;AAAEjC,QAAAA,MAAM,EAAE,yBAAUiC,KAAV;AAAV,OAAP;AACD;AACF;;AAGuB,QAAVhB,UAAU,CAACL,OAAD,EAAkBhC,OAAlB,EAA2CG,OAA3C,EAAoE;AAC1F,QAAI;AACF,WAAK2B,OAAL,CAAakB,WAAb,CAAyB;AACvB7C,QAAAA,OAAO,EAAER,YAAY,CAACC,kBAAb,CAAgCO,OAAhC,CADc;AAEvBC,QAAAA,MAAM,EAAEa,iBAFe;AAGvBjB,QAAAA,OAHuB;AAIvBgC,QAAAA,OAJuB;AAKvB1B,QAAAA,IAAI,EAAEC;AALiB,OAAzB;;AAQA,YAAM2C,kBAAkB,GAAG,IAAIC,2BAAJ,CAA2C,KAAKjC,aAAhD,EAA+Df,OAAO,CAACN,KAAvE,CAA3B;AACA,aAAOqD,kBAAkB,CAACE,WAAnB,EAAP;AACD,KAXD,CAWE,OAAOC,KAAP,EAAc;AACd,aAAO;AAAEjC,QAAAA,MAAM,EAAE,yBAAUiC,KAAV;AAAV,OAAP;AACD;AACF;;AApJ+B,C","sourcesContent":["import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ boxID, hasDeferOrStream = false }: RequestContext): MessageContext {\n return { boxID, hasDeferOrStream };\n }\n\n private _cache: WorkerCachemap;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\n\n constructor(options: UserOptions) {\n const errors: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ? options.debugManager() : null;\n this._eventEmitter = new EventEmitter();\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): WorkerCachemap {\n return this._cache;\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n boxID: uuid(),\n debugManager: this._debugManager,\n fieldTypeMap: new Map(),\n operation,\n operationName: \"\",\n queryFiltered: false,\n request,\n whitelistHash: hashRequest(request),\n ...context,\n };\n }\n\n private _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) return;\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = { ...otherProps, requestID: context.boxID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === REQUEST) {\n const pending = this._pending.get(context.boxID);\n\n if (!pending) {\n return;\n }\n\n pending.resolve(response);\n } else if (method === SUBSCRIBE || context.hasDeferOrStream) {\n this._eventEmitter.emit(context.boxID, response);\n }\n };\n\n @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\n try {\n if (!context.hasDeferOrStream) {\n return new Promise((resolve: PendingResolver) => {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.boxID, { resolve });\n });\n }\n\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n\n @logRequest()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/main/index.ts"],"names":["WorkerClient","_getMessageContext","boxID","hasDeferOrStream","constructor","options","Map","data","context","method","result","type","GRAPHQL_BOX","_cacheMetadata","otherProps","response","requestID","REQUEST","pending","_pending","get","resolve","SUBSCRIBE","_eventEmitter","emit","errors","push","TypeError","cache","worker","length","_cache","_debugManager","debugManager","EventEmitter","_worker","_addEventListener","request","_request","_getRequestContext","QUERY","subscribe","_subscribe","SUBSCRIPTION","addEventListener","MESSAGE","_onMessage","operation","fieldTypeMap","operationName","queryFiltered","whitelistHash","Promise","postMessage","set","eventAsyncIterator","EventAsyncIterator","getIterator","error"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;;AAUA;;AACA;;AAEA;;AACA;;AACA;;;;IAGqBA,Y,WAsGlB,0B,UAgCA,0B,YAtIY,MAAMA,YAAN,CAAmB;AACC,SAAlBC,kBAAkB,CAAC;AAAEC,IAAAA,KAAF;AAASC,IAAAA,gBAAgB,GAAG;AAA5B,GAAD,EAAsE;AACrG,WAAO;AAAED,MAAAA,KAAF;AAASC,MAAAA;AAAT,KAAP;AACD;;AAQDC,EAAAA,WAAW,CAACC,OAAD,EAAuB;AAAA;AAAA;AAAA;AAAA,oDAHC,IAAIC,GAAJ,EAGD;AAAA;AAAA,sDA4Db,OAAO;AAAEC,MAAAA;AAAF,KAAP,KAAiD;AACpE,UAAI,CAAC,6BAAcA,IAAd,CAAL,EAA0B;AACxB;AACD;;AAED,YAAM;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,MAAX;AAAmBC,QAAAA,MAAnB;AAA2BC,QAAAA;AAA3B,UAAoCJ,IAA1C;;AAEA,UAAII,IAAI,KAAKC,mBAAT,IAAwB,CAAC,6BAAcF,MAAd,CAA7B,EAAoD;AAClD;AACD;;AAED,YAAM;AAAEG,QAAAA,cAAF;AAAkB,WAAGC;AAArB,UAAoCJ,MAA1C;AACA,YAAMK,QAA4B,GAAG,gCAAkB,EAAE,GAAGD,UAAL;AAAiBE,QAAAA,SAAS,EAAER,OAAO,CAACN;AAApC,OAAlB,CAArC;;AAEA,UAAIW,cAAJ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AACA,aAAOqD,kBAAkB,CAACE,WAAnB,EAAP;AACD,KAXD,CAWE,OAAOC,KAAP,EAAc;AACd,aAAO;AAAEjC,QAAAA,MAAM,EAAE,yBAAUiC,KAAV;AAAV,OAAP;AACD;AACF;;AAtJ+B,C","sourcesContent":["import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ boxID, hasDeferOrStream = false }: RequestContext): MessageContext {\n return { boxID, hasDeferOrStream };\n }\n\n private _cache: WorkerCachemap;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\n\n constructor(options: UserOptions) {\n const errors: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ? options.debugManager() : null;\n this._eventEmitter = new EventEmitter();\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): WorkerCachemap {\n return this._cache;\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n boxID: uuid(),\n debugManager: this._debugManager,\n fieldTypeMap: new Map(),\n operation,\n operationName: \"\",\n queryFiltered: false,\n request,\n whitelistHash: hashRequest(request),\n ...context,\n };\n }\n\n private _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = deserializeErrors({ ...otherProps, requestID: context.boxID });\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === REQUEST) {\n const pending = this._pending.get(context.boxID);\n\n if (!pending) {\n return;\n }\n\n pending.resolve(response);\n } else if (method === SUBSCRIBE || context.hasDeferOrStream) {\n this._eventEmitter.emit(context.boxID, response);\n }\n };\n\n @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\n try {\n if (!context.hasDeferOrStream) {\n return new Promise((resolve: PendingResolver) => {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.boxID, { resolve });\n });\n }\n\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n\n @logRequest()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n"],"file":"index.js"}
@@ -43,7 +43,7 @@ async function handleRequest(request, method, options, context, client) {
43
43
  postMessage({
44
44
  context,
45
45
  method,
46
- result,
46
+ result: (0, _helpers.serializeErrors)(result),
47
47
  type: _consts.GRAPHQL_BOX
48
48
  });
49
49
  return;
@@ -63,7 +63,7 @@ async function handleRequest(request, method, options, context, client) {
63
63
  postMessage({
64
64
  context,
65
65
  method,
66
- result,
66
+ result: (0, _helpers.serializeErrors)(result),
67
67
  type: _consts.GRAPHQL_BOX
68
68
  });
69
69
  });
@@ -72,29 +72,34 @@ async function handleRequest(request, method, options, context, client) {
72
72
  async function handleSubscription(request, method, options, context, client) {
73
73
  const subscribeResult = await client.subscribe(request, options, context);
74
74
 
75
- if ((0, _iterall.isAsyncIterable)(subscribeResult)) {
76
- (0, _iterall.forAwaitEach)(subscribeResult, ({
77
- _cacheMetadata,
78
- ...otherProps
79
- }) => {
80
- const result = { ...otherProps
81
- };
82
- if (_cacheMetadata) result._cacheMetadata = (0, _helpers.dehydrateCacheMetadata)(_cacheMetadata);
83
- postMessage({
84
- context,
85
- method,
86
- result,
87
- type: _consts.GRAPHQL_BOX
88
- });
89
- });
90
- } else {
75
+ if (!(0, _iterall.isAsyncIterable)(subscribeResult)) {
91
76
  postMessage({
92
77
  context,
93
78
  method,
94
- result: undefined,
79
+ result: (0, _helpers.serializeErrors)(subscribeResult),
95
80
  type: _consts.GRAPHQL_BOX
96
81
  });
82
+ return;
97
83
  }
84
+
85
+ (0, _iterall.forAwaitEach)(subscribeResult, ({
86
+ _cacheMetadata,
87
+ ...otherProps
88
+ }) => {
89
+ const result = { ...otherProps
90
+ };
91
+
92
+ if (_cacheMetadata) {
93
+ result._cacheMetadata = (0, _helpers.dehydrateCacheMetadata)(_cacheMetadata);
94
+ }
95
+
96
+ postMessage({
97
+ context,
98
+ method,
99
+ result: (0, _helpers.serializeErrors)(result),
100
+ type: _consts.GRAPHQL_BOX
101
+ });
102
+ });
98
103
  }
99
104
 
100
105
  function handleMessage(data, client) {
@@ -118,7 +123,10 @@ async function registerWorker({
118
123
  function onMessage({
119
124
  data
120
125
  }) {
121
- if (!(0, _isPlainObject2.default)(data)) return;
126
+ if (!(0, _isPlainObject2.default)(data)) {
127
+ return;
128
+ }
129
+
122
130
  const {
123
131
  type
124
132
  } = data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/register-worker/index.ts"],"names":["addEventListener","postMessage","self","handleRequest","request","method","options","context","client","requestResult","_cacheMetadata","otherProps","result","type","GRAPHQL_BOX","handleSubscription","subscribeResult","subscribe","undefined","handleMessage","data","REQUEST","SUBSCRIBE","registerWorker","onMessage","CACHEMAP","cache","MESSAGE"],"mappings":";;;;;;;;;;;;;;AAAA;;AAGA;;AACA;;AAEA;;AAGA,MAAM;AAAEA,EAAAA,gBAAF;AAAoBC,EAAAA;AAApB,IAAqCC,IAA3C;;AAEA,eAAeC,aAAf,CACEC,OADF,EAEEC,MAFF,EAGEC,OAHF,EAIEC,OAJF,EAKEC,MALF,EAMiB;AACf,QAAMC,aAAa,GAAG,MAAMD,MAAM,CAACJ,OAAP,CAAeA,OAAf,EAAwBE,OAAxB,EAAiCC,OAAjC,CAA5B;;AAEA,MAAI,CAAC,8BAAgBE,aAAhB,CAAL,EAAqC;AACnC,UAAM;AAAEC,MAAAA,cAAF;AAAkB,SAAGC;AAArB,QAAoCF,aAA1C;AACA,UAAMG,MAAqD,GAAG,EAAE,GAAGD;AAAL,KAA9D;;AAEA,QAAID,cAAJ,EAAoB;AAClBE,MAAAA,MAAM,CAACF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AAEM,MAAAA,OAAF;AAAWF,MAAAA,MAAX;AAAmBO,MAAAA,MAAM,EAAEM,SAA3B;AAAsCL,MAAAA,IAAI,EAAEC;AAA5C,KAAD,CAAX;AACD;AACF;;AAEM,SAASK,aAAT,CAAuBC,IAAvB,EAAoDZ,MAApD,EAA0E;AAC/E,QAAM;AAAED,IAAAA,OAAF;AAAWF,IAAAA,MAAX;AAAmBC,IAAAA,OAAnB;AAA4BF,IAAAA;AAA5B,MAAwCgB,IAA9C;;AAEA,MAAIf,MAAM,KAAKgB,eAAf,EAAwB;AACtBlB,IAAAA,aAAa,CAACC,OAAD,EAAUC,MAAV,EAAkBC,OAAlB,EAA2BC,OAA3B,EAAoCC,MAApC,CAAb;AACD,GAFD,MAEO,IAAIH,MAAM,KAAKiB,iBAAf,EAA0B;AAC/BP,IAAAA,kBAAkB,CAACX,OAAD,EAAUC,MAAV,EAAkBC,OAAlB,EAA2BC,OAA3B,EAAoCC,MAApC,CAAlB;AACD;AACF;;AAEc,eAAee,cAAf,CAA8B;AAAEf,EAAAA;AAAF,CAA9B,EAAgF;AAC7F,WAASgB,SAAT,CAAmB;AAAEJ,IAAAA;AAAF,GAAnB,EAAiD;AAC/C,QAAI,CAAC,6BAAcA,IAAd,CAAL,EAA0B;AAE1B,UAAM;AAAEP,MAAAA;AAAF,QAAWO,IAAjB;;AAEA,QAAIP,IAAI,KAAKC,mBAAb,EAA0B;AACxBK,MAAAA,aAAa,CAACC,IAAD,EAAOZ,MAAP,CAAb;AACD,KAFD,MAEO,IAAIK,IAAI,KAAKY,gBAAT,IAAqBjB,MAAM,CAACkB,KAAhC,EAAuC;AAC5C,qCAAsBN,IAAtB,EAA4BZ,MAAM,CAACkB,KAAnC;AACD;AACF;;AAED1B,EAAAA,gBAAgB,CAAC2B,eAAD,EAAUH,SAAV,CAAhB;AACD","sourcesContent":["import { handleMessage as handleCachemapMessage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (isAsyncIterable(subscribeResult)) {\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n if (_cacheMetadata) result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n } else {\n postMessage({ context, method, result: undefined, type: GRAPHQL_BOX });\n }\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) return;\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/register-worker/index.ts"],"names":["addEventListener","postMessage","self","handleRequest","request","method","options","context","client","requestResult","_cacheMetadata","otherProps","result","type","GRAPHQL_BOX","handleSubscription","subscribeResult","subscribe","handleMessage","data","REQUEST","SUBSCRIBE","registerWorker","onMessage","CACHEMAP","cache","MESSAGE"],"mappings":";;;;;;;;;;;;;;AAAA;;AAGA;;AACA;;AAEA;;AAGA,MAAM;AAAEA,EAAAA,gBAAF;AAAoBC,EAAAA;AAApB,IAAqCC,IAA3C;;AAEA,eAAeC,aAAf,CACEC,OADF,EAEEC,MAFF,EAGEC,OAHF,EAIEC,OAJF,EAKEC,MALF,EAMiB;AACf,QAAMC,aAAa,GAAG,MAAMD,MAAM,CAACJ,OAAP,CAAeA,OAAf,EAAwBE,OAAxB,EAAiCC,OAAjC,CAA5B;;AAEA,MAAI,CAAC,8BAAgBE,aAAhB,CAAL,EAAqC;AACnC,UAAM;AAAEC,MAAAA,cAAF;AAAkB,SAAGC;AAArB,QAAoCF,aAA1C;AACA,UAAMG,MAAqD,GAAG,EAAE,GAAGD;AAAL,KAA9D;;AAEA,QAAID,cAAJ,EAAoB;AAClBE,MAAAA,MAAM,CAACF,cAAP,GAAwB,qCAAuBA,cAAvB,CAAxB;AACD;;AAEDT,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essage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata, serializeErrors } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (!isAsyncIterable(subscribeResult)) {\n postMessage({ context, method, result: serializeErrors(subscribeResult as MaybeRequestResult), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"file":"index.js"}
@@ -7,7 +7,7 @@ var _dec, _dec2, _class;
7
7
 
8
8
  import "core-js/modules/es.promise.js";
9
9
  import { QUERY, SUBSCRIPTION } from "@graphql-box/core";
10
- import { EventAsyncIterator, hashRequest, rehydrateCacheMetadata } from "@graphql-box/helpers";
10
+ import { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from "@graphql-box/helpers";
11
11
  import EventEmitter from "eventemitter3";
12
12
  import { v1 as uuid } from "uuid";
13
13
  import { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from "../consts";
@@ -37,7 +37,10 @@ let WorkerClient = (_dec = logRequest(), _dec2 = logRequest(), (_class = class W
37
37
  _defineProperty(this, "_onMessage", async ({
38
38
  data
39
39
  }) => {
40
- if (!_isPlainObject(data)) return;
40
+ if (!_isPlainObject(data)) {
41
+ return;
42
+ }
43
+
41
44
  const {
42
45
  context,
43
46
  method,
@@ -53,9 +56,9 @@ let WorkerClient = (_dec = logRequest(), _dec2 = logRequest(), (_class = class W
53
56
  _cacheMetadata,
54
57
  ...otherProps
55
58
  } = result;
56
- const response = { ...otherProps,
59
+ const response = deserializeErrors({ ...otherProps,
57
60
  requestID: context.boxID
58
- };
61
+ });
59
62
 
60
63
  if (_cacheMetadata) {
61
64
  response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/main/index.ts"],"names":["QUERY","SUBSCRIPTION","EventAsyncIterator","hashRequest","rehydrateCacheMetadata","EventEmitter","v1","uuid","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","logRequest","WorkerClient","_getMessageContext","boxID","hasDeferOrStream","constructor","options","Map","data","context","method","result","type","_cacheMetadata","otherProps","response","requestID","pending","_pending","get","resolve","_eventEmitter","emit","errors","push","TypeError","cache","worker","length","_cache","_debugManager","debugManager","_worker","_addEventListener","request","_request","_getRequestContext","subscribe","_subscribe","addEventListener","_onMessage","operation","fieldTypeMap","operationName","queryFiltered","whitelistHash","Promise","postMessage","set","eventAsyncIterator","getIterator","error"],"mappings":";;;;;;;;AACA,SAIEA,KAJF,EAOEC,YAPF,QASO,mBATP;AAUA,SAASC,kBAAT,EAA6BC,WAA7B,EAA0CC,sBAA1C,QAAwE,sBAAxE;AACA,OAAOC,YAAP,MAAyB,eAAzB;AAEA,SAASC,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,OAA/B,EAAwCC,SAAxC,QAAyD,WAAzD;AACA,OAAOC,UAAP,MAAuB,sBAAvB;IAGqBC,Y,WAoGlBD,UAAU,E,UAgCVA,UAAU,E,YApIE,MAAMC,YAAN,CAAmB;AACC,SAAlBC,kBAAkB,CAAC;AAAEC,IAAAA,KAAF;AAASC,IAAAA,gBAAgB,GAAG;AAA5B,GAAD,EAAsE;AACrG,WAAO;AAAED,MAAAA,KAAF;AAASC,MAAAA;AAAT,KAAP;AACD;;AAQDC,EAAAA,WAAW,CAACC,OAAD,EAAuB;AAAA;;AAAA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,CAACC,WAAnB,EAAP;AACD,KAzBD,CAyBE,OAAOC,KAAP,EAAc;AACd,aAAO;AAAE5B,QAAAA,MAAM,EAAE,WAAU4B,KAAV;AAAV,OAAP;AACD;AACF;;AAGuB,QAAVb,UAAU,CAACJ,OAAD,EAAkB5B,OAAlB,EAA2CG,OAA3C,EAAoE;AAC1F,QAAI;AACF,WAAKuB,OAAL,CAAae,WAAb,CAAyB;AACvBtC,QAAAA,OAAO,EAAER,YAAY,CAACC,kBAAb,CAAgCO,OAAhC,CADc;AAEvBC,QAAAA,MAAM,EAAEX,SAFe;AAGvBO,QAAAA,OAHuB;AAIvB4B,QAAAA,OAJuB;AAKvBtB,QAAAA,IAAI,EAAEhB;AALiB,OAAzB;;AAQA,YAAMqD,kBAAkB,GAAG,IAAI3D,kBAAJ,CAA2C,KAAK+B,aAAhD,EAA+DZ,OAAO,CAACN,KAAvE,CAA3B;AACA,aAAO8C,kBAAkB,CAACC,WAAnB,EAAP;AACD,KAXD,CAWE,OAAOC,KAAP,EAAc;AACd,aAAO;AAAE5B,QAAAA,MAAM,EAAE,WAAU4B,KAAV;AAAV,OAAP;AACD;AACF;;AApJ+B,C;SAAblD,Y","sourcesContent":["import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ boxID, hasDeferOrStream = false }: RequestContext): MessageContext {\n return { boxID, hasDeferOrStream };\n }\n\n private _cache: WorkerCachemap;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\n\n constructor(options: UserOptions) {\n const errors: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ? options.debugManager() : null;\n this._eventEmitter = new EventEmitter();\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): WorkerCachemap {\n return this._cache;\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n boxID: uuid(),\n debugManager: this._debugManager,\n fieldTypeMap: new Map(),\n operation,\n operationName: \"\",\n queryFiltered: false,\n request,\n whitelistHash: hashRequest(request),\n ...context,\n };\n }\n\n private _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) return;\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = { ...otherProps, requestID: context.boxID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === REQUEST) {\n const pending = this._pending.get(context.boxID);\n\n if (!pending) {\n return;\n }\n\n pending.resolve(response);\n } else if (method === SUBSCRIBE || context.hasDeferOrStream) {\n this._eventEmitter.emit(context.boxID, response);\n }\n };\n\n @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\n try {\n if (!context.hasDeferOrStream) {\n return new Promise((resolve: PendingResolver) => {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.boxID, { resolve });\n });\n }\n\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n\n @logRequest()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/main/index.ts"],"names":["QUERY","SUBSCRIPTION","EventAsyncIterator","deserializeErrors","hashRequest","rehydrateCacheMetadata","EventEmitter","v1","uuid","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","logRequest","WorkerClient","_getMessageContext","boxID","hasDeferOrStream","constructor","options","Map","data","context","method","result","type","_cacheMetadata","otherProps","response","requestID","pending","_pending","get","resolve","_eventEmitter","emit","errors","push","TypeError","cache","worker","length","_cache","_debugManager","debugManager","_worker","_addEventListener","request","_request","_getRequestContext","subscribe","_subscribe","addEventListener","_onMessage","operation","fieldTypeMap","operationName","que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Z,OAAO,CAACN,KAAvE,CAA3B;AACA,aAAO8C,kBAAkB,CAACC,WAAnB,EAAP;AACD,KAXD,CAWE,OAAOC,KAAP,EAAc;AACd,aAAO;AAAE5B,QAAAA,MAAM,EAAE,WAAU4B,KAAV;AAAV,OAAP;AACD;AACF;;AAtJ+B,C;SAAblD,Y","sourcesContent":["import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ boxID, hasDeferOrStream = false }: RequestContext): MessageContext {\n return { boxID, hasDeferOrStream };\n }\n\n private _cache: WorkerCachemap;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\n\n constructor(options: UserOptions) {\n const errors: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ? options.debugManager() : null;\n this._eventEmitter = new EventEmitter();\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): WorkerCachemap {\n return this._cache;\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n boxID: uuid(),\n debugManager: this._debugManager,\n fieldTypeMap: new Map(),\n operation,\n operationName: \"\",\n queryFiltered: false,\n request,\n whitelistHash: hashRequest(request),\n ...context,\n };\n }\n\n private _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = deserializeErrors({ ...otherProps, requestID: context.boxID });\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === REQUEST) {\n const pending = this._pending.get(context.boxID);\n\n if (!pending) {\n return;\n }\n\n pending.resolve(response);\n } else if (method === SUBSCRIBE || context.hasDeferOrStream) {\n this._eventEmitter.emit(context.boxID, response);\n }\n };\n\n @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\n try {\n if (!context.hasDeferOrStream) {\n return new Promise((resolve: PendingResolver) => {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.boxID, { resolve });\n });\n }\n\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n\n @logRequest()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.boxID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n"],"file":"index.js"}
@@ -1,7 +1,7 @@
1
1
  import _isPlainObject from "lodash/isPlainObject";
2
2
  import "core-js/modules/es.promise.js";
3
3
  import { handleMessage as handleCachemapMessage } from "@cachemap/core-worker";
4
- import { dehydrateCacheMetadata } from "@graphql-box/helpers";
4
+ import { dehydrateCacheMetadata, serializeErrors } from "@graphql-box/helpers";
5
5
  import { forAwaitEach, isAsyncIterable } from "iterall";
6
6
  import { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from "../consts";
7
7
  const {
@@ -27,7 +27,7 @@ async function handleRequest(request, method, options, context, client) {
27
27
  postMessage({
28
28
  context,
29
29
  method,
30
- result,
30
+ result: serializeErrors(result),
31
31
  type: GRAPHQL_BOX
32
32
  });
33
33
  return;
@@ -47,7 +47,7 @@ async function handleRequest(request, method, options, context, client) {
47
47
  postMessage({
48
48
  context,
49
49
  method,
50
- result,
50
+ result: serializeErrors(result),
51
51
  type: GRAPHQL_BOX
52
52
  });
53
53
  });
@@ -56,29 +56,34 @@ async function handleRequest(request, method, options, context, client) {
56
56
  async function handleSubscription(request, method, options, context, client) {
57
57
  const subscribeResult = await client.subscribe(request, options, context);
58
58
 
59
- if (isAsyncIterable(subscribeResult)) {
60
- forAwaitEach(subscribeResult, ({
61
- _cacheMetadata,
62
- ...otherProps
63
- }) => {
64
- const result = { ...otherProps
65
- };
66
- if (_cacheMetadata) result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
67
- postMessage({
68
- context,
69
- method,
70
- result,
71
- type: GRAPHQL_BOX
72
- });
73
- });
74
- } else {
59
+ if (!isAsyncIterable(subscribeResult)) {
75
60
  postMessage({
76
61
  context,
77
62
  method,
78
- result: undefined,
63
+ result: serializeErrors(subscribeResult),
79
64
  type: GRAPHQL_BOX
80
65
  });
66
+ return;
81
67
  }
68
+
69
+ forAwaitEach(subscribeResult, ({
70
+ _cacheMetadata,
71
+ ...otherProps
72
+ }) => {
73
+ const result = { ...otherProps
74
+ };
75
+
76
+ if (_cacheMetadata) {
77
+ result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
78
+ }
79
+
80
+ postMessage({
81
+ context,
82
+ method,
83
+ result: serializeErrors(result),
84
+ type: GRAPHQL_BOX
85
+ });
86
+ });
82
87
  }
83
88
 
84
89
  export function handleMessage(data, client) {
@@ -101,7 +106,10 @@ export default async function registerWorker({
101
106
  function onMessage({
102
107
  data
103
108
  }) {
104
- if (!_isPlainObject(data)) return;
109
+ if (!_isPlainObject(data)) {
110
+ return;
111
+ }
112
+
105
113
  const {
106
114
  type
107
115
  } = data;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/register-worker/index.ts"],"names":["handleMessage","handleCachemapMessage","dehydrateCacheMetadata","forAwaitEach","isAsyncIterable","CACHEMAP","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","addEventListener","postMessage","self","handleRequest","request","method","options","context","client","requestResult","_cacheMetadata","otherProps","result","type","handleSubscription","subscribeResult","subscribe","undefined","data","registerWorker","onMessage","cache"],"mappings":";;AAAA,SAASA,aAAa,IAAIC,qBAA1B,QAAuD,uBAAvD;AAGA,SAASC,sBAAT,QAAuC,sBAAvC;AACA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,SAA9C;AAEA,SAASC,QAAT,EAAmBC,WAAnB,EAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,SAAlD,QAAmE,WAAnE;AAGA,MAAM;AAAEC,EAAAA,gBAAF;A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AAAEF,IAAAA;AAAF,GAAnB,EAAiD;AAC/C,QAAI,CAAC,eAAcA,IAAd,CAAL,EAA0B;AAE1B,UAAM;AAAEL,MAAAA;AAAF,QAAWK,IAAjB;;AAEA,QAAIL,IAAI,KAAKjB,WAAb,EAA0B;AACxBN,MAAAA,aAAa,CAAC4B,IAAD,EAAOV,MAAP,CAAb;AACD,KAFD,MAEO,IAAIK,IAAI,KAAKlB,QAAT,IAAqBa,MAAM,CAACa,KAAhC,EAAuC;AAC5C9B,MAAAA,qBAAqB,CAAC2B,IAAD,EAAOV,MAAM,CAACa,KAAd,CAArB;AACD;AACF;;AAEDrB,EAAAA,gBAAgB,CAACH,OAAD,EAAUuB,SAAV,CAAhB;AACD","sourcesContent":["import { handleMessage as handleCachemapMessage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (isAsyncIterable(subscribeResult)) {\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n if (_cacheMetadata) result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n } else {\n postMessage({ context, method, result: undefined, type: GRAPHQL_BOX });\n }\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) return;\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/register-worker/index.ts"],"names":["handleMessage","handleCachemapMessage","dehydrateCacheMetadata","serializeErrors","forAwaitEach","isAsyncIterable","CACHEMAP","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","addEventListener","postMessage","self","handleRequest","request","method","options","context","client","requestResult","_cacheMetadata","otherProps","result","type","handleSubscription","subscribeResult","subscribe","data","registerWorker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AA4BF,IAAAA;AAA5B,MAAwCa,IAA9C;;AAEA,MAAIZ,MAAM,KAAKP,OAAf,EAAwB;AACtBK,IAAAA,aAAa,CAACC,OAAD,EAAUC,MAAV,EAAkBC,OAAlB,EAA2BC,OAA3B,EAAoCC,MAApC,CAAb;AACD,GAFD,MAEO,IAAIH,MAAM,KAAKN,SAAf,EAA0B;AAC/Be,IAAAA,kBAAkB,CAACV,OAAD,EAAUC,MAAV,EAAkBC,OAAlB,EAA2BC,OAA3B,EAAoCC,MAApC,CAAlB;AACD;AACF;AAED,eAAe,eAAeU,cAAf,CAA8B;AAAEV,EAAAA;AAAF,CAA9B,EAAgF;AAC7F,WAASW,SAAT,CAAmB;AAAEF,IAAAA;AAAF,GAAnB,EAAiD;AAC/C,QAAI,CAAC,eAAcA,IAAd,CAAL,EAA0B;AACxB;AACD;;AAED,UAAM;AAAEJ,MAAAA;AAAF,QAAWI,IAAjB;;AAEA,QAAIJ,IAAI,KAAKjB,WAAb,EAA0B;AACxBP,MAAAA,aAAa,CAAC4B,IAAD,EAAOT,MAAP,CAAb;AACD,KAFD,MAEO,IAAIK,IAAI,KAAKlB,QAAT,IAAqBa,MAAM,CAACY,KAAhC,EAAuC;AAC5C9B,MAAAA,qBAAqB,CAAC2B,IAAD,EAAOT,MAAM,CAACY,KAAd,CAArB;AACD;AACF;;AAEDpB,EAAAA,gBAAgB,CAACH,OAAD,EAAUsB,SAAV,CAAhB;AACD","sourcesContent":["import { handleMessage as handleCachemapMessage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata, serializeErrors } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (!isAsyncIterable(subscribeResult)) {\n postMessage({ context, method, result: serializeErrors(subscribeResult as MaybeRequestResult), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"file":"index.js"}
@@ -1,6 +1,6 @@
1
1
  import WorkerCachemap from "@cachemap/core-worker";
2
2
  import Client from "@graphql-box/client";
3
- import { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from "@graphql-box/core";
3
+ import { MaybeRawFetchData, MaybeRequestResult, RequestOptions } from "@graphql-box/core";
4
4
  import { DebugManagerInit } from "@graphql-box/debug-manager";
5
5
  export interface UserOptions {
6
6
  /**
@@ -32,7 +32,7 @@ export interface MessageRequestPayload {
32
32
  export interface MessageResponsePayload {
33
33
  context: MessageContext;
34
34
  method: MethodNames;
35
- result: MaybeRequestResultWithDehydratedCacheMetadata;
35
+ result: MaybeRawFetchData;
36
36
  type: "graphqlBox" | "cachemap";
37
37
  }
38
38
  export interface MessageContext {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/defs/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;AACnD,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,6CAA6C,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAEhC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,WAAW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OAAO,EAAE,WAAW;IA0BhC,IAAI,KAAK,IAAI,cAAc,CAE1B;IAEY,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,mBAAwB;;;IAIxF,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;;;IAIpE,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,kBAAkB;IAkB1B,OAAO,CAAC,UAAU,CA2BhB;YAGY,QAAQ;YAgCR,UAAU;CAgBzB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/main/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAEL,mBAAmB,EACnB,kBAAkB,EAGlB,cAAc,EAGf,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EAA2E,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/G,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAIjC,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,WAAW;IA0BhC,IAAI,KAAK,IAAI,cAAc,CAE1B;IAEY,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,mBAAwB;;;IAIxF,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;;;IAIpE,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,kBAAkB;IAkB1B,OAAO,CAAC,UAAU,CA6BhB;YAGY,QAAQ;YAgCR,UAAU;CAgBzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/register-worker/index.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAMzC,OAAO,EAAkB,qBAAqB,EAAe,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAwDpG,wBAAgB,aAAa,CAAC,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAQ/E;AAED,wBAA8B,cAAc,CAAC,EAAE,MAAM,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAc7F"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/register-worker/index.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAMzC,OAAO,EAAkB,qBAAqB,EAAe,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA6DpG,wBAAgB,aAAa,CAAC,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAQ/E;AAED,wBAA8B,cAAc,CAAC,EAAE,MAAM,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB7F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-box/worker-client",
3
- "version": "3.2.0",
3
+ "version": "3.3.2",
4
4
  "description": "The GraphQL Box web worker client module.",
5
5
  "author": "Dylan Aubrey <dylanaubrey@gmail.com>",
6
6
  "license": "MIT",
package/src/defs/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import WorkerCachemap from "@cachemap/core-worker";
2
2
  import Client from "@graphql-box/client";
3
- import { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from "@graphql-box/core";
3
+ import { MaybeRawFetchData, MaybeRequestResult, RequestOptions } from "@graphql-box/core";
4
4
  import { DebugManagerInit } from "@graphql-box/debug-manager";
5
5
 
6
6
  export interface UserOptions {
@@ -41,7 +41,7 @@ export interface MessageRequestPayload {
41
41
  export interface MessageResponsePayload {
42
42
  context: MessageContext;
43
43
  method: MethodNames;
44
- result: MaybeRequestResultWithDehydratedCacheMetadata;
44
+ result: MaybeRawFetchData;
45
45
  type: "graphqlBox" | "cachemap";
46
46
  }
47
47
 
package/src/main/index.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  SUBSCRIPTION,
10
10
  ValidOperations,
11
11
  } from "@graphql-box/core";
12
- import { EventAsyncIterator, hashRequest, rehydrateCacheMetadata } from "@graphql-box/helpers";
12
+ import { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from "@graphql-box/helpers";
13
13
  import EventEmitter from "eventemitter3";
14
14
  import { castArray, isPlainObject } from "lodash";
15
15
  import { v1 as uuid } from "uuid";
@@ -89,7 +89,9 @@ export default class WorkerClient {
89
89
  }
90
90
 
91
91
  private _onMessage = async ({ data }: MessageEvent): Promise<void> => {
92
- if (!isPlainObject(data)) return;
92
+ if (!isPlainObject(data)) {
93
+ return;
94
+ }
93
95
 
94
96
  const { context, method, result, type } = data as MessageResponsePayload;
95
97
 
@@ -98,7 +100,7 @@ export default class WorkerClient {
98
100
  }
99
101
 
100
102
  const { _cacheMetadata, ...otherProps } = result;
101
- const response: MaybeRequestResult = { ...otherProps, requestID: context.boxID };
103
+ const response: MaybeRequestResult = deserializeErrors({ ...otherProps, requestID: context.boxID });
102
104
 
103
105
  if (_cacheMetadata) {
104
106
  response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);
@@ -1,7 +1,7 @@
1
1
  import { handleMessage as handleCachemapMessage } from "@cachemap/core-worker";
2
2
  import Client from "@graphql-box/client";
3
3
  import { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from "@graphql-box/core";
4
- import { dehydrateCacheMetadata } from "@graphql-box/helpers";
4
+ import { dehydrateCacheMetadata, serializeErrors } from "@graphql-box/helpers";
5
5
  import { forAwaitEach, isAsyncIterable } from "iterall";
6
6
  import { isPlainObject } from "lodash";
7
7
  import { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from "../consts";
@@ -26,7 +26,7 @@ async function handleRequest(
26
26
  result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
27
27
  }
28
28
 
29
- postMessage({ context, method, result, type: GRAPHQL_BOX });
29
+ postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });
30
30
  return;
31
31
  }
32
32
 
@@ -37,7 +37,7 @@ async function handleRequest(
37
37
  result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
38
38
  }
39
39
 
40
- postMessage({ context, method, result, type: GRAPHQL_BOX });
40
+ postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });
41
41
  });
42
42
  }
43
43
 
@@ -50,15 +50,20 @@ async function handleSubscription(
50
50
  ): Promise<void> {
51
51
  const subscribeResult = await client.subscribe(request, options, context);
52
52
 
53
- if (isAsyncIterable(subscribeResult)) {
54
- forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {
55
- const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };
56
- if (_cacheMetadata) result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
57
- postMessage({ context, method, result, type: GRAPHQL_BOX });
58
- });
59
- } else {
60
- postMessage({ context, method, result: undefined, type: GRAPHQL_BOX });
53
+ if (!isAsyncIterable(subscribeResult)) {
54
+ postMessage({ context, method, result: serializeErrors(subscribeResult as MaybeRequestResult), type: GRAPHQL_BOX });
55
+ return;
61
56
  }
57
+
58
+ forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {
59
+ const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };
60
+
61
+ if (_cacheMetadata) {
62
+ result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
63
+ }
64
+
65
+ postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });
66
+ });
62
67
  }
63
68
 
64
69
  export function handleMessage(data: MessageRequestPayload, client: Client): void {
@@ -73,7 +78,9 @@ export function handleMessage(data: MessageRequestPayload, client: Client): void
73
78
 
74
79
  export default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {
75
80
  function onMessage({ data }: MessageEvent): void {
76
- if (!isPlainObject(data)) return;
81
+ if (!isPlainObject(data)) {
82
+ return;
83
+ }
77
84
 
78
85
  const { type } = data as MessageRequestPayload;
79
86