@graphql-box/worker-client 5.4.16 → 5.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 dylanaubrey
3
+ Copyright (c) 2018 miami-man
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,2 +1,2 @@
1
- "use strict";require("core-js/modules/es.array.push.js");var e=require("@graphql-box/core"),t=require("@graphql-box/helpers"),r=require("eventemitter3"),s=require("graphql"),a=require("lodash-es"),o=require("uuid"),n=require("iterall"),i=require("@cachemap/core-worker");const u="graphqlBox",c="message",h="request",p="subscribe",g=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function l(e,t,r,s){var a,o=arguments.length,n=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(n=(o<3?a(n):o>3?a(t,r,n):a(t,r))||n);return o>3&&n&&Object.defineProperty(t,r,n),n}function d(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class q{static _getMessageContext({hasDeferOrStream:e=!1,initiator:t,operation:r,requestID:s}){return{hasDeferOrStream:e,initiator:t,operation:r,requestID:s}}static _resolve({cacheMetadata:e,...t},r,{requestID:s}){const a={...t,requestID:s};return r.returnCacheMetadata&&e&&(a._cacheMetadata=e),a}constructor(a){this._onMessage=({data:r})=>{if(!t.isPlainObject(r))return;const{context:a,method:o,result:n,type:i}=r;if(i!==u)return;const{_cacheMetadata:c,...h}=n,g={...t.deserializeErrors(h),requestID:a.requestID};if(c&&(g._cacheMetadata=t.rehydrateCacheMetadata(c)),o===p)this._debugManager?.log(e.SUBSCRIPTION_RESOLVED,{context:a,result:g,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(a.requestID,g);else if(a.hasDeferOrStream){const r=this._pending.get(a.requestID);if(r){const e=new t.EventAsyncIterator(this._eventEmitter,a.requestID);r.resolve(e.getIterator())}this._debugManager?.log(e.REQUEST_RESOLVED,{context:a,result:g,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(a.requestID,g)}else{const t=this._pending.get(a.requestID);if(!t)return;this._debugManager?.log(e.REQUEST_RESOLVED,{context:a,result:g,stats:{endTime:this._debugManager.now()}}),a.operation===s.OperationTypeNode.QUERY&&t.requestData&&t.options&&t.context&&this._cacheManager.cacheQuery(t.requestData,void 0,g,t.options,t.context),t.resolve(g)}},this._messageQueue=[],this._pending=new Map;const o=[];if(t.isPlainObject(a)||o.push(new t.ArgsError("@graphql-box/worker-client expected options to ba a plain object.")),"cache"in a||o.push(new t.ArgsError("@graphql-box/worker-client expected options.cache.")),"cacheManager"in a||o.push(new t.ArgsError("@graphql-box/worker-client expected options.cacheManager.")),"requestParser"in a||o.push(new t.ArgsError("@graphql-box/worker-client expected options.requestParser.")),a.lazyWorkerInit||"worker"in a||o.push(new t.ArgsError("@graphql-box/worker-client expected options.worker.")),o.length>0)throw new t.GroupedError("@graphql-box/worker-client argument validation errors.",o);this._cache=a.cache,this._cacheManager=a.cacheManager,this._debugManager=a.debugManager??null,this._eventEmitter=new r.EventEmitter,this._experimentalDeferStreamSupport=a.experimentalDeferStreamSupport??!1,this._requestParser=a.requestParser,"function"==typeof a.worker?Promise.resolve(a.worker()).then((e=>{this._worker=e,this._addEventListener(),this._releaseMessageQueue()})).catch((e=>{throw e})):a.worker&&(this._worker=a.worker,this._addEventListener())}get cache(){return this._cache}get cacheManager(){return this._cacheManager}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(s.OperationTypeNode.MUTATION,e,r))}async query(e,t={},r={}){return this._query(e,t,this._getRequestContext(s.OperationTypeNode.QUERY,e,r))}async request(e,t={},r={}){return this._request(e,t,this._getRequestContext(s.OperationTypeNode.QUERY,e,r))}async subscribe(e,t={}){return this._subscribe(e,t,this._getRequestContext(s.OperationTypeNode.SUBSCRIPTION,e))}set worker(e){this._worker=e,this._addEventListener(),this._releaseMessageQueue()}_addEventListener(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");this._worker.addEventListener(c,this._onMessage)}_getRequestContext(e,r,s={}){return{debugManager:this._debugManager,experimentalDeferStreamSupport:this._experimentalDeferStreamSupport,fieldTypeMap:new Map,filteredRequest:"",operation:e,operationName:"",originalRequestHash:t.hashRequest(r),parsedRequest:"",queryFiltered:!1,request:r,requestComplexity:null,requestDepth:null,requestID:o.v4(),...s}}async _query(e,r,s){try{const{ast:a,request:o}=this._requestParser.updateRequest(e,r,s),n={ast:a,hash:t.hashRequest(o),request:o},i=await this._cacheManager.checkQueryResponseCacheEntry(n.hash,r,s);return i?q._resolve(i,r,s):await new Promise((t=>{this._worker?this._worker.postMessage({context:q._getMessageContext(s),method:h,options:r,request:e,type:u}):this._messageQueue.push({context:q._getMessageContext(s),method:h,options:r,request:e,type:u}),this._pending.set(s.requestID,{context:s,options:r,requestData:n,resolve:t})}))}catch(e){return{errors:[a.isError(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:s.requestID}}}_releaseMessageQueue(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");const e=[...this._messageQueue];this._messageQueue=[];for(const t of e)this._worker.postMessage(t)}async _request(e,t,r){try{return await new Promise((s=>{this._worker?this._worker.postMessage({context:q._getMessageContext(r),method:h,options:t,request:e,type:u}):this._messageQueue.push({context:q._getMessageContext(r),method:h,options:t,request:e,type:u}),this._pending.set(r.requestID,{resolve:s})}))}catch(e){return{errors:[a.isError(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.requestID}}}_subscribe(e,r,s){try{this._worker?this._worker.postMessage({context:q._getMessageContext(s),method:p,options:r,request:e,type:u}):this._messageQueue.push({context:q._getMessageContext(s),method:p,options:r,request:e,type:u});const a=new t.EventAsyncIterator(this._eventEmitter,s.requestID);return Promise.resolve(a.getIterator())}catch(e){const t=a.isError(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:s.requestID})}}}l([(t,r,s)=>{const a=s.value;a&&(s.value=async function(...t){return new Promise((r=>{(async()=>{const{debugManager:s,...o}=t[2];if(!s)return void r(await a.apply(this,t));const i=g(t[0]),u=s.now();s.log(e.REQUEST_EXECUTED,{context:{...o,operationName:i},options:t[1],request:t[0],stats:{startTime:u}});const c=await a.apply(this,t),h=s.now(),p=h-u;r(c),n.isAsyncIterable(c)||s.log(e.REQUEST_RESOLVED,{context:{...o,operationName:i},options:t[1],request:t[0],result:c,stats:{duration:p,endTime:h,startTime:u}})})()}))})},d("design:type",Function),d("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),d("design:returntype",Promise)],q.prototype,"_request",null),l([(t,r,s)=>{const a=s.value;a&&(s.value=async function(...t){return new Promise((r=>{(async()=>{const{debugManager:s,...o}=t[2];if(!s)return void r(await a.apply(this,t));const n=g(t[0]),i=s.now();s.log(e.SUBSCRIPTION_EXECUTED,{context:{...o,operationName:n},options:t[1],request:t[0],stats:{startTime:i}});const u=await a.apply(this,t);r(u)})()}))})},d("design:type",Function),d("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),d("design:returntype","undefined"==typeof Promise?Object:Promise)],q.prototype,"_subscribe",null);const _=(e,r)=>{const{context:s,method:a,options:o,request:i}=e;a===h?(async(e,r,s,a,o)=>{const i=await o.request(e,s,a);if(!n.isAsyncIterable(i)){const{_cacheMetadata:e,...s}=i,o=t.serializeErrors({...s});return e&&(o._cacheMetadata=t.dehydrateCacheMetadata(e)),void globalThis.postMessage({context:a,method:r,result:o,type:u})}n.forAwaitEach(i,(({_cacheMetadata:e,...s})=>{const o=t.serializeErrors({...s});e&&(o._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:a,method:r,result:o,type:u})}))})(i,a,o,s,r):(async(e,r,s,a,o)=>{const i=await o.subscribe(e,s,a);n.isAsyncIterable(i)?n.forAwaitEach(i,(({_cacheMetadata:e,...s})=>{const o=t.serializeErrors({...s});e&&(o._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:a,method:r,result:o,type:u})})):globalThis.postMessage({context:a,method:r,result:t.serializeErrors(i),type:u})})(i,a,o,s,r)};exports.CACHEMAP="cachemap",exports.GRAPHQL_BOX=u,exports.MESSAGE=c,exports.REQUEST=h,exports.SUBSCRIBE=p,exports.WorkerClient=q,exports.handleMessage=_,exports.registerWorker=({client:e})=>{globalThis.addEventListener(c,(({data:t})=>{t.type===u?_(t,e):e.cache&&i.handleMessage(t,e.cache)}))};
1
+ "use strict";require("core-js/modules/es.array.push.js");var e=require("@graphql-box/core"),t=require("@graphql-box/helpers"),r=require("eventemitter3"),a=require("graphql"),s=require("lodash-es"),o=require("uuid"),n=require("iterall"),i=require("@cachemap/core-worker");const c="graphqlBox",u="message",d="request",h="subscribe",p=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function l(e,t,r,a){var s,o=arguments.length,n=o<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,a);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(n=(o<3?s(n):o>3?s(t,r,n):s(t,r))||n);return o>3&&n&&Object.defineProperty(t,r,n),n}function g(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class q{static _resolve({cacheMetadata:e,...t},r,{data:a}){const s={...t,requestID:a.requestID};return r.returnCacheMetadata&&e&&(s._cacheMetadata=e),s}constructor(s){this._onMessage=({data:r})=>{if(!t.isPlainObject(r))return;const{context:s,method:o,result:n,type:i}=r;if(i!==c)return;const{operation:u,requestID:d}=s.data,{hasDeferOrStream:p}=s.deprecated,{_cacheMetadata:l,...g}=n,q={...t.deserializeErrors(g),requestID:d};if(l&&(q._cacheMetadata=t.rehydrateCacheMetadata(l)),o===h)this._debugManager?.log(e.SUBSCRIPTION_RESOLVED,{data:s.data,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(d,q);else if(p){const r=this._pending.get(d);if(r){const e=new t.EventAsyncIterator(this._eventEmitter,d);r.resolve(e.getIterator())}this._debugManager?.log(e.REQUEST_RESOLVED,{data:s.data,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(d,q)}else{const t=this._pending.get(d);if(!t)return;this._debugManager?.log(e.REQUEST_RESOLVED,{data:s.data,stats:{endTime:this._debugManager.now()}}),u===a.OperationTypeNode.QUERY&&t.requestData&&t.options&&t.context&&this._cacheManager.cacheQuery(t.requestData,void 0,q,t.options,t.context),t.resolve(q)}},this._messageQueue=[],this._pending=new Map;const o=[];if(t.isPlainObject(s)||o.push(new t.ArgsError("@graphql-box/worker-client expected options to ba a plain object.")),"cache"in s||o.push(new t.ArgsError("@graphql-box/worker-client expected options.cache.")),"cacheManager"in s||o.push(new t.ArgsError("@graphql-box/worker-client expected options.cacheManager.")),"requestParser"in s||o.push(new t.ArgsError("@graphql-box/worker-client expected options.requestParser.")),s.lazyWorkerInit||"worker"in s||o.push(new t.ArgsError("@graphql-box/worker-client expected options.worker.")),o.length>0)throw new t.GroupedError("@graphql-box/worker-client argument validation errors.",o);this._cache=s.cache,this._cacheManager=s.cacheManager,this._debugManager=s.debugManager,this._eventEmitter=new r.EventEmitter,this._experimentalDeferStreamSupport=s.experimentalDeferStreamSupport??!1,this._requestParser=s.requestParser,"function"==typeof s.worker?Promise.resolve(s.worker()).then((e=>{this._worker=e,this._addEventListener(),this._releaseMessageQueue()})).catch((e=>{throw e})):s.worker&&(this._worker=s.worker,this._addEventListener())}get cache(){return this._cache}get cacheManager(){return this._cacheManager}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(a.OperationTypeNode.MUTATION,e,t,r))}async query(e,t={},r={}){return this._query(e,t,this._getRequestContext(a.OperationTypeNode.QUERY,e,t,r))}async request(e,t={},r={}){return this._request(e,t,this._getRequestContext(a.OperationTypeNode.QUERY,e,t,r))}async subscribe(e,t={},r={}){return this._subscribe(e,t,this._getRequestContext(a.OperationTypeNode.SUBSCRIPTION,e,t,r))}set worker(e){this._worker=e,this._addEventListener(),this._releaseMessageQueue()}_addEventListener(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");this._worker.addEventListener(u,this._onMessage)}_getRequestContext(e,r,a,n){return s.merge({data:{batched:a.batch,operation:e,operationName:"",originalRequestHash:t.hashRequest(r),queryFiltered:!1,requestComplexity:void 0,requestDepth:void 0,requestID:o.v4(),tag:a.tag,variables:a.variables},debugManager:this._debugManager,deprecated:{experimentalDeferStreamSupport:this._experimentalDeferStreamSupport},fieldTypeMap:new Map,filteredRequest:"",parsedRequest:"",request:r},n)}async _query(e,r,a){try{const{ast:s,request:o}=this._requestParser.updateRequest(e,r,a),n={ast:s,hash:t.hashRequest(o),request:o},i=await this._cacheManager.checkQueryResponseCacheEntry(n.hash,r,a);return i?q._resolve(i,r,a):await new Promise((t=>{this._worker?this._worker.postMessage({context:{data:a.data,deprecated:a.deprecated},method:d,options:r,request:e,type:c}):this._messageQueue.push({context:{data:a.data,deprecated:a.deprecated},method:d,options:r,request:e,type:c}),this._pending.set(a.data.requestID,{context:a,options:r,requestData:n,resolve:t})}))}catch(e){return{errors:[s.isError(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:a.data.requestID}}}_releaseMessageQueue(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");const e=[...this._messageQueue];this._messageQueue=[];for(const t of e)this._worker.postMessage(t)}async _request(e,t,{data:r,deprecated:a}){try{return await new Promise((s=>{this._worker?this._worker.postMessage({context:{data:r,deprecated:a},method:d,options:t,request:e,type:c}):this._messageQueue.push({context:{data:r,deprecated:a},method:d,options:t,request:e,type:c}),this._pending.set(r.requestID,{resolve:s})}))}catch(e){return{errors:[s.isError(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.requestID}}}_subscribe(e,r,{data:a,deprecated:o}){try{this._worker?this._worker.postMessage({context:{data:a,deprecated:o},method:h,options:r,request:e,type:c}):this._messageQueue.push({context:{data:a,deprecated:o},method:h,options:r,request:e,type:c});const s=new t.EventAsyncIterator(this._eventEmitter,a.requestID);return Promise.resolve(s.getIterator())}catch(e){const t=s.isError(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:a.requestID})}}}l([(t,r,a)=>{const s=a.value;s&&(a.value=async function(...t){return new Promise((r=>{(async()=>{const{data:a,debugManager:o}=t[2];if(!o)return void r(await s.apply(this,t));const i=p(t[0]),c=o.now();o.log(e.REQUEST_EXECUTED,{data:{...a,...!a.operationName&&i?{operationName:i}:void 0},stats:{startTime:c}});const u=await s.apply(this,t),d=o.now(),h=d-c;r(u),n.isAsyncIterable(u)||o.log(e.REQUEST_RESOLVED,{data:{...a,...!a.operationName&&i?{operationName:i}:void 0},stats:{duration:h,endTime:d,startTime:c}})})()}))})},g("design:type",Function),g("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),g("design:returntype",Promise)],q.prototype,"_request",null),l([(t,r,a)=>{const s=a.value;s&&(a.value=async function(...t){return new Promise((r=>{(async()=>{const{data:a,debugManager:o}=t[2];if(!o)return void r(await s.apply(this,t));const n=p(t[0]),i=o.now();o.log(e.SUBSCRIPTION_EXECUTED,{data:{...a,...!a.operationName&&n?{operationName:n}:void 0},stats:{startTime:i}});const c=await s.apply(this,t);r(c)})()}))})},g("design:type",Function),g("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),g("design:returntype","undefined"==typeof Promise?Object:Promise)],q.prototype,"_subscribe",null);const _=(e,r)=>{const{context:a,method:s,options:o,request:i}=e;s===d?(async(e,r,a,s,o)=>{const i=await o.request(e,a,s);if(!n.isAsyncIterable(i)){const{_cacheMetadata:e,...a}=i,o=t.serializeErrors({...a});return e&&(o._cacheMetadata=t.dehydrateCacheMetadata(e)),void globalThis.postMessage({context:s,method:r,result:o,type:c})}n.forAwaitEach(i,(({_cacheMetadata:e,...a})=>{const o=t.serializeErrors({...a});e&&(o._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:s,method:r,result:o,type:c})}))})(i,s,o,a,r):(async(e,r,a,s,o)=>{const i=await o.subscribe(e,a,s);n.isAsyncIterable(i)?n.forAwaitEach(i,(({_cacheMetadata:e,...a})=>{const o=t.serializeErrors({...a});e&&(o._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:s,method:r,result:o,type:c})})):globalThis.postMessage({context:s,method:r,result:t.serializeErrors(i),type:c})})(i,s,o,a,r)};exports.CACHEMAP="cachemap",exports.GRAPHQL_BOX=c,exports.MESSAGE=u,exports.REQUEST=d,exports.SUBSCRIBE=h,exports.WorkerClient=q,exports.handleMessage=_,exports.registerWorker=({client:e})=>{globalThis.addEventListener(u,(({data:t})=>{t.type===c?_(t,e):e.cache&&i.handleMessage(t,e.cache)}))};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../worker-client/src//constants.ts","../worker-client/src//helpers/operationNameRegex.ts","../worker-client/src//main.ts","../worker-client/src//debug/logRequest.ts","../worker-client/src//debug/logSubscription.ts","../worker-client/src//helpers/isGraphqlBoxMessageRequestPayload.ts","../worker-client/src//registerWorker.ts"],"sourcesContent":["export const CACHEMAP = 'cachemap';\nexport const GRAPHQL_BOX = 'graphqlBox';\nexport const MESSAGE = 'message';\nexport const REQUEST = 'request';\nexport const SUBSCRIBE = 'subscribe';\n","export const operationNameRegex = (request: string) => {\n const output = /(query|mutation|subscription) ([A-Za-z]+)(\\(| {)/.exec(request);\n return output ? output[2] : '';\n};\n","import { type CoreWorker } from '@cachemap/core-worker';\nimport { type CacheManagerDef } from '@graphql-box/cache-manager';\nimport {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n type PartialResponseData,\n REQUEST_RESOLVED,\n type RawResponseDataWithMaybeCacheMetadata,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_RESOLVED,\n} from '@graphql-box/core';\nimport {\n ArgsError,\n EventAsyncIterator,\n GroupedError,\n deserializeErrors,\n hashRequest,\n isPlainObject,\n rehydrateCacheMetadata,\n} from '@graphql-box/helpers';\nimport { type RequestParserDef } from '@graphql-box/request-parser';\nimport { EventEmitter } from 'eventemitter3';\nimport { OperationTypeNode } from 'graphql';\nimport { isError } from 'lodash-es';\nimport { v4 as uuid } from 'uuid';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from './constants.ts';\nimport { logRequest } from './debug/logRequest.ts';\nimport { logSubscription } from './debug/logSubscription.ts';\nimport {\n type MessageContext,\n type MessageRequestPayload,\n type MessageResponsePayload,\n type PendingResolver,\n type PendingTracker,\n type UserOptions,\n} from './types.ts';\n\nexport class WorkerClient {\n private static _getMessageContext({\n hasDeferOrStream = false,\n initiator,\n operation,\n requestID,\n }: RequestContext): MessageContext {\n return { hasDeferOrStream, initiator, operation, requestID };\n }\n\n private static _resolve(\n { cacheMetadata, ...rest }: PartialResponseData,\n options: RequestOptions,\n { requestID }: RequestContext,\n ): PartialRequestResult {\n const result: PartialRequestResult = { ...rest, requestID };\n\n if (options.returnCacheMetadata && cacheMetadata) {\n result._cacheMetadata = cacheMetadata;\n }\n\n return result;\n }\n\n private _onMessage = ({ data }: MessageEvent<MessageResponsePayload>): void => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data;\n\n if (type !== GRAPHQL_BOX) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: PartialRequestResult = { ...deserializeErrors(otherProps), requestID: context.requestID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === SUBSCRIBE) {\n this._debugManager?.log(SUBSCRIPTION_RESOLVED, {\n context,\n result: response,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(context.requestID, response);\n } else if (context.hasDeferOrStream) {\n const pending = this._pending.get(context.requestID);\n\n if (pending) {\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, context.requestID);\n pending.resolve(eventAsyncIterator.getIterator());\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n context,\n result: response,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(context.requestID, response);\n } else {\n const pending = this._pending.get(context.requestID);\n\n if (!pending) {\n return;\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n context,\n result: response,\n stats: { endTime: this._debugManager.now() },\n });\n\n if (context.operation === OperationTypeNode.QUERY && pending.requestData && pending.options && pending.context) {\n void this._cacheManager.cacheQuery(\n pending.requestData,\n undefined,\n // Need to look at what type guards can be put in place\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n response as RawResponseDataWithMaybeCacheMetadata,\n pending.options,\n pending.context,\n );\n }\n\n pending.resolve(response);\n }\n };\n\n /**\n * This cache instance does not actually store anything itself,\n * it is for communicating with the worker cache that the worker\n * client is using within the worker.\n */\n private _cache: CoreWorker;\n private _cacheManager: CacheManagerDef;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _experimentalDeferStreamSupport: boolean;\n private _messageQueue: MessageRequestPayload[] = [];\n private _pending: PendingTracker = new Map();\n private _requestParser: RequestParserDef;\n private _worker: Worker | undefined;\n\n constructor(options: UserOptions) {\n const errors: ArgsError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options to ba a plain object.'));\n }\n\n if (!('cache' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cache.'));\n }\n\n if (!('cacheManager' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cacheManager.'));\n }\n\n if (!('requestParser' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.requestParser.'));\n }\n\n if (!options.lazyWorkerInit && !('worker' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.worker.'));\n }\n\n if (errors.length > 0) {\n throw new GroupedError('@graphql-box/worker-client argument validation errors.', errors);\n }\n\n this._cache = options.cache;\n this._cacheManager = options.cacheManager;\n this._debugManager = options.debugManager ?? null;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n this._requestParser = options.requestParser;\n\n if (typeof options.worker === 'function') {\n Promise.resolve(options.worker())\n .then(worker => {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n })\n .catch((error: unknown) => {\n throw error;\n });\n } else if (options.worker) {\n this._worker = options.worker;\n this._addEventListener();\n }\n }\n\n get cache(): CoreWorker {\n return this._cache;\n }\n\n get cacheManager(): CacheManagerDef {\n return this._cacheManager;\n }\n\n public async mutate(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(OperationTypeNode.MUTATION, request, context));\n }\n\n public async query(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._query(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, context));\n }\n\n public async request(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(OperationTypeNode.SUBSCRIPTION, request));\n }\n\n public set worker(worker: Worker) {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n }\n\n private _addEventListener(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: OperationTypeNode,\n request: string,\n context: PartialRequestContext = {},\n ): RequestContext {\n return {\n debugManager: this._debugManager,\n experimentalDeferStreamSupport: this._experimentalDeferStreamSupport,\n fieldTypeMap: new Map(),\n filteredRequest: '',\n operation,\n operationName: '',\n originalRequestHash: hashRequest(request),\n parsedRequest: '',\n queryFiltered: false,\n request,\n requestComplexity: null,\n requestDepth: null,\n requestID: uuid(),\n ...context,\n };\n }\n\n private async _query(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n const { ast, request: updateRequest } = this._requestParser.updateRequest(request, options, context);\n const requestData = { ast, hash: hashRequest(updateRequest), request: updateRequest };\n const checkResult = await this._cacheManager.checkQueryResponseCacheEntry(requestData.hash, options, context);\n\n if (checkResult) {\n return WorkerClient._resolve(checkResult, options, context);\n }\n\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(context.requestID, { context, options, requestData, resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: context.requestID };\n }\n }\n\n private _releaseMessageQueue(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n const messageQueue = [...this._messageQueue];\n this._messageQueue = [];\n\n for (const message of messageQueue) {\n this._worker.postMessage(message);\n }\n }\n\n @logRequest()\n private async _request(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(context.requestID, { resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: context.requestID };\n }\n }\n\n @logSubscription()\n private _subscribe(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n if (this._worker) {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, context.requestID);\n return Promise.resolve(eventAsyncIterator.getIterator());\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client subscribe had an unexpected error.');\n\n return Promise.resolve({ errors: [confirmedError], requestID: context.requestID });\n }\n }\n}\n","import {\n type PartialRequestResult,\n REQUEST_EXECUTED,\n REQUEST_RESOLVED,\n type RequestContext,\n type RequestOptions,\n} from '@graphql-box/core';\nimport { isAsyncIterable } from 'iterall';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logRequest = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { debugManager, ...otherContext } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(REQUEST_EXECUTED, {\n context: { ...otherContext, operationName: derivedOperationName },\n options: args[1],\n request: args[0],\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n const endTime = debugManager.now();\n const duration = endTime - startTime;\n resolve(result);\n\n if (isAsyncIterable(result)) {\n return;\n }\n\n debugManager.log(REQUEST_RESOLVED, {\n context: { ...otherContext, operationName: derivedOperationName },\n options: args[1],\n request: args[0],\n result,\n stats: { duration, endTime, startTime },\n });\n })();\n });\n };\n };\n};\n","import {\n type PartialRequestResult,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_EXECUTED,\n} from '@graphql-box/core';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logSubscription = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { debugManager, ...otherContext } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(SUBSCRIPTION_EXECUTED, {\n context: { ...otherContext, operationName: derivedOperationName },\n options: args[1],\n request: args[0],\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n resolve(result);\n })();\n });\n };\n };\n};\n","import { type PostMessage as CachemapMessageRequestPayload } from '@cachemap/core-worker';\nimport { GRAPHQL_BOX } from '../constants.ts';\nimport { type MessageRequestPayload } from '../types.ts';\n\nexport const isGraphqlBoxMessageRequestPayload = (\n payload: MessageRequestPayload | CachemapMessageRequestPayload,\n): payload is MessageRequestPayload => payload.type === GRAPHQL_BOX;\n","import {\n type PostMessage as CachemapMessageRequestPayload,\n handleMessage as handleCachemapMessage,\n} from '@cachemap/core-worker';\nimport { type Client } from '@graphql-box/client';\nimport { type PartialDehydratedRequestResult, type PartialRequestResult, type RequestOptions } from '@graphql-box/core';\nimport { dehydrateCacheMetadata, serializeErrors } from '@graphql-box/helpers';\nimport { forAwaitEach, isAsyncIterable } from 'iterall';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST } from './constants.ts';\nimport { isGraphqlBoxMessageRequestPayload } from './helpers/isGraphqlBoxMessageRequestPayload.ts';\nimport {\n type MessageContext,\n type MessageRequestPayload,\n type MethodNames,\n type RegisterWorkerOptions,\n} from './types.ts';\n\nconst handleRequest = async (\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 // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const { _cacheMetadata, ...otherProps } = requestResult as PartialRequestResult;\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n void forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nconst handleSubscription = async (\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 globalThis.postMessage({\n context,\n method,\n // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n result: serializeErrors(subscribeResult as PartialRequestResult),\n type: GRAPHQL_BOX,\n });\n\n return;\n }\n\n void forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nexport const handleMessage = (data: MessageRequestPayload, client: Client): void => {\n const { context, method, options, request } = data;\n\n if (method === REQUEST) {\n void handleRequest(request, method, options, context, client);\n } else {\n void handleSubscription(request, method, options, context, client);\n }\n};\n\nexport const registerWorker = ({ client }: RegisterWorkerOptions): void => {\n const onMessage = ({ data }: MessageEvent<MessageRequestPayload | CachemapMessageRequestPayload>): void => {\n if (isGraphqlBoxMessageRequestPayload(data)) {\n handleMessage(data, client);\n } else if (client.cache) {\n void handleCachemapMessage(data, client.cache);\n }\n };\n\n globalThis.addEventListener(MESSAGE, onMessage);\n};\n"],"names":["GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","operationNameRegex","request","output","exec","WorkerClient","_getMessageContext","hasDeferOrStream","initiator","operation","requestID","_resolve","cacheMetadata","rest","options","result","returnCacheMetadata","_cacheMetadata","constructor","_onMessage","data","isPlainObject","context","method","type","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","OperationTypeNode","QUERY","requestData","_cacheManager","cacheQuery","undefined","_messageQueue","Map","errors","push","ArgsError","lazyWorkerInit","length","GroupedError","_cache","cache","cacheManager","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_requestParser","requestParser","worker","Promise","then","_worker","_addEventListener","_releaseMessageQueue","catch","error","mutate","_request","_getRequestContext","MUTATION","query","_query","subscribe","_subscribe","SUBSCRIPTION","Error","addEventListener","fieldTypeMap","filteredRequest","operationName","originalRequestHash","hashRequest","parsedRequest","queryFiltered","requestComplexity","requestDepth","uuid","ast","updateRequest","hash","checkResult","checkQueryResponseCacheEntry","postMessage","set","isError","messageQueue","message","confirmedError","_target","_propertyName","descriptor","value","async","args","otherContext","apply","derivedOperationName","startTime","REQUEST_EXECUTED","duration","isAsyncIterable","SUBSCRIPTION_EXECUTED","handleMessage","client","requestResult","serializeErrors","dehydrateCacheMetadata","globalThis","forAwaitEach","handleRequest","subscribeResult","handleSubscription","handleCachemapMessage","onMessage"],"mappings":"+QAAO,MACMA,EAAc,aACdC,EAAU,UACVC,EAAU,UACVC,EAAY,YCJZC,EAAsBC,IACjC,MAAMC,EAAS,mDAAmDC,KAAKF,GACvE,OAAOC,EAASA,EAAO,GAAK,EAAA,qbCqCvB,MAAME,EACX,yBAAeC,EAAmBC,iBAChCA,GAAmB,EAAKC,UACxBA,EAASC,UACTA,EAASC,UACTA,IAEA,MAAO,CAAEH,mBAAkBC,YAAWC,YAAWC,YACnD,CAEA,eAAeC,EACbC,cAAEA,KAAkBC,GACpBC,GACAJ,UAAEA,IAEF,MAAMK,EAA+B,IAAKF,EAAMH,aAMhD,OAJII,EAAQE,qBAAuBJ,IACjCG,EAAOE,eAAiBL,GAGnBG,CACT,CAuFAG,WAAAA,CAAYJ,QArFJK,WAAa,EAAGC,WACtB,IAAKC,EAAAA,cAAcD,GACjB,OAGF,MAAME,QAAEA,EAAOC,OAAEA,EA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G,KAEA,MAAMO,QAAwBP,EAAOzC,UAAUjF,EAASY,EAASQ,GAE5DmG,EAAAA,gBAAgBU,GAahBF,EAAAA,aAAaE,GAAiB,EAAGlH,oBAAmBQ,MACvD,MAAMV,EAAyC+G,EAAAA,gBAAgB,IAAKrG,IAEhER,IACFF,EAAOE,eAAiB8G,EAAuB9G,uBAAAA,IAGjD+G,WAAWzB,YAAY,CAAEjF,UAASC,SAAQR,SAAQS,KAAM3B,GAAY,IAnBpEmI,WAAWzB,YAAY,CACrBjF,UACAC,SAGAR,OAAQ+G,EAAgBK,gBAAAA,GACxB3G,KAAM3B,GAcV,EASOuI,CAAmBlI,EAASqB,EAAQT,EAASQ,EAASsG,EAC7D,mBN3FsB,+JM8FM,EAAGA,aAS/BI,WAAWzC,iBAAiBzF,GARV,EAAGsB,WACmBA,ED1FKI,OAAS3B,EC2FlD8H,EAAcvG,EAAMwG,GACXA,EAAO/D,OACXwE,gBAAsBjH,EAAMwG,EAAO/D,MAC1C,GAGmCyE"}
1
+ {"version":3,"file":"index.cjs","sources":["../worker-client/src//constants.ts","../worker-client/src//helpers/operationNameRegex.ts","../worker-client/src//main.ts","../worker-client/src//debug/logRequest.ts","../worker-client/src//debug/logSubscription.ts","../worker-client/src//helpers/isGraphqlBoxMessageRequestPayload.ts","../worker-client/src//registerWorker.ts"],"sourcesContent":["export const CACHEMAP = 'cachemap';\nexport const GRAPHQL_BOX = 'graphqlBox';\nexport const MESSAGE = 'message';\nexport const REQUEST = 'request';\nexport const SUBSCRIBE = 'subscribe';\n","export const operationNameRegex = (request: string) => {\n const output = /(query|mutation|subscription) ([A-Za-z]+)(\\(| {)/.exec(request);\n return output ? output[2] : '';\n};\n","import { type CoreWorker } from '@cachemap/core-worker';\nimport { type CacheManagerDef } from '@graphql-box/cache-manager';\nimport {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n type PartialResponseData,\n REQUEST_RESOLVED,\n type RawResponseDataWithMaybeCacheMetadata,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_RESOLVED,\n} from '@graphql-box/core';\nimport {\n ArgsError,\n EventAsyncIterator,\n GroupedError,\n deserializeErrors,\n hashRequest,\n isPlainObject,\n rehydrateCacheMetadata,\n} from '@graphql-box/helpers';\nimport { type RequestParserDef } from '@graphql-box/request-parser';\nimport { EventEmitter } from 'eventemitter3';\nimport { OperationTypeNode } from 'graphql';\nimport { isError, merge } from 'lodash-es';\nimport { v4 as uuid } from 'uuid';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from './constants.ts';\nimport { logRequest } from './debug/logRequest.ts';\nimport { logSubscription } from './debug/logSubscription.ts';\nimport {\n type MessageRequestPayload,\n type MessageResponsePayload,\n type PendingResolver,\n type PendingTracker,\n type UserOptions,\n} from './types.ts';\n\nexport class WorkerClient {\n private static _resolve(\n { cacheMetadata, ...rest }: PartialResponseData,\n options: RequestOptions,\n { data }: RequestContext,\n ): PartialRequestResult {\n const result: PartialRequestResult = { ...rest, requestID: data.requestID };\n\n if (options.returnCacheMetadata && cacheMetadata) {\n result._cacheMetadata = cacheMetadata;\n }\n\n return result;\n }\n\n private _onMessage = ({ data }: MessageEvent<MessageResponsePayload>): void => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data;\n\n if (type !== GRAPHQL_BOX) {\n return;\n }\n\n const { operation, requestID } = context.data;\n const { hasDeferOrStream } = context.deprecated;\n const { _cacheMetadata, ...otherProps } = result;\n const response: PartialRequestResult = { ...deserializeErrors(otherProps), requestID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === SUBSCRIBE) {\n this._debugManager?.log(SUBSCRIPTION_RESOLVED, {\n data: context.data,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(requestID, response);\n } else if (hasDeferOrStream) {\n const pending = this._pending.get(requestID);\n\n if (pending) {\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, requestID);\n pending.resolve(eventAsyncIterator.getIterator());\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n data: context.data,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(requestID, response);\n } else {\n const pending = this._pending.get(requestID);\n\n if (!pending) {\n return;\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n data: context.data,\n stats: { endTime: this._debugManager.now() },\n });\n\n if (operation === OperationTypeNode.QUERY && pending.requestData && pending.options && pending.context) {\n void this._cacheManager.cacheQuery(\n pending.requestData,\n undefined,\n // Need to look at what type guards can be put in place\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n response as RawResponseDataWithMaybeCacheMetadata,\n pending.options,\n pending.context,\n );\n }\n\n pending.resolve(response);\n }\n };\n\n /**\n * This cache instance does not actually store anything itself,\n * it is for communicating with the worker cache that the worker\n * client is using within the worker.\n */\n private readonly _cache: CoreWorker;\n private readonly _cacheManager: CacheManagerDef;\n private readonly _debugManager: DebugManagerDef | undefined;\n private readonly _eventEmitter: EventEmitter;\n private readonly _experimentalDeferStreamSupport: boolean;\n private _messageQueue: MessageRequestPayload[] = [];\n private _pending: PendingTracker = new Map();\n private _requestParser: RequestParserDef;\n private _worker: Worker | undefined;\n\n constructor(options: UserOptions) {\n const errors: ArgsError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options to ba a plain object.'));\n }\n\n if (!('cache' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cache.'));\n }\n\n if (!('cacheManager' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cacheManager.'));\n }\n\n if (!('requestParser' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.requestParser.'));\n }\n\n if (!options.lazyWorkerInit && !('worker' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.worker.'));\n }\n\n if (errors.length > 0) {\n throw new GroupedError('@graphql-box/worker-client argument validation errors.', errors);\n }\n\n this._cache = options.cache;\n this._cacheManager = options.cacheManager;\n this._debugManager = options.debugManager;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n this._requestParser = options.requestParser;\n\n if (typeof options.worker === 'function') {\n Promise.resolve(options.worker())\n .then(worker => {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n })\n .catch((error: unknown) => {\n throw error;\n });\n } else if (options.worker) {\n this._worker = options.worker;\n this._addEventListener();\n }\n }\n\n get cache(): CoreWorker {\n return this._cache;\n }\n\n get cacheManager(): CacheManagerDef {\n return this._cacheManager;\n }\n\n public async mutate(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(\n request,\n options,\n this._getRequestContext(OperationTypeNode.MUTATION, request, options, context),\n );\n }\n\n public async query(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._query(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, options, context));\n }\n\n public async request(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, options, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._subscribe(\n request,\n options,\n this._getRequestContext(OperationTypeNode.SUBSCRIPTION, request, options, context),\n );\n }\n\n public set worker(worker: Worker) {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n }\n\n private _addEventListener(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: OperationTypeNode,\n request: string,\n options: RequestOptions,\n context: PartialRequestContext,\n ): RequestContext {\n return merge(\n {\n data: {\n batched: options.batch,\n operation,\n operationName: '',\n originalRequestHash: hashRequest(request),\n queryFiltered: false,\n requestComplexity: undefined,\n requestDepth: undefined,\n requestID: uuid(),\n tag: options.tag,\n variables: options.variables,\n },\n debugManager: this._debugManager,\n deprecated: {\n experimentalDeferStreamSupport: this._experimentalDeferStreamSupport,\n },\n fieldTypeMap: new Map(),\n filteredRequest: '',\n parsedRequest: '',\n request,\n },\n context,\n );\n }\n\n private async _query(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n const { ast, request: updateRequest } = this._requestParser.updateRequest(request, options, context);\n const requestData = { ast, hash: hashRequest(updateRequest), request: updateRequest };\n const checkResult = await this._cacheManager.checkQueryResponseCacheEntry(requestData.hash, options, context);\n\n if (checkResult) {\n return WorkerClient._resolve(checkResult, options, context);\n }\n\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: {\n data: context.data,\n deprecated: context.deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: {\n data: context.data,\n deprecated: context.deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(context.data.requestID, { context, options, requestData, resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: context.data.requestID };\n }\n }\n\n private _releaseMessageQueue(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n const messageQueue = [...this._messageQueue];\n this._messageQueue = [];\n\n for (const message of messageQueue) {\n this._worker.postMessage(message);\n }\n }\n\n @logRequest()\n private async _request(\n request: string,\n options: RequestOptions,\n { data, deprecated }: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: {\n data,\n deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: {\n data,\n deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(data.requestID, { resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: data.requestID };\n }\n }\n\n @logSubscription()\n private _subscribe(\n request: string,\n options: RequestOptions,\n { data, deprecated }: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n if (this._worker) {\n this._worker.postMessage({\n context: {\n data,\n deprecated,\n },\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: {\n data,\n deprecated,\n },\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, data.requestID);\n\n return Promise.resolve(eventAsyncIterator.getIterator());\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client subscribe had an unexpected error.');\n\n return Promise.resolve({ errors: [confirmedError], requestID: data.requestID });\n }\n }\n}\n","import {\n type PartialRequestResult,\n REQUEST_EXECUTED,\n REQUEST_RESOLVED,\n type RequestContext,\n type RequestOptions,\n} from '@graphql-box/core';\nimport { isAsyncIterable } from 'iterall';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logRequest = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { data, debugManager } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(REQUEST_EXECUTED, {\n data: {\n ...data,\n ...(!data.operationName && derivedOperationName ? { operationName: derivedOperationName } : undefined),\n },\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n const endTime = debugManager.now();\n const duration = endTime - startTime;\n resolve(result);\n\n if (isAsyncIterable(result)) {\n return;\n }\n\n debugManager.log(REQUEST_RESOLVED, {\n data: {\n ...data,\n ...(!data.operationName && derivedOperationName ? { operationName: derivedOperationName } : undefined),\n },\n stats: { duration, endTime, startTime },\n });\n })();\n });\n };\n };\n};\n","import {\n type PartialRequestResult,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_EXECUTED,\n} from '@graphql-box/core';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logSubscription = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { data, debugManager } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(SUBSCRIPTION_EXECUTED, {\n data: {\n ...data,\n ...(!data.operationName && derivedOperationName ? { operationName: derivedOperationName } : undefined),\n },\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n resolve(result);\n })();\n });\n };\n };\n};\n","import { type PostMessage as CachemapMessageRequestPayload } from '@cachemap/core-worker';\nimport { GRAPHQL_BOX } from '../constants.ts';\nimport { type MessageRequestPayload } from '../types.ts';\n\nexport const isGraphqlBoxMessageRequestPayload = (\n payload: MessageRequestPayload | CachemapMessageRequestPayload,\n): payload is MessageRequestPayload => payload.type === GRAPHQL_BOX;\n","import {\n type PostMessage as CachemapMessageRequestPayload,\n handleMessage as handleCachemapMessage,\n} from '@cachemap/core-worker';\nimport { type Client } from '@graphql-box/client';\nimport { type PartialDehydratedRequestResult, type PartialRequestResult, type RequestOptions } from '@graphql-box/core';\nimport { dehydrateCacheMetadata, serializeErrors } from '@graphql-box/helpers';\nimport { forAwaitEach, isAsyncIterable } from 'iterall';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST } from './constants.ts';\nimport { isGraphqlBoxMessageRequestPayload } from './helpers/isGraphqlBoxMessageRequestPayload.ts';\nimport {\n type MessageContext,\n type MessageRequestPayload,\n type MethodNames,\n type RegisterWorkerOptions,\n} from './types.ts';\n\nconst handleRequest = async (\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 // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const { _cacheMetadata, ...otherProps } = requestResult as PartialRequestResult;\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n void forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nconst handleSubscription = async (\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 globalThis.postMessage({\n context,\n method,\n // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n result: serializeErrors(subscribeResult as PartialRequestResult),\n type: GRAPHQL_BOX,\n });\n\n return;\n }\n\n void forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nexport const handleMessage = (data: MessageRequestPayload, client: Client): void => {\n const { context, method, options, request } = data;\n\n if (method === REQUEST) {\n void handleRequest(request, method, options, context, client);\n } else {\n void handleSubscription(request, method, options, context, client);\n }\n};\n\nexport const registerWorker = ({ client }: RegisterWorkerOptions): void => {\n const onMessage = ({ data }: MessageEvent<MessageRequestPayload | CachemapMessageRequestPayload>): void => {\n if (isGraphqlBoxMessageRequestPayload(data)) {\n handleMessage(data, client);\n } else if (client.cache) {\n void handleCachemapMessage(data, client.cache);\n }\n };\n\n globalThis.addEventListener(MESSAGE, onMessage);\n};\n"],"names":["GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","operationNameRegex","request","output","exec","WorkerClient","_resolve","cacheMetadata","rest","options","data","result","requestID","returnCacheMetadata","_cacheMetadata","constructor","_onMessage","isPlainObject","context","method","type","operation","hasDeferOrStream","deprecated","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","OperationTypeNode","QUERY","requestData","_cacheManager","cacheQuery","undefined","_messageQueue","Map","errors","push","ArgsError","lazyWorkerInit","length","GroupedError","_cache","cache","cacheManager","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_requestParser","requestParser","worker","Promise","then","_worker","_addEventListener","_releaseMessageQueue","catch","error","mutate","_request","_getRequestContext","MUTATION","query","_query","subscribe","_subscribe","SUBSCRIPTION","Error","addEventListener","merge","batched","batch","operationName","originalRequestHash","hashRequest","queryFiltered","requestComplexity","requestDepth","uuid","tag","variables","fieldTypeMap","filteredRequest","parsedRequest","ast","updateRequest","hash","checkResult","checkQueryResponseCacheEntry","postMessage","set","isError","messageQueue","message","confirmedError","_target","_propertyName","descriptor","value","async","args","apply","derivedOperationName","startTime","REQUEST_EXECUTED","duration","isAsyncIterable","SUBSCRIPTION_EXECUTED","handleMessage","client","requestResult","serializeErrors","dehydrateCacheMetadata","globalThis","forAwaitEach","handleRequest","subscribeResult","handleSubscription","handleCachemapMessage","onMessage"],"mappings":"+QAAO,MACMA,EAAc,aACdC,EAAU,UACVC,EAAU,UACVC,EAAY,YCJZC,EAAsBC,IACjC,MAAMC,EAAS,mDAAmDC,KAAKF,GACvE,OAAOC,EAASA,EAAO,GAAK,EAAA,qbCoCvB,MAAME,EACX,eAAeC,EACbC,cAAEA,KAAkBC,GACpBC,GACAC,KAAEA,IAEF,MAAMC,EAA+B,IAAKH,EAAMI,UAAWF,EAAKE,WAMhE,OAJIH,EAAQI,qBAAuBN,IACjCI,EAAOG,eAAiBP,GAGnBI,CACT,CAsFAI,WAAAA,CAAYN,QApFJO,WAAa,EAAGN,WACtB,IAAKO,EAAAA,cAAcP,GACjB,OAGF,MAAMQ,QAAEA,EAAOC,OAAEA,EAAMR,OAAEA,EAAMS,KAAEA,GAASV,EAE1C,GAAIU,IAASvB,EACX,OAGF,MAAMwB,UAAEA,EAAST,UAAEA,GAAcM,EAAQR,MACnCY,iBAAEA,GAAqBJ,EAAQK,YAC/BT,eAAEA,KAAmBU,GAAeb,EACpCc,EAAiC,IAAKC,EAAAA,kBAAkBF,GAAaZ,aAM3E,GAJIE,IACFW,EAASX,eA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O,QAAwBP,EAAO7C,UAAUhF,EAASO,EAASS,GAE5D0G,EAAAA,gBAAgBU,GAahBF,EAAAA,aAAaE,GAAiB,EAAGxH,oBAAmBU,MACvD,MAAMb,EAAyCsH,EAAAA,gBAAgB,IAAKzG,IAEhEV,IACFH,EAAOG,eAAiBoH,EAAuBpH,uBAAAA,IAGjDqH,WAAWxB,YAAY,CAAEzF,UAASC,SAAQR,SAAQS,KAAMvB,GAAY,IAnBpEsI,WAAWxB,YAAY,CACrBzF,UACAC,SAGAR,OAAQsH,EAAgBK,gBAAAA,GACxBlH,KAAMvB,GAcV,EASO0I,CAAmBrI,EAASiB,EAAQV,EAASS,EAAS6G,EAC7D,mBN3FsB,+JM8FM,EAAGA,aAS/BI,WAAW7C,iBAAiBxF,GARV,EAAGY,WACmBA,ED1FKU,OAASvB,EC2FlDiI,EAAcpH,EAAMqH,GACXA,EAAOnE,OACX4E,gBAAsB9H,EAAMqH,EAAOnE,MAC1C,GAGmC6E"}
@@ -1,2 +1,2 @@
1
- import"core-js/modules/es.array.push.js";import{REQUEST_EXECUTED as e,REQUEST_RESOLVED as t,SUBSCRIPTION_EXECUTED as r,SUBSCRIPTION_RESOLVED as s}from"@graphql-box/core";import{isPlainObject as o,deserializeErrors as a,rehydrateCacheMetadata as n,EventAsyncIterator as i,ArgsError as u,GroupedError as c,hashRequest as h,serializeErrors as p,dehydrateCacheMetadata as g}from"@graphql-box/helpers";import{EventEmitter as l}from"eventemitter3";import{OperationTypeNode as d}from"graphql";import{isError as q}from"lodash-es";import{v4 as _}from"uuid";import{isAsyncIterable as m,forAwaitEach as w}from"iterall";import{handleMessage as f}from"@cachemap/core-worker";const y="cachemap",x="graphqlBox",M="message",b="request",k="subscribe",D=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function v(e,t,r,s){var o,a=arguments.length,n=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(n=(a<3?o(n):a>3?o(t,r,n):o(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n}function R(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class I{static _getMessageContext({hasDeferOrStream:e=!1,initiator:t,operation:r,requestID:s}){return{hasDeferOrStream:e,initiator:t,operation:r,requestID:s}}static _resolve({cacheMetadata:e,...t},r,{requestID:s}){const o={...t,requestID:s};return r.returnCacheMetadata&&e&&(o._cacheMetadata=e),o}constructor(e){this._onMessage=({data:e})=>{if(!o(e))return;const{context:r,method:u,result:c,type:h}=e;if(h!==x)return;const{_cacheMetadata:p,...g}=c,l={...a(g),requestID:r.requestID};if(p&&(l._cacheMetadata=n(p)),u===k)this._debugManager?.log(s,{context:r,result:l,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(r.requestID,l);else if(r.hasDeferOrStream){const e=this._pending.get(r.requestID);if(e){const t=new i(this._eventEmitter,r.requestID);e.resolve(t.getIterator())}this._debugManager?.log(t,{context:r,result:l,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(r.requestID,l)}else{const e=this._pending.get(r.requestID);if(!e)return;this._debugManager?.log(t,{context:r,result:l,stats:{endTime:this._debugManager.now()}}),r.operation===d.QUERY&&e.requestData&&e.options&&e.context&&this._cacheManager.cacheQuery(e.requestData,void 0,l,e.options,e.context),e.resolve(l)}},this._messageQueue=[],this._pending=new Map;const r=[];if(o(e)||r.push(new u("@graphql-box/worker-client expected options to ba a plain object.")),"cache"in e||r.push(new u("@graphql-box/worker-client expected options.cache.")),"cacheManager"in e||r.push(new u("@graphql-box/worker-client expected options.cacheManager.")),"requestParser"in e||r.push(new u("@graphql-box/worker-client expected options.requestParser.")),e.lazyWorkerInit||"worker"in e||r.push(new u("@graphql-box/worker-client expected options.worker.")),r.length>0)throw new c("@graphql-box/worker-client argument validation errors.",r);this._cache=e.cache,this._cacheManager=e.cacheManager,this._debugManager=e.debugManager??null,this._eventEmitter=new l,this._experimentalDeferStreamSupport=e.experimentalDeferStreamSupport??!1,this._requestParser=e.requestParser,"function"==typeof e.worker?Promise.resolve(e.worker()).then((e=>{this._worker=e,this._addEventListener(),this._releaseMessageQueue()})).catch((e=>{throw e})):e.worker&&(this._worker=e.worker,this._addEventListener())}get cache(){return this._cache}get cacheManager(){return this._cacheManager}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(d.MUTATION,e,r))}async query(e,t={},r={}){return this._query(e,t,this._getRequestContext(d.QUERY,e,r))}async request(e,t={},r={}){return this._request(e,t,this._getRequestContext(d.QUERY,e,r))}async subscribe(e,t={}){return this._subscribe(e,t,this._getRequestContext(d.SUBSCRIPTION,e))}set worker(e){this._worker=e,this._addEventListener(),this._releaseMessageQueue()}_addEventListener(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");this._worker.addEventListener(M,this._onMessage)}_getRequestContext(e,t,r={}){return{debugManager:this._debugManager,experimentalDeferStreamSupport:this._experimentalDeferStreamSupport,fieldTypeMap:new Map,filteredRequest:"",operation:e,operationName:"",originalRequestHash:h(t),parsedRequest:"",queryFiltered:!1,request:t,requestComplexity:null,requestDepth:null,requestID:_(),...r}}async _query(e,t,r){try{const{ast:s,request:o}=this._requestParser.updateRequest(e,t,r),a={ast:s,hash:h(o),request:o},n=await this._cacheManager.checkQueryResponseCacheEntry(a.hash,t,r);return n?I._resolve(n,t,r):await new Promise((s=>{this._worker?this._worker.postMessage({context:I._getMessageContext(r),method:b,options:t,request:e,type:x}):this._messageQueue.push({context:I._getMessageContext(r),method:b,options:t,request:e,type:x}),this._pending.set(r.requestID,{context:r,options:t,requestData:a,resolve:s})}))}catch(e){return{errors:[q(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.requestID}}}_releaseMessageQueue(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");const e=[...this._messageQueue];this._messageQueue=[];for(const t of e)this._worker.postMessage(t)}async _request(e,t,r){try{return await new Promise((s=>{this._worker?this._worker.postMessage({context:I._getMessageContext(r),method:b,options:t,request:e,type:x}):this._messageQueue.push({context:I._getMessageContext(r),method:b,options:t,request:e,type:x}),this._pending.set(r.requestID,{resolve:s})}))}catch(e){return{errors:[q(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.requestID}}}_subscribe(e,t,r){try{this._worker?this._worker.postMessage({context:I._getMessageContext(r),method:k,options:t,request:e,type:x}):this._messageQueue.push({context:I._getMessageContext(r),method:k,options:t,request:e,type:x});const s=new i(this._eventEmitter,r.requestID);return Promise.resolve(s.getIterator())}catch(e){const t=q(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:r.requestID})}}}v([(r,s,o)=>{const a=o.value;a&&(o.value=async function(...r){return new Promise((s=>{(async()=>{const{debugManager:o,...n}=r[2];if(!o)return void s(await a.apply(this,r));const i=D(r[0]),u=o.now();o.log(e,{context:{...n,operationName:i},options:r[1],request:r[0],stats:{startTime:u}});const c=await a.apply(this,r),h=o.now(),p=h-u;s(c),m(c)||o.log(t,{context:{...n,operationName:i},options:r[1],request:r[0],result:c,stats:{duration:p,endTime:h,startTime:u}})})()}))})},R("design:type",Function),R("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),R("design:returntype",Promise)],I.prototype,"_request",null),v([(e,t,s)=>{const o=s.value;o&&(s.value=async function(...e){return new Promise((t=>{(async()=>{const{debugManager:s,...a}=e[2];if(!s)return void t(await o.apply(this,e));const n=D(e[0]),i=s.now();s.log(r,{context:{...a,operationName:n},options:e[1],request:e[0],stats:{startTime:i}});const u=await o.apply(this,e);t(u)})()}))})},R("design:type",Function),R("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),R("design:returntype","undefined"==typeof Promise?Object:Promise)],I.prototype,"_subscribe",null);const C=(e,t)=>{const{context:r,method:s,options:o,request:a}=e;s===b?(async(e,t,r,s,o)=>{const a=await o.request(e,r,s);if(!m(a)){const{_cacheMetadata:e,...r}=a,o=p({...r});return e&&(o._cacheMetadata=g(e)),void globalThis.postMessage({context:s,method:t,result:o,type:x})}w(a,(({_cacheMetadata:e,...r})=>{const o=p({...r});e&&(o._cacheMetadata=g(e)),globalThis.postMessage({context:s,method:t,result:o,type:x})}))})(a,s,o,r,t):(async(e,t,r,s,o)=>{const a=await o.subscribe(e,r,s);m(a)?w(a,(({_cacheMetadata:e,...r})=>{const o=p({...r});e&&(o._cacheMetadata=g(e)),globalThis.postMessage({context:s,method:t,result:o,type:x})})):globalThis.postMessage({context:s,method:t,result:p(a),type:x})})(a,s,o,r,t)},E=({client:e})=>{globalThis.addEventListener(M,(({data:t})=>{t.type===x?C(t,e):e.cache&&f(t,e.cache)}))};export{y as CACHEMAP,x as GRAPHQL_BOX,M as MESSAGE,b as REQUEST,k as SUBSCRIBE,I as WorkerClient,C as handleMessage,E as registerWorker};
1
+ import"core-js/modules/es.array.push.js";import{REQUEST_EXECUTED as e,REQUEST_RESOLVED as t,SUBSCRIPTION_EXECUTED as r,SUBSCRIPTION_RESOLVED as a}from"@graphql-box/core";import{isPlainObject as s,deserializeErrors as o,rehydrateCacheMetadata as n,EventAsyncIterator as i,ArgsError as c,GroupedError as u,hashRequest as h,serializeErrors as p,dehydrateCacheMetadata as d}from"@graphql-box/helpers";import{EventEmitter as g}from"eventemitter3";import{OperationTypeNode as l}from"graphql";import{merge as m,isError as _}from"lodash-es";import{v4 as q}from"uuid";import{isAsyncIterable as w,forAwaitEach as y}from"iterall";import{handleMessage as f}from"@cachemap/core-worker";const b="cachemap",x="graphqlBox",M="message",v="request",k="subscribe",R=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function D(e,t,r,a){var s,o=arguments.length,n=o<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,a);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(n=(o<3?s(n):o>3?s(t,r,n):s(t,r))||n);return o>3&&n&&Object.defineProperty(t,r,n),n}function E(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class I{static _resolve({cacheMetadata:e,...t},r,{data:a}){const s={...t,requestID:a.requestID};return r.returnCacheMetadata&&e&&(s._cacheMetadata=e),s}constructor(e){this._onMessage=({data:e})=>{if(!s(e))return;const{context:r,method:c,result:u,type:h}=e;if(h!==x)return;const{operation:p,requestID:d}=r.data,{hasDeferOrStream:g}=r.deprecated,{_cacheMetadata:m,..._}=u,q={...o(_),requestID:d};if(m&&(q._cacheMetadata=n(m)),c===k)this._debugManager?.log(a,{data:r.data,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(d,q);else if(g){const e=this._pending.get(d);if(e){const t=new i(this._eventEmitter,d);e.resolve(t.getIterator())}this._debugManager?.log(t,{data:r.data,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(d,q)}else{const e=this._pending.get(d);if(!e)return;this._debugManager?.log(t,{data:r.data,stats:{endTime:this._debugManager.now()}}),p===l.QUERY&&e.requestData&&e.options&&e.context&&this._cacheManager.cacheQuery(e.requestData,void 0,q,e.options,e.context),e.resolve(q)}},this._messageQueue=[],this._pending=new Map;const r=[];if(s(e)||r.push(new c("@graphql-box/worker-client expected options to ba a plain object.")),"cache"in e||r.push(new c("@graphql-box/worker-client expected options.cache.")),"cacheManager"in e||r.push(new c("@graphql-box/worker-client expected options.cacheManager.")),"requestParser"in e||r.push(new c("@graphql-box/worker-client expected options.requestParser.")),e.lazyWorkerInit||"worker"in e||r.push(new c("@graphql-box/worker-client expected options.worker.")),r.length>0)throw new u("@graphql-box/worker-client argument validation errors.",r);this._cache=e.cache,this._cacheManager=e.cacheManager,this._debugManager=e.debugManager,this._eventEmitter=new g,this._experimentalDeferStreamSupport=e.experimentalDeferStreamSupport??!1,this._requestParser=e.requestParser,"function"==typeof e.worker?Promise.resolve(e.worker()).then((e=>{this._worker=e,this._addEventListener(),this._releaseMessageQueue()})).catch((e=>{throw e})):e.worker&&(this._worker=e.worker,this._addEventListener())}get cache(){return this._cache}get cacheManager(){return this._cacheManager}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(l.MUTATION,e,t,r))}async query(e,t={},r={}){return this._query(e,t,this._getRequestContext(l.QUERY,e,t,r))}async request(e,t={},r={}){return this._request(e,t,this._getRequestContext(l.QUERY,e,t,r))}async subscribe(e,t={},r={}){return this._subscribe(e,t,this._getRequestContext(l.SUBSCRIPTION,e,t,r))}set worker(e){this._worker=e,this._addEventListener(),this._releaseMessageQueue()}_addEventListener(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");this._worker.addEventListener(M,this._onMessage)}_getRequestContext(e,t,r,a){return m({data:{batched:r.batch,operation:e,operationName:"",originalRequestHash:h(t),queryFiltered:!1,requestComplexity:void 0,requestDepth:void 0,requestID:q(),tag:r.tag,variables:r.variables},debugManager:this._debugManager,deprecated:{experimentalDeferStreamSupport:this._experimentalDeferStreamSupport},fieldTypeMap:new Map,filteredRequest:"",parsedRequest:"",request:t},a)}async _query(e,t,r){try{const{ast:a,request:s}=this._requestParser.updateRequest(e,t,r),o={ast:a,hash:h(s),request:s},n=await this._cacheManager.checkQueryResponseCacheEntry(o.hash,t,r);return n?I._resolve(n,t,r):await new Promise((a=>{this._worker?this._worker.postMessage({context:{data:r.data,deprecated:r.deprecated},method:v,options:t,request:e,type:x}):this._messageQueue.push({context:{data:r.data,deprecated:r.deprecated},method:v,options:t,request:e,type:x}),this._pending.set(r.data.requestID,{context:r,options:t,requestData:o,resolve:a})}))}catch(e){return{errors:[_(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.data.requestID}}}_releaseMessageQueue(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");const e=[...this._messageQueue];this._messageQueue=[];for(const t of e)this._worker.postMessage(t)}async _request(e,t,{data:r,deprecated:a}){try{return await new Promise((s=>{this._worker?this._worker.postMessage({context:{data:r,deprecated:a},method:v,options:t,request:e,type:x}):this._messageQueue.push({context:{data:r,deprecated:a},method:v,options:t,request:e,type:x}),this._pending.set(r.requestID,{resolve:s})}))}catch(e){return{errors:[_(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.requestID}}}_subscribe(e,t,{data:r,deprecated:a}){try{this._worker?this._worker.postMessage({context:{data:r,deprecated:a},method:k,options:t,request:e,type:x}):this._messageQueue.push({context:{data:r,deprecated:a},method:k,options:t,request:e,type:x});const s=new i(this._eventEmitter,r.requestID);return Promise.resolve(s.getIterator())}catch(e){const t=_(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:r.requestID})}}}D([(r,a,s)=>{const o=s.value;o&&(s.value=async function(...r){return new Promise((a=>{(async()=>{const{data:s,debugManager:n}=r[2];if(!n)return void a(await o.apply(this,r));const i=R(r[0]),c=n.now();n.log(e,{data:{...s,...!s.operationName&&i?{operationName:i}:void 0},stats:{startTime:c}});const u=await o.apply(this,r),h=n.now(),p=h-c;a(u),w(u)||n.log(t,{data:{...s,...!s.operationName&&i?{operationName:i}:void 0},stats:{duration:p,endTime:h,startTime:c}})})()}))})},E("design:type",Function),E("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),E("design:returntype",Promise)],I.prototype,"_request",null),D([(e,t,a)=>{const s=a.value;s&&(a.value=async function(...e){return new Promise((t=>{(async()=>{const{data:a,debugManager:o}=e[2];if(!o)return void t(await s.apply(this,e));const n=R(e[0]),i=o.now();o.log(r,{data:{...a,...!a.operationName&&n?{operationName:n}:void 0},stats:{startTime:i}});const c=await s.apply(this,e);t(c)})()}))})},E("design:type",Function),E("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),E("design:returntype","undefined"==typeof Promise?Object:Promise)],I.prototype,"_subscribe",null);const P=(e,t)=>{const{context:r,method:a,options:s,request:o}=e;a===v?(async(e,t,r,a,s)=>{const o=await s.request(e,r,a);if(!w(o)){const{_cacheMetadata:e,...r}=o,s=p({...r});return e&&(s._cacheMetadata=d(e)),void globalThis.postMessage({context:a,method:t,result:s,type:x})}y(o,(({_cacheMetadata:e,...r})=>{const s=p({...r});e&&(s._cacheMetadata=d(e)),globalThis.postMessage({context:a,method:t,result:s,type:x})}))})(o,a,s,r,t):(async(e,t,r,a,s)=>{const o=await s.subscribe(e,r,a);w(o)?y(o,(({_cacheMetadata:e,...r})=>{const s=p({...r});e&&(s._cacheMetadata=d(e)),globalThis.postMessage({context:a,method:t,result:s,type:x})})):globalThis.postMessage({context:a,method:t,result:p(o),type:x})})(o,a,s,r,t)},T=({client:e})=>{globalThis.addEventListener(M,(({data:t})=>{t.type===x?P(t,e):e.cache&&f(t,e.cache)}))};export{b as CACHEMAP,x as GRAPHQL_BOX,M as MESSAGE,v as REQUEST,k as SUBSCRIBE,I as WorkerClient,P as handleMessage,T as registerWorker};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../worker-client/src//constants.ts","../worker-client/src//helpers/operationNameRegex.ts","../worker-client/src//main.ts","../worker-client/src//debug/logRequest.ts","../worker-client/src//debug/logSubscription.ts","../worker-client/src//helpers/isGraphqlBoxMessageRequestPayload.ts","../worker-client/src//registerWorker.ts"],"sourcesContent":["export const CACHEMAP = 'cachemap';\nexport const GRAPHQL_BOX = 'graphqlBox';\nexport const MESSAGE = 'message';\nexport const REQUEST = 'request';\nexport const SUBSCRIBE = 'subscribe';\n","export const operationNameRegex = (request: string) => {\n const output = /(query|mutation|subscription) ([A-Za-z]+)(\\(| {)/.exec(request);\n return output ? output[2] : '';\n};\n","import { type CoreWorker } from '@cachemap/core-worker';\nimport { type CacheManagerDef } from '@graphql-box/cache-manager';\nimport {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n type PartialResponseData,\n REQUEST_RESOLVED,\n type RawResponseDataWithMaybeCacheMetadata,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_RESOLVED,\n} from '@graphql-box/core';\nimport {\n ArgsError,\n EventAsyncIterator,\n GroupedError,\n deserializeErrors,\n hashRequest,\n isPlainObject,\n rehydrateCacheMetadata,\n} from '@graphql-box/helpers';\nimport { type RequestParserDef } from '@graphql-box/request-parser';\nimport { EventEmitter } from 'eventemitter3';\nimport { OperationTypeNode } from 'graphql';\nimport { isError } from 'lodash-es';\nimport { v4 as uuid } from 'uuid';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from './constants.ts';\nimport { logRequest } from './debug/logRequest.ts';\nimport { logSubscription } from './debug/logSubscription.ts';\nimport {\n type MessageContext,\n type MessageRequestPayload,\n type MessageResponsePayload,\n type PendingResolver,\n type PendingTracker,\n type UserOptions,\n} from './types.ts';\n\nexport class WorkerClient {\n private static _getMessageContext({\n hasDeferOrStream = false,\n initiator,\n operation,\n requestID,\n }: RequestContext): MessageContext {\n return { hasDeferOrStream, initiator, operation, requestID };\n }\n\n private static _resolve(\n { cacheMetadata, ...rest }: PartialResponseData,\n options: RequestOptions,\n { requestID }: RequestContext,\n ): PartialRequestResult {\n const result: PartialRequestResult = { ...rest, requestID };\n\n if (options.returnCacheMetadata && cacheMetadata) {\n result._cacheMetadata = cacheMetadata;\n }\n\n return result;\n }\n\n private _onMessage = ({ data }: MessageEvent<MessageResponsePayload>): void => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data;\n\n if (type !== GRAPHQL_BOX) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: PartialRequestResult = { ...deserializeErrors(otherProps), requestID: context.requestID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === SUBSCRIBE) {\n this._debugManager?.log(SUBSCRIPTION_RESOLVED, {\n context,\n result: response,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(context.requestID, response);\n } else if (context.hasDeferOrStream) {\n const pending = this._pending.get(context.requestID);\n\n if (pending) {\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, context.requestID);\n pending.resolve(eventAsyncIterator.getIterator());\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n context,\n result: response,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(context.requestID, response);\n } else {\n const pending = this._pending.get(context.requestID);\n\n if (!pending) {\n return;\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n context,\n result: response,\n stats: { endTime: this._debugManager.now() },\n });\n\n if (context.operation === OperationTypeNode.QUERY && pending.requestData && pending.options && pending.context) {\n void this._cacheManager.cacheQuery(\n pending.requestData,\n undefined,\n // Need to look at what type guards can be put in place\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n response as RawResponseDataWithMaybeCacheMetadata,\n pending.options,\n pending.context,\n );\n }\n\n pending.resolve(response);\n }\n };\n\n /**\n * This cache instance does not actually store anything itself,\n * it is for communicating with the worker cache that the worker\n * client is using within the worker.\n */\n private _cache: CoreWorker;\n private _cacheManager: CacheManagerDef;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _experimentalDeferStreamSupport: boolean;\n private _messageQueue: MessageRequestPayload[] = [];\n private _pending: PendingTracker = new Map();\n private _requestParser: RequestParserDef;\n private _worker: Worker | undefined;\n\n constructor(options: UserOptions) {\n const errors: ArgsError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options to ba a plain object.'));\n }\n\n if (!('cache' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cache.'));\n }\n\n if (!('cacheManager' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cacheManager.'));\n }\n\n if (!('requestParser' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.requestParser.'));\n }\n\n if (!options.lazyWorkerInit && !('worker' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.worker.'));\n }\n\n if (errors.length > 0) {\n throw new GroupedError('@graphql-box/worker-client argument validation errors.', errors);\n }\n\n this._cache = options.cache;\n this._cacheManager = options.cacheManager;\n this._debugManager = options.debugManager ?? null;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n this._requestParser = options.requestParser;\n\n if (typeof options.worker === 'function') {\n Promise.resolve(options.worker())\n .then(worker => {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n })\n .catch((error: unknown) => {\n throw error;\n });\n } else if (options.worker) {\n this._worker = options.worker;\n this._addEventListener();\n }\n }\n\n get cache(): CoreWorker {\n return this._cache;\n }\n\n get cacheManager(): CacheManagerDef {\n return this._cacheManager;\n }\n\n public async mutate(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(OperationTypeNode.MUTATION, request, context));\n }\n\n public async query(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._query(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, context));\n }\n\n public async request(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(OperationTypeNode.SUBSCRIPTION, request));\n }\n\n public set worker(worker: Worker) {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n }\n\n private _addEventListener(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: OperationTypeNode,\n request: string,\n context: PartialRequestContext = {},\n ): RequestContext {\n return {\n debugManager: this._debugManager,\n experimentalDeferStreamSupport: this._experimentalDeferStreamSupport,\n fieldTypeMap: new Map(),\n filteredRequest: '',\n operation,\n operationName: '',\n originalRequestHash: hashRequest(request),\n parsedRequest: '',\n queryFiltered: false,\n request,\n requestComplexity: null,\n requestDepth: null,\n requestID: uuid(),\n ...context,\n };\n }\n\n private async _query(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n const { ast, request: updateRequest } = this._requestParser.updateRequest(request, options, context);\n const requestData = { ast, hash: hashRequest(updateRequest), request: updateRequest };\n const checkResult = await this._cacheManager.checkQueryResponseCacheEntry(requestData.hash, options, context);\n\n if (checkResult) {\n return WorkerClient._resolve(checkResult, options, context);\n }\n\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(context.requestID, { context, options, requestData, resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: context.requestID };\n }\n }\n\n private _releaseMessageQueue(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n const messageQueue = [...this._messageQueue];\n this._messageQueue = [];\n\n for (const message of messageQueue) {\n this._worker.postMessage(message);\n }\n }\n\n @logRequest()\n private async _request(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(context.requestID, { resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: context.requestID };\n }\n }\n\n @logSubscription()\n private _subscribe(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n if (this._worker) {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, context.requestID);\n return Promise.resolve(eventAsyncIterator.getIterator());\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client subscribe had an unexpected error.');\n\n return Promise.resolve({ errors: [confirmedError], requestID: context.requestID });\n }\n }\n}\n","import {\n type PartialRequestResult,\n REQUEST_EXECUTED,\n REQUEST_RESOLVED,\n type RequestContext,\n type RequestOptions,\n} from '@graphql-box/core';\nimport { isAsyncIterable } from 'iterall';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logRequest = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { debugManager, ...otherContext } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(REQUEST_EXECUTED, {\n context: { ...otherContext, operationName: derivedOperationName },\n options: args[1],\n request: args[0],\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n const endTime = debugManager.now();\n const duration = endTime - startTime;\n resolve(result);\n\n if (isAsyncIterable(result)) {\n return;\n }\n\n debugManager.log(REQUEST_RESOLVED, {\n context: { ...otherContext, operationName: derivedOperationName },\n options: args[1],\n request: args[0],\n result,\n stats: { duration, endTime, startTime },\n });\n })();\n });\n };\n };\n};\n","import {\n type PartialRequestResult,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_EXECUTED,\n} from '@graphql-box/core';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logSubscription = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { debugManager, ...otherContext } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(SUBSCRIPTION_EXECUTED, {\n context: { ...otherContext, operationName: derivedOperationName },\n options: args[1],\n request: args[0],\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n resolve(result);\n })();\n });\n };\n };\n};\n","import { type PostMessage as CachemapMessageRequestPayload } from '@cachemap/core-worker';\nimport { GRAPHQL_BOX } from '../constants.ts';\nimport { type MessageRequestPayload } from '../types.ts';\n\nexport const isGraphqlBoxMessageRequestPayload = (\n payload: MessageRequestPayload | CachemapMessageRequestPayload,\n): payload is MessageRequestPayload => payload.type === GRAPHQL_BOX;\n","import {\n type PostMessage as CachemapMessageRequestPayload,\n handleMessage as handleCachemapMessage,\n} from '@cachemap/core-worker';\nimport { type Client } from '@graphql-box/client';\nimport { type PartialDehydratedRequestResult, type PartialRequestResult, type RequestOptions } from '@graphql-box/core';\nimport { dehydrateCacheMetadata, serializeErrors } from '@graphql-box/helpers';\nimport { forAwaitEach, isAsyncIterable } from 'iterall';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST } from './constants.ts';\nimport { isGraphqlBoxMessageRequestPayload } from './helpers/isGraphqlBoxMessageRequestPayload.ts';\nimport {\n type MessageContext,\n type MessageRequestPayload,\n type MethodNames,\n type RegisterWorkerOptions,\n} from './types.ts';\n\nconst handleRequest = async (\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 // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const { _cacheMetadata, ...otherProps } = requestResult as PartialRequestResult;\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n void forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nconst handleSubscription = async (\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 globalThis.postMessage({\n context,\n method,\n // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n result: serializeErrors(subscribeResult as PartialRequestResult),\n type: GRAPHQL_BOX,\n });\n\n return;\n }\n\n void forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nexport const handleMessage = (data: MessageRequestPayload, client: Client): void => {\n const { context, method, options, request } = data;\n\n if (method === REQUEST) {\n void handleRequest(request, method, options, context, client);\n } else {\n void handleSubscription(request, method, options, context, client);\n }\n};\n\nexport const registerWorker = ({ client }: RegisterWorkerOptions): void => {\n const onMessage = ({ data }: MessageEvent<MessageRequestPayload | CachemapMessageRequestPayload>): void => {\n if (isGraphqlBoxMessageRequestPayload(data)) {\n handleMessage(data, client);\n } else if (client.cache) {\n void handleCachemapMessage(data, client.cache);\n }\n };\n\n globalThis.addEventListener(MESSAGE, onMessage);\n};\n"],"names":["CACHEMAP","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","operationNameRegex","request","output","exec","WorkerClient","_getMessageContext","hasDeferOrStream","initiator","operation","requestID","_resolve","cacheMetadata","rest","options","result","returnCacheMetadata","_cacheMetadata","constructor","_onMessage","data","isPlainObject","context","method","type","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","OperationTypeNode","QUERY","requestData","_cacheManager","cacheQuery","undefined","_messageQueue","Map","errors","push","ArgsError","lazyWorkerInit","length","GroupedError","_cache","cache","cacheManager","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_requestParser","requestParser","worker","Promise","then","_worker","_addEventListener","_releaseMessageQueue","catch","error","mutate","_request","_getRequestContext","MUTATION","query","_query","subscribe","_subscribe","SUBSCRIPTION","Error","addEventListener","fieldTypeMap","filteredRequest","operationName","originalRequestHash","hashRequest","parsedRequest","queryFiltered","requestComplexity","requestDepth","uuid","ast","updateRequest","hash","checkResult","checkQueryResponseCacheEntry","postMessage","set","isError","messageQueue","message","confirmedError","_target","_propertyName","descriptor","value","async","args","otherContext","apply","derivedOperationName","startTime","REQUEST_EXECUTED","duration","isAsyncIterable","SUBSCRIPTION_EXECUTED","handleMessage","client","requestResult","serializeErrors","dehydrateCacheMetadata","globalThis","forAwaitEach","handleRequest","subscribeResult","handleSubscription","registerWorker","handleCachemapMessage","onMessage"],"mappings":"spBAAO,MAAMA,EAAW,WACXC,EAAc,aACdC,EAAU,UACVC,EAAU,UACVC,EAAY,YCJZC,EAAsBC,IACjC,MAAMC,EAAS,mDAAmDC,KAAKF,GACvE,OAAOC,EAASA,EAAO,GAAK,EAAA,qbCqCvB,MAAME,EACX,yBAAeC,EAAmBC,iBAChCA,GAAmB,EAAKC,UACxBA,EAASC,UACTA,EAASC,UACTA,IAEA,MAAO,CAAEH,mBAAkBC,YAAWC,YAAWC,YACnD,CAEA,eAAeC,EACbC,cAAEA,KAAkBC,GACpBC,GACAJ,UAAEA,IAEF,MAAMK,EAA+B,IAAKF,EAAMH,aAMhD,OAJII,EAAQE,qBAAuBJ,IACjCG,EAAOE,eAAiBL,GAGnBG,CACT,CAuFAG,WAAAA,CAAYJ,QArFJK,WAAa,EAAGC,WACtB,IAAKC,EAAcD,GACjB,OAGF,MAAME,QAAEA,EAAOC,OAAEA,EAAMR,OAAEA,EAAMS,KAAEA,GAASJ,EAE1C,GAAII,IAAS3B,EACX,OAGF,MAAMoB,eAAE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UACAC,SAGAR,OAAQ+G,EAAgBK,GACxB3G,KAAM3B,GAcV,EASOuI,CAAmBlI,EAASqB,EAAQT,EAASQ,EAASsG,EAC7D,EAGWS,EAAiB,EAAGT,aAS/BI,WAAWzC,iBAAiBzF,GARV,EAAGsB,WACmBA,ED1FKI,OAAS3B,EC2FlD8H,EAAcvG,EAAMwG,GACXA,EAAO/D,OACXyE,EAAsBlH,EAAMwG,EAAO/D,MAC1C,GAGmC0E"}
1
+ {"version":3,"file":"index.mjs","sources":["../worker-client/src//constants.ts","../worker-client/src//helpers/operationNameRegex.ts","../worker-client/src//main.ts","../worker-client/src//debug/logRequest.ts","../worker-client/src//debug/logSubscription.ts","../worker-client/src//helpers/isGraphqlBoxMessageRequestPayload.ts","../worker-client/src//registerWorker.ts"],"sourcesContent":["export const CACHEMAP = 'cachemap';\nexport const GRAPHQL_BOX = 'graphqlBox';\nexport const MESSAGE = 'message';\nexport const REQUEST = 'request';\nexport const SUBSCRIBE = 'subscribe';\n","export const operationNameRegex = (request: string) => {\n const output = /(query|mutation|subscription) ([A-Za-z]+)(\\(| {)/.exec(request);\n return output ? output[2] : '';\n};\n","import { type CoreWorker } from '@cachemap/core-worker';\nimport { type CacheManagerDef } from '@graphql-box/cache-manager';\nimport {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n type PartialResponseData,\n REQUEST_RESOLVED,\n type RawResponseDataWithMaybeCacheMetadata,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_RESOLVED,\n} from '@graphql-box/core';\nimport {\n ArgsError,\n EventAsyncIterator,\n GroupedError,\n deserializeErrors,\n hashRequest,\n isPlainObject,\n rehydrateCacheMetadata,\n} from '@graphql-box/helpers';\nimport { type RequestParserDef } from '@graphql-box/request-parser';\nimport { EventEmitter } from 'eventemitter3';\nimport { OperationTypeNode } from 'graphql';\nimport { isError, merge } from 'lodash-es';\nimport { v4 as uuid } from 'uuid';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from './constants.ts';\nimport { logRequest } from './debug/logRequest.ts';\nimport { logSubscription } from './debug/logSubscription.ts';\nimport {\n type MessageRequestPayload,\n type MessageResponsePayload,\n type PendingResolver,\n type PendingTracker,\n type UserOptions,\n} from './types.ts';\n\nexport class WorkerClient {\n private static _resolve(\n { cacheMetadata, ...rest }: PartialResponseData,\n options: RequestOptions,\n { data }: RequestContext,\n ): PartialRequestResult {\n const result: PartialRequestResult = { ...rest, requestID: data.requestID };\n\n if (options.returnCacheMetadata && cacheMetadata) {\n result._cacheMetadata = cacheMetadata;\n }\n\n return result;\n }\n\n private _onMessage = ({ data }: MessageEvent<MessageResponsePayload>): void => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data;\n\n if (type !== GRAPHQL_BOX) {\n return;\n }\n\n const { operation, requestID } = context.data;\n const { hasDeferOrStream } = context.deprecated;\n const { _cacheMetadata, ...otherProps } = result;\n const response: PartialRequestResult = { ...deserializeErrors(otherProps), requestID };\n\n if (_cacheMetadata) {\n response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);\n }\n\n if (method === SUBSCRIBE) {\n this._debugManager?.log(SUBSCRIPTION_RESOLVED, {\n data: context.data,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(requestID, response);\n } else if (hasDeferOrStream) {\n const pending = this._pending.get(requestID);\n\n if (pending) {\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, requestID);\n pending.resolve(eventAsyncIterator.getIterator());\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n data: context.data,\n stats: { endTime: this._debugManager.now() },\n });\n\n this._eventEmitter.emit(requestID, response);\n } else {\n const pending = this._pending.get(requestID);\n\n if (!pending) {\n return;\n }\n\n this._debugManager?.log(REQUEST_RESOLVED, {\n data: context.data,\n stats: { endTime: this._debugManager.now() },\n });\n\n if (operation === OperationTypeNode.QUERY && pending.requestData && pending.options && pending.context) {\n void this._cacheManager.cacheQuery(\n pending.requestData,\n undefined,\n // Need to look at what type guards can be put in place\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n response as RawResponseDataWithMaybeCacheMetadata,\n pending.options,\n pending.context,\n );\n }\n\n pending.resolve(response);\n }\n };\n\n /**\n * This cache instance does not actually store anything itself,\n * it is for communicating with the worker cache that the worker\n * client is using within the worker.\n */\n private readonly _cache: CoreWorker;\n private readonly _cacheManager: CacheManagerDef;\n private readonly _debugManager: DebugManagerDef | undefined;\n private readonly _eventEmitter: EventEmitter;\n private readonly _experimentalDeferStreamSupport: boolean;\n private _messageQueue: MessageRequestPayload[] = [];\n private _pending: PendingTracker = new Map();\n private _requestParser: RequestParserDef;\n private _worker: Worker | undefined;\n\n constructor(options: UserOptions) {\n const errors: ArgsError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options to ba a plain object.'));\n }\n\n if (!('cache' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cache.'));\n }\n\n if (!('cacheManager' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.cacheManager.'));\n }\n\n if (!('requestParser' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.requestParser.'));\n }\n\n if (!options.lazyWorkerInit && !('worker' in options)) {\n errors.push(new ArgsError('@graphql-box/worker-client expected options.worker.'));\n }\n\n if (errors.length > 0) {\n throw new GroupedError('@graphql-box/worker-client argument validation errors.', errors);\n }\n\n this._cache = options.cache;\n this._cacheManager = options.cacheManager;\n this._debugManager = options.debugManager;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n this._requestParser = options.requestParser;\n\n if (typeof options.worker === 'function') {\n Promise.resolve(options.worker())\n .then(worker => {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n })\n .catch((error: unknown) => {\n throw error;\n });\n } else if (options.worker) {\n this._worker = options.worker;\n this._addEventListener();\n }\n }\n\n get cache(): CoreWorker {\n return this._cache;\n }\n\n get cacheManager(): CacheManagerDef {\n return this._cacheManager;\n }\n\n public async mutate(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(\n request,\n options,\n this._getRequestContext(OperationTypeNode.MUTATION, request, options, context),\n );\n }\n\n public async query(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._query(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, options, context));\n }\n\n public async request(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(OperationTypeNode.QUERY, request, options, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}, context: PartialRequestContext = {}) {\n return this._subscribe(\n request,\n options,\n this._getRequestContext(OperationTypeNode.SUBSCRIPTION, request, options, context),\n );\n }\n\n public set worker(worker: Worker) {\n this._worker = worker;\n this._addEventListener();\n this._releaseMessageQueue();\n }\n\n private _addEventListener(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: OperationTypeNode,\n request: string,\n options: RequestOptions,\n context: PartialRequestContext,\n ): RequestContext {\n return merge(\n {\n data: {\n batched: options.batch,\n operation,\n operationName: '',\n originalRequestHash: hashRequest(request),\n queryFiltered: false,\n requestComplexity: undefined,\n requestDepth: undefined,\n requestID: uuid(),\n tag: options.tag,\n variables: options.variables,\n },\n debugManager: this._debugManager,\n deprecated: {\n experimentalDeferStreamSupport: this._experimentalDeferStreamSupport,\n },\n fieldTypeMap: new Map(),\n filteredRequest: '',\n parsedRequest: '',\n request,\n },\n context,\n );\n }\n\n private async _query(\n request: string,\n options: RequestOptions,\n context: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n const { ast, request: updateRequest } = this._requestParser.updateRequest(request, options, context);\n const requestData = { ast, hash: hashRequest(updateRequest), request: updateRequest };\n const checkResult = await this._cacheManager.checkQueryResponseCacheEntry(requestData.hash, options, context);\n\n if (checkResult) {\n return WorkerClient._resolve(checkResult, options, context);\n }\n\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: {\n data: context.data,\n deprecated: context.deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: {\n data: context.data,\n deprecated: context.deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(context.data.requestID, { context, options, requestData, resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: context.data.requestID };\n }\n }\n\n private _releaseMessageQueue(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n const messageQueue = [...this._messageQueue];\n this._messageQueue = [];\n\n for (const message of messageQueue) {\n this._worker.postMessage(message);\n }\n }\n\n @logRequest()\n private async _request(\n request: string,\n options: RequestOptions,\n { data, deprecated }: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n return await new Promise((resolve: PendingResolver) => {\n if (this._worker) {\n this._worker.postMessage({\n context: {\n data,\n deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: {\n data,\n deprecated,\n },\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n this._pending.set(data.requestID, { resolve });\n });\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client request had an unexpected error.');\n\n return { errors: [confirmedError], requestID: data.requestID };\n }\n }\n\n @logSubscription()\n private _subscribe(\n request: string,\n options: RequestOptions,\n { data, deprecated }: RequestContext,\n ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {\n try {\n if (this._worker) {\n this._worker.postMessage({\n context: {\n data,\n deprecated,\n },\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n } else {\n this._messageQueue.push({\n context: {\n data,\n deprecated,\n },\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n }\n\n const eventAsyncIterator = new EventAsyncIterator<PartialRequestResult>(this._eventEmitter, data.requestID);\n\n return Promise.resolve(eventAsyncIterator.getIterator());\n } catch (error) {\n const confirmedError = isError(error)\n ? error\n : new Error('@graphql-box/worker-client subscribe had an unexpected error.');\n\n return Promise.resolve({ errors: [confirmedError], requestID: data.requestID });\n }\n }\n}\n","import {\n type PartialRequestResult,\n REQUEST_EXECUTED,\n REQUEST_RESOLVED,\n type RequestContext,\n type RequestOptions,\n} from '@graphql-box/core';\nimport { isAsyncIterable } from 'iterall';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logRequest = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { data, debugManager } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(REQUEST_EXECUTED, {\n data: {\n ...data,\n ...(!data.operationName && derivedOperationName ? { operationName: derivedOperationName } : undefined),\n },\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n const endTime = debugManager.now();\n const duration = endTime - startTime;\n resolve(result);\n\n if (isAsyncIterable(result)) {\n return;\n }\n\n debugManager.log(REQUEST_RESOLVED, {\n data: {\n ...data,\n ...(!data.operationName && derivedOperationName ? { operationName: derivedOperationName } : undefined),\n },\n stats: { duration, endTime, startTime },\n });\n })();\n });\n };\n };\n};\n","import {\n type PartialRequestResult,\n type RequestContext,\n type RequestOptions,\n SUBSCRIPTION_EXECUTED,\n} from '@graphql-box/core';\nimport { operationNameRegex } from '../helpers/operationNameRegex.ts';\nimport { type WorkerClient } from '../main.ts';\n\ntype Descriptor = (\n request: string,\n options: RequestOptions,\n context: RequestContext,\n) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;\n\nexport const logSubscription = () => {\n return (_target: WorkerClient, _propertyName: string, descriptor: TypedPropertyDescriptor<Descriptor>): void => {\n const method = descriptor.value;\n\n if (!method) {\n return;\n }\n\n descriptor.value = async function descriptorValue(...args: Parameters<Descriptor>): ReturnType<Descriptor> {\n return new Promise(resolve => {\n void (async () => {\n const { data, debugManager } = args[2];\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const derivedOperationName = operationNameRegex(args[0]);\n const startTime = debugManager.now();\n\n debugManager.log(SUBSCRIPTION_EXECUTED, {\n data: {\n ...data,\n ...(!data.operationName && derivedOperationName ? { operationName: derivedOperationName } : undefined),\n },\n stats: { startTime },\n });\n\n const result = await method.apply(this, args);\n resolve(result);\n })();\n });\n };\n };\n};\n","import { type PostMessage as CachemapMessageRequestPayload } from '@cachemap/core-worker';\nimport { GRAPHQL_BOX } from '../constants.ts';\nimport { type MessageRequestPayload } from '../types.ts';\n\nexport const isGraphqlBoxMessageRequestPayload = (\n payload: MessageRequestPayload | CachemapMessageRequestPayload,\n): payload is MessageRequestPayload => payload.type === GRAPHQL_BOX;\n","import {\n type PostMessage as CachemapMessageRequestPayload,\n handleMessage as handleCachemapMessage,\n} from '@cachemap/core-worker';\nimport { type Client } from '@graphql-box/client';\nimport { type PartialDehydratedRequestResult, type PartialRequestResult, type RequestOptions } from '@graphql-box/core';\nimport { dehydrateCacheMetadata, serializeErrors } from '@graphql-box/helpers';\nimport { forAwaitEach, isAsyncIterable } from 'iterall';\nimport { GRAPHQL_BOX, MESSAGE, REQUEST } from './constants.ts';\nimport { isGraphqlBoxMessageRequestPayload } from './helpers/isGraphqlBoxMessageRequestPayload.ts';\nimport {\n type MessageContext,\n type MessageRequestPayload,\n type MethodNames,\n type RegisterWorkerOptions,\n} from './types.ts';\n\nconst handleRequest = async (\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 // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const { _cacheMetadata, ...otherProps } = requestResult as PartialRequestResult;\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n return;\n }\n\n void forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nconst handleSubscription = async (\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 globalThis.postMessage({\n context,\n method,\n // Need to replace this casting with a type guard\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n result: serializeErrors(subscribeResult as PartialRequestResult),\n type: GRAPHQL_BOX,\n });\n\n return;\n }\n\n void forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: PartialRequestResult) => {\n const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });\n });\n};\n\nexport const handleMessage = (data: MessageRequestPayload, client: Client): void => {\n const { context, method, options, request } = data;\n\n if (method === REQUEST) {\n void handleRequest(request, method, options, context, client);\n } else {\n void handleSubscription(request, method, options, context, client);\n }\n};\n\nexport const registerWorker = ({ client }: RegisterWorkerOptions): void => {\n const onMessage = ({ data }: MessageEvent<MessageRequestPayload | CachemapMessageRequestPayload>): void => {\n if (isGraphqlBoxMessageRequestPayload(data)) {\n handleMessage(data, client);\n } else if (client.cache) {\n void handleCachemapMessage(data, client.cache);\n }\n };\n\n globalThis.addEventListener(MESSAGE, onMessage);\n};\n"],"names":["CACHEMAP","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","operationNameRegex","request","output","exec","WorkerClient","_resolve","cacheMetadata","rest","options","data","result","requestID","returnCacheMetadata","_cacheMetadata","constructor","_onMessage","isPlainObject","context","method","type","operation","hasDeferOrStream","deprecated","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","OperationTypeNode","QUERY","requestData","_cacheManager","cacheQuery","undefined","_messageQueue","Map","errors","push","ArgsError","lazyWorkerInit","length","GroupedError","_cache","cache","cacheManager","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_requestParser","requestParser","worker","Promise","then","_worker","_addEventListener","_releaseMessageQueue","catch","error","mutate","_request","_getRequestContext","MUTATION","query","_query","subscribe","_subscribe","SUBSCRIPTION","Error","addEventListener","merge","batched","batch","operationName","originalRequestHash","hashRequest","queryFiltered","requestComplexity","requestDepth","uuid","tag","variables","fieldTypeMap","filteredRequest","parsedRequest","ast","updateRequest","hash","checkResult","checkQueryResponseCacheEntry","postMessage","set","isError","messageQueue","message","confirmedError","_target","_propertyName","descriptor","value","async","args","apply","derivedOperationName","startTime","REQUEST_EXECUTED","duration","isAsyncIterable","SUBSCRIPTION_EXECUTED","handleMessage","client","requestResult","serializeErrors","dehydrateCacheMetadata","globalThis","forAwaitEach","handleRequest","subscribeResult","handleSubscription","registerWorker","handleCachemapMessage","onMessage"],"mappings":"iqBAAO,MAAMA,EAAW,WACXC,EAAc,aACdC,EAAU,UACVC,EAAU,UACVC,EAAY,YCJZC,EAAsBC,IACjC,MAAMC,EAAS,mDAAmDC,KAAKF,GACvE,OAAOC,EAASA,EAAO,GAAK,EAAA,qbCoCvB,MAAME,EACX,eAAeC,EACbC,cAAEA,KAAkBC,GACpBC,GACAC,KAAEA,IAEF,MAAMC,EAA+B,IAAKH,EAAMI,UAAWF,EAAKE,WAMhE,OAJIH,EAAQI,qBAAuBN,IACjCI,EAAOG,eAAiBP,GAGnBI,CACT,CAsFAI,WAAAA,CAAYN,QApFJO,WAAa,EAAGN,WACtB,IAAKO,EAAcP,GACjB,OAGF,MAAMQ,QAAEA,EAAOC,OAAEA,EAAMR,OAAEA,EAAMS,KAAEA,GAASV,EAE1C,GAAIU,IAASvB,EACX,OAGF,MAAMwB,UAAEA,EAAST,UAAEA,GAAcM,EAAQR,MACnCY,iBAAEA,GAAqBJ,EAAQK,YAC/BT,eAAEA,KAAmBU,GAAeb,EACpCc,EAAiC,IAAKC,EAAkBF,GAAaZ,aAM3E,GAJIE,IACFW,EAASX,eAAiBa,EAAuBb,IAG/CK,IAAWnB,EACb4B,KAAKC,eAAeC,IAAIC,EAAuB,CAC7CrB,KAAMQ,EAAQR,KACdsB,MAAO,CAAEC,QAASL,KAAKC,cAAcK,SAGvCN,KAAKO,cAAcC,KAAKxB,EAAWa,QAC9B,GAAIH,EAAkB,CAC3B,MAAMe,EAAUT,KAAKU,SAASC,IAAI3B,GAElC,GAAIyB,EAAS,CACX,MAAMG,EAAqB,IAAIC,EAAyCb,KAAKO,cAAevB,GAC5FyB,EAAQK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E,MAC1C,GAGmC8E"}
@@ -1,50 +1,50 @@
1
1
  -----------------------------
2
2
  Rollup File Analysis
3
3
  -----------------------------
4
- bundle size: 19.706 KB
5
- original size: 20.261 KB
6
- code reduction: 2.74 %
4
+ bundle size: 19.868 KB
5
+ original size: 20.724 KB
6
+ code reduction: 4.13 %
7
7
  module count: 8
8
8
 
9
9
  █████████████████████████████████░░░░░░░░░░░░░░░░░
10
10
  file: /src/main.ts
11
- bundle space: 66.51 %
12
- rendered size: 13.107 KB
13
- original size: 12.234 KB
11
+ bundle space: 67.21 %
12
+ rendered size: 13.353 KB
13
+ original size: 12.628 KB
14
14
  code reduction: 0 %
15
15
  dependents: 1
16
16
  - /src/index.ts
17
17
 
18
- ███████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
18
+ ██████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
19
19
  file: /src/registerWorker.ts
20
- bundle space: 14.5 %
21
- rendered size: 2.857 KB
20
+ bundle space: 13.89 %
21
+ rendered size: 2.76 KB
22
22
  original size: 3.638 KB
23
- code reduction: 21.47 %
23
+ code reduction: 24.13 %
24
24
  dependents: 1
25
25
  - /src/index.ts
26
26
 
27
27
  █████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
28
28
  file: /src/debug/logRequest.ts
29
- bundle space: 10.43 %
30
- rendered size: 2.056 KB
31
- original size: 2.006 KB
29
+ bundle space: 10.34 %
30
+ rendered size: 2.055 KB
31
+ original size: 2.049 KB
32
32
  code reduction: 0 %
33
33
  dependents: 1
34
34
  - /src/main.ts
35
35
 
36
36
  ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
37
37
  file: /src/debug/logSubscription.ts
38
- bundle space: 6.57 %
39
- rendered size: 1.294 KB
40
- original size: 1.516 KB
41
- code reduction: 14.64 %
38
+ bundle space: 6.58 %
39
+ rendered size: 1.308 KB
40
+ original size: 1.542 KB
41
+ code reduction: 15.18 %
42
42
  dependents: 1
43
43
  - /src/main.ts
44
44
 
45
45
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
46
46
  file: /src/helpers/operationNameRegex.ts
47
- bundle space: 0.83 %
47
+ bundle space: 0.82 %
48
48
  rendered size: 163 Bytes
49
49
  original size: 177 Bytes
50
50
  code reduction: 7.91 %
@@ -54,7 +54,7 @@ dependents: 2
54
54
 
55
55
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
56
56
  file: /src/constants.ts
57
- bundle space: 0.75 %
57
+ bundle space: 0.74 %
58
58
  rendered size: 147 Bytes
59
59
  original size: 183 Bytes
60
60
  code reduction: 19.67 %
@@ -66,7 +66,7 @@ dependents: 4
66
66
 
67
67
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
68
68
  file: /src/helpers/isGraphqlBoxMessageRequestPayload.ts
69
- bundle space: 0.42 %
69
+ bundle space: 0.41 %
70
70
  rendered size: 82 Bytes
71
71
  original size: 383 Bytes
72
72
  code reduction: 78.59 %
@@ -1 +1 @@
1
- {"version":3,"file":"logRequest.d.cts","sourceRoot":"","sources":["../../../../src/debug/logRequest.cts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAGzB,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,KAAK,UAAU,GAAG,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,oBAAoB,GAAG,qBAAqB,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC,CAAC;AAE7F,eAAO,MAAM,UAAU,kBACJ,YAAY,iBAAiB,MAAM,cAAc,uBAAuB,CAAC,UAAU,CAAC,KAAG,IA+CzG,CAAC"}
1
+ {"version":3,"file":"logRequest.d.cts","sourceRoot":"","sources":["../../../../src/debug/logRequest.cts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAGzB,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,KAAK,UAAU,GAAG,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,oBAAoB,GAAG,qBAAqB,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC,CAAC;AAE7F,eAAO,MAAM,UAAU,kBACJ,YAAY,iBAAiB,MAAM,cAAc,uBAAuB,CAAC,UAAU,CAAC,KAAG,IAgDzG,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logSubscription.d.cts","sourceRoot":"","sources":["../../../../src/debug/logSubscription.cts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,KAAK,UAAU,GAAG,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,oBAAoB,GAAG,qBAAqB,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC,CAAC;AAE7F,eAAO,MAAM,eAAe,kBACT,YAAY,iBAAiB,MAAM,cAAc,uBAAuB,CAAC,UAAU,CAAC,KAAG,IAiCzG,CAAC"}
1
+ {"version":3,"file":"logSubscription.d.cts","sourceRoot":"","sources":["../../../../src/debug/logSubscription.cts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,KAAK,UAAU,GAAG,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,oBAAoB,GAAG,qBAAqB,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC,CAAC;AAE7F,eAAO,MAAM,eAAe,kBACT,YAAY,iBAAiB,MAAM,cAAc,uBAAuB,CAAC,UAAU,CAAC,KAAG,IAkCzG,CAAC"}
@@ -3,7 +3,6 @@ import { type CacheManagerDef } from '@graphql-box/cache-manager';
3
3
  import { type PartialRequestContext, type PartialRequestResult, type RequestOptions } from '@graphql-box/core';
4
4
  import { type UserOptions } from './types.cts';
5
5
  export declare class WorkerClient {
6
- private static _getMessageContext;
7
6
  private static _resolve;
8
7
  private _onMessage;
9
8
  /**
@@ -11,11 +10,11 @@ export declare class WorkerClient {
11
10
  * it is for communicating with the worker cache that the worker
12
11
  * client is using within the worker.
13
12
  */
14
- private _cache;
15
- private _cacheManager;
16
- private _debugManager;
17
- private _eventEmitter;
18
- private _experimentalDeferStreamSupport;
13
+ private readonly _cache;
14
+ private readonly _cacheManager;
15
+ private readonly _debugManager;
16
+ private readonly _eventEmitter;
17
+ private readonly _experimentalDeferStreamSupport;
19
18
  private _messageQueue;
20
19
  private _pending;
21
20
  private _requestParser;
@@ -26,7 +25,7 @@ export declare class WorkerClient {
26
25
  mutate(request: string, options?: RequestOptions, context?: PartialRequestContext): Promise<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | AsyncIterableIterator<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | undefined>>;
27
26
  query(request: string, options?: RequestOptions, context?: PartialRequestContext): Promise<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | AsyncIterableIterator<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | undefined>>;
28
27
  request(request: string, options?: RequestOptions, context?: PartialRequestContext): Promise<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | AsyncIterableIterator<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | undefined>>;
29
- subscribe(request: string, options?: RequestOptions): Promise<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | AsyncIterableIterator<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | undefined>>;
28
+ subscribe(request: string, options?: RequestOptions, context?: PartialRequestContext): Promise<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | AsyncIterableIterator<PartialRequestResult<import("@graphql-box/core").PlainData<unknown> | null> | undefined>>;
30
29
  set worker(worker: Worker);
31
30
  private _addEventListener;
32
31
  private _getRequestContext;
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.cts","sourceRoot":"","sources":["../../../src/main.cts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAKzB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAkB3B,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,kBAAkB;IASjC,OAAO,CAAC,MAAM,CAAC,QAAQ;IAcvB,OAAO,CAAC,UAAU,CAoEhB;IAEF;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,+BAA+B,CAAU;IACjD,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,cAAc,CAAmB;IAC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