@graphql-box/worker-client 5.4.0 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "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"),n=require("uuid"),o=require("iterall"),i=require("@cachemap/core-worker");const u="graphqlBox",c="message",p="request",h="subscribe",l=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function d(e,t,r,s){var a,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(o=(n<3?a(o):n>3?a(t,r,o):a(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}function g(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class q{static _getMessageContext({hasDeferOrStream:e=!1,requestID:t}){return{hasDeferOrStream:e,requestID:t}}constructor(s){this._onMessage=({data:r})=>{if(!t.isPlainObject(r))return;const{context:s,method:a,result:n,type:o}=r;if(o!==u)return;const{_cacheMetadata:i,...c}=n,p={...t.deserializeErrors(c),requestID:s.requestID};if(i&&(p._cacheMetadata=t.rehydrateCacheMetadata(i)),a===h)this._debugManager?.log(e.SUBSCRIPTION_RESOLVED,{context:s,result:p,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(s.requestID,p);else if(s.hasDeferOrStream){const r=this._pending.get(s.requestID);if(r){const e=new t.EventAsyncIterator(this._eventEmitter,s.requestID);r.resolve(e.getIterator())}this._debugManager?.log(e.REQUEST_RESOLVED,{context:s,result:p,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(s.requestID,p)}else{const t=this._pending.get(s.requestID);if(!t)return;this._debugManager?.log(e.REQUEST_RESOLVED,{context:s,result:p,stats:{endTime:this._debugManager.now()}}),t.resolve(p)}},this._pending=new Map;const a=[];if(t.isPlainObject(s)||a.push(new t.ArgsError("@graphql-box/worker-client expected options to ba a plain object.")),"cache"in s||a.push(new t.ArgsError("@graphql-box/worker-client expected options.cache.")),"worker"in s||a.push(new t.ArgsError("@graphql-box/worker-client expected options.worker.")),a.length>0)throw new t.GroupedError("@graphql-box/worker-client argument validation errors.",a);this._cache=s.cache,this._debugManager=s.debugManager??null,this._eventEmitter=new r.EventEmitter,this._experimentalDeferStreamSupport=s.experimentalDeferStreamSupport??!1,this._worker=s.worker,this._addEventListener()}get cache(){return this._cache}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(s.OperationTypeNode.MUTATION,e,r))}async query(e,t={},r={}){return this._request(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))}_addEventListener(){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:n.v4(),...s}}async _request(e,t,r){try{return await new Promise((s=>{this._worker.postMessage({context:q._getMessageContext(r),method:p,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.postMessage({context:q._getMessageContext(s),method:h,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})}}}d([(t,r,s)=>{const a=s.value;a&&(s.value=async function(...t){return new Promise((r=>{(async()=>{const{debugManager:s,...n}=t[2];if(!s)return void r(await a.apply(this,t));const i=l(t[0]),u=s.now();s.log(e.REQUEST_EXECUTED,{context:{...n,operationName:i},options:t[1],request:t[0],stats:{startTime:u}});const c=await a.apply(this,t),p=s.now(),h=p-u;r(c),o.isAsyncIterable(c)||s.log(e.REQUEST_RESOLVED,{context:{...n,operationName:i},options:t[1],request:t[0],result:c,stats:{duration:h,endTime:p,startTime:u}})})()}))})},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),d([(t,r,s)=>{const a=s.value;a&&(s.value=async function(...t){return new Promise((r=>{(async()=>{const{debugManager:s,...n}=t[2];if(!s)return void r(await a.apply(this,t));const o=l(t[0]),i=s.now();s.log(e.SUBSCRIPTION_EXECUTED,{context:{...n,operationName:o},options:t[1],request:t[0],stats:{startTime:i}});const u=await a.apply(this,t);r(u)})()}))})},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 y=(e,r)=>{const{context:s,method:a,options:n,request:i}=e;a===p?(async(e,r,s,a,n)=>{const i=await n.request(e,s,a);if(!o.isAsyncIterable(i)){const{_cacheMetadata:e,...s}=i,n=t.serializeErrors({...s});return e&&(n._cacheMetadata=t.dehydrateCacheMetadata(e)),void globalThis.postMessage({context:a,method:r,result:n,type:u})}o.forAwaitEach(i,(({_cacheMetadata:e,...s})=>{const n=t.serializeErrors({...s});e&&(n._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:a,method:r,result:n,type:u})}))})(i,a,n,s,r):(async(e,r,s,a,n)=>{const i=await n.subscribe(e,s,a);o.isAsyncIterable(i)?o.forAwaitEach(i,(({_cacheMetadata:e,...s})=>{const n=t.serializeErrors({...s});e&&(n._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:a,method:r,result:n,type:u})})):globalThis.postMessage({context:a,method:r,result:t.serializeErrors(i),type:u})})(i,a,n,s,r)};exports.CACHEMAP="cachemap",exports.GRAPHQL_BOX=u,exports.MESSAGE=c,exports.REQUEST=p,exports.SUBSCRIBE=h,exports.WorkerClient=q,exports.handleMessage=y,exports.registerWorker=({client:e})=>{globalThis.addEventListener(c,(({data:t})=>{t.type===u?y(t,e):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"),s=require("graphql"),o=require("lodash-es"),a=require("uuid"),n=require("iterall"),i=require("@cachemap/core-worker");const u="graphqlBox",c="message",h="request",p="subscribe",l=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function d(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 g(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class q{static _getMessageContext({hasDeferOrStream:e=!1,requestID:t}){return{hasDeferOrStream:e,requestID:t}}constructor(s){this._onMessage=({data:r})=>{if(!t.isPlainObject(r))return;const{context:s,method:o,result:a,type:n}=r;if(n!==u)return;const{_cacheMetadata:i,...c}=a,h={...t.deserializeErrors(c),requestID:s.requestID};if(i&&(h._cacheMetadata=t.rehydrateCacheMetadata(i)),o===p)this._debugManager?.log(e.SUBSCRIPTION_RESOLVED,{context:s,result:h,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(s.requestID,h);else if(s.hasDeferOrStream){const r=this._pending.get(s.requestID);if(r){const e=new t.EventAsyncIterator(this._eventEmitter,s.requestID);r.resolve(e.getIterator())}this._debugManager?.log(e.REQUEST_RESOLVED,{context:s,result:h,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(s.requestID,h)}else{const t=this._pending.get(s.requestID);if(!t)return;this._debugManager?.log(e.REQUEST_RESOLVED,{context:s,result:h,stats:{endTime:this._debugManager.now()}}),t.resolve(h)}},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.")),"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._debugManager=s.debugManager??null,this._eventEmitter=new r.EventEmitter,this._experimentalDeferStreamSupport=s.experimentalDeferStreamSupport??!1,"function"==typeof s.worker?s.worker().then((e=>{this._worker=e,this._addEventListener(),this._releaseMessageQueue()})).catch((e=>{throw e})):(this._worker=s.worker,this._addEventListener())}get cache(){return this._cache}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(s.OperationTypeNode.MUTATION,e,r))}async query(e,t={},r={}){return this._request(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))}_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:a.v4(),...s}}_releaseMessageQueue(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");for(const e of this._messageQueue)this._worker.postMessage(e)}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:[o.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 o=new t.EventAsyncIterator(this._eventEmitter,s.requestID);return Promise.resolve(o.getIterator())}catch(e){const t=o.isError(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:s.requestID})}}}d([(t,r,s)=>{const o=s.value;o&&(s.value=async function(...t){return new Promise((r=>{(async()=>{const{debugManager:s,...a}=t[2];if(!s)return void r(await o.apply(this,t));const i=l(t[0]),u=s.now();s.log(e.REQUEST_EXECUTED,{context:{...a,operationName:i},options:t[1],request:t[0],stats:{startTime:u}});const c=await o.apply(this,t),h=s.now(),p=h-u;r(c),n.isAsyncIterable(c)||s.log(e.REQUEST_RESOLVED,{context:{...a,operationName:i},options:t[1],request:t[0],result:c,stats:{duration:p,endTime:h,startTime:u}})})()}))})},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),d([(t,r,s)=>{const o=s.value;o&&(s.value=async function(...t){return new Promise((r=>{(async()=>{const{debugManager:s,...a}=t[2];if(!s)return void r(await o.apply(this,t));const n=l(t[0]),i=s.now();s.log(e.SUBSCRIPTION_EXECUTED,{context:{...a,operationName:n},options:t[1],request:t[0],stats:{startTime:i}});const u=await o.apply(this,t);r(u)})()}))})},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:s,method:o,options:a,request:i}=e;o===h?(async(e,r,s,o,a)=>{const i=await a.request(e,s,o);if(!n.isAsyncIterable(i)){const{_cacheMetadata:e,...s}=i,a=t.serializeErrors({...s});return e&&(a._cacheMetadata=t.dehydrateCacheMetadata(e)),void globalThis.postMessage({context:o,method:r,result:a,type:u})}n.forAwaitEach(i,(({_cacheMetadata:e,...s})=>{const a=t.serializeErrors({...s});e&&(a._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:o,method:r,result:a,type:u})}))})(i,o,a,s,r):(async(e,r,s,o,a)=>{const i=await a.subscribe(e,s,o);n.isAsyncIterable(i)?n.forAwaitEach(i,(({_cacheMetadata:e,...s})=>{const a=t.serializeErrors({...s});e&&(a._cacheMetadata=t.dehydrateCacheMetadata(e)),globalThis.postMessage({context:o,method:r,result:a,type:u})})):globalThis.postMessage({context:o,method:r,result:t.serializeErrors(i),type:u})})(i,o,a,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)}))};
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 {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n REQUEST_RESOLVED,\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 { 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 MessageResponsePayload,\n type PendingResolver,\n type PendingTracker,\n type UserOptions,\n} from './types.ts';\n\nexport class WorkerClient {\n private static _getMessageContext({ hasDeferOrStream = false, requestID }: RequestContext): MessageContext {\n return { hasDeferOrStream, requestID };\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 pending.resolve(response);\n }\n };\n\n private _cache: CoreWorker;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _experimentalDeferStreamSupport: boolean;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\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 (!('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._debugManager = options.debugManager ?? null;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): CoreWorker {\n return this._cache;\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._request(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 private _addEventListener(): void {\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 @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 this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.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 this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<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 {\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","requestID","constructor","options","_onMessage","data","isPlainObject","context","method","result","type","_cacheMetadata","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","Map","errors","push","ArgsError","length","GroupedError","_cache","cache","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_worker","worker","_addEventListener","mutate","_request","_getRequestContext","OperationTypeNode","MUTATION","query","QUERY","subscribe","_subscribe","SUBSCRIPTION","addEventListener","operation","fieldTypeMap","filteredRequest","operationName","originalRequestHash","hashRequest","parsedRequest","queryFiltered","requestComplexity","requestDepth","uuid","Promise","postMessage","set","error","isError","Error","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,qbCgCvB,MAAME,EACX,yBAAeC,EAAmBC,iBAAEA,GAAmB,EAAKC,UAAEA,IAC5D,MAAO,CAAED,mBAAkBC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,CAGnC,MAAMlF,eAAEA,KAAmBC,GAAeiF,EACpCpF,EAAyCqF,EAAAA,gBAAgB,IAAKlF,IAOpE,OALID,IACFF,EAAOE,eAAiBoF,EAAuBpF,uBAAAA,SAGjDqF,WAAWzB,YAAY,CAAEhE,UAASC,SAAQC,SAAQC,KAAMpB,GAE1D,CAEK2G,EAAAA,aAAaJ,GAAe,EAAGlF,oBAAmBC,MACrD,MAAMH,EAAyCqF,EAAAA,gBAAgB,IAAKlF,IAEhED,IACFF,EAAOE,eAAiBoF,EAAuBpF,uBAAAA,IAGjDqF,WAAWzB,YAAY,CAAEhE,UAASC,SAAQC,SAAQC,KAAMpB,GAAY,GACtE,EAwCO4G,CAAcvG,EAASa,EAAQL,EAASI,EAASqF,GArC/BX,OACzBtF,EACAa,EACAL,EACAI,EACAqF,KAEA,MAAMO,QAAwBP,EAAOrC,UAAU5D,EAASQ,EAASI,GAE5DkF,EAAAA,gBAAgBU,GAahBF,EAAAA,aAAaE,GAAiB,EAAGxF,oBAAmBC,MACvD,MAAMH,EAAyCqF,EAAAA,gBAAgB,IAAKlF,IAEhED,IACFF,EAAOE,eAAiBoF,EAAuBpF,uBAAAA,IAGjDqF,WAAWzB,YAAY,CAAEhE,UAASC,SAAQC,SAAQC,KAAMpB,GAAY,IAnBpE0G,WAAWzB,YAAY,CACrBhE,UACAC,SAGAC,OAAQqF,EAAgBK,gBAAAA,GACxBzF,KAAMpB,GAcV,EASO8G,CAAmBzG,EAASa,EAAQL,EAASI,EAASqF,EAC7D,mBN3FsB,+JM8FM,EAAGA,aAS/BI,WAAWtC,iBAAiBnE,GARV,EAAGc,WACmBA,ED1FKK,OAASpB,EC2FlDqG,EAActF,EAAMuF,GAEfS,gBAAsBhG,EAAMuF,EAAOpD,MAC1C,GAGmC8D"}
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 {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n REQUEST_RESOLVED,\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 { 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({ hasDeferOrStream = false, requestID }: RequestContext): MessageContext {\n return { hasDeferOrStream, requestID };\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 pending.resolve(response);\n }\n };\n\n private _cache: CoreWorker;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _experimentalDeferStreamSupport: boolean;\n private _messageQueue: MessageRequestPayload[] = [];\n private _pending: PendingTracker = new Map();\n\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 (!('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._debugManager = options.debugManager ?? null;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n\n if (typeof options.worker === 'function') {\n options\n .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 {\n this._worker = options.worker;\n this._addEventListener();\n }\n }\n\n get cache(): CoreWorker {\n return this._cache;\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._request(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 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 _releaseMessageQueue(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n for (const message of this._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","requestID","constructor","options","_onMessage","data","isPlainObject","context","method","result","type","_cacheMetadata","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","_messageQueue","Map","errors","push","ArgsError","length","GroupedError","_cache","cache","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","worker","then","_worker","_addEventListener","_releaseMessageQueue","catch","error","mutate","_request","_getRequestContext","OperationTypeNode","MUTATION","query","QUERY","subscribe","_subscribe","SUBSCRIPTION","Error","addEventListener","operation","fieldTypeMap","filteredRequest","operationName","originalRequestHash","hashRequest","parsedRequest","queryFiltered","requestComplexity","requestDepth","uuid","message","postMessage","Promise","set","isError","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,qbCiCvB,MAAME,EACX,yBAAeC,EAAmBC,iBAAEA,GAAmB,EAAKC,UAAEA,IAC5D,MAAO,CAAED,mBAAkBC,YAC7B,CAqEAC,WAAAA,CAAYC,QAnEJC,WAAa,EAAGC,WACtB,IAAKC,EAAAA,cAAcD,GACjB,OAGF,MAAME,QAAEA,EAAOC,OAAEA,EAAMC,OAAEA,EAAMC,KAAEA,GAASL,EAE1C,GAAIK,IAASpB,EACX,OAGF,MAAMqB,eAAEA,KAAmBC,GAAeH,EACpCI,EAAiC,IAAKC,EAAAA,kBAAkBF,GAAaX,UAAWM,EAAQN,WAM9F,GAJIU,IACFE,EAASF,eAAiBI,EAAuBJ,uBAAAA,IAG/CH,IAAWf,EACbuB,KAAKC,eAAeC,IAAIC,wBAAuB,CAC7CZ,UACAE,OAAQI,EACRO,MAAO,CAAEC,QAASL,KAAKC,cAAcK,SAGvCN,KAAKO,cAAcC,KAAKjB,EAAQN,UAAWY,QACtC,GAAIN,EAAQP,iBAAkB,CACnC,MAAMyB,EAAUT,KAAKU,SAASC,IAAIpB,EAAQN,WAE1C,GAAIwB,EAAS,CACX,MAAMG,EAAqB,IAAIC,EAAyCA,mBAAAb,KAAKO,cAAehB,EAA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@graphql-box/core";import{isPlainObject as n,deserializeErrors as o,rehydrateCacheMetadata as a,EventAsyncIterator as i,ArgsError as u,GroupedError as c,hashRequest as p,serializeErrors as h,dehydrateCacheMetadata as l}from"@graphql-box/helpers";import{EventEmitter as g}from"eventemitter3";import{OperationTypeNode as d}from"graphql";import{isError as m}from"lodash-es";import{v4 as q}from"uuid";import{isAsyncIterable as f,forAwaitEach as _}from"iterall";import{handleMessage as b}from"@cachemap/core-worker";const y="cachemap",x="graphqlBox",w="message",M="request",v="subscribe",D=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function R(e,t,r,s){var n,o=arguments.length,a=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(n=e[i])&&(a=(o<3?n(a):o>3?n(t,r,a):n(t,r))||a);return o>3&&a&&Object.defineProperty(t,r,a),a}function I(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class O{static _getMessageContext({hasDeferOrStream:e=!1,requestID:t}){return{hasDeferOrStream:e,requestID:t}}constructor(e){this._onMessage=({data:e})=>{if(!n(e))return;const{context:r,method:u,result:c,type:p}=e;if(p!==x)return;const{_cacheMetadata:h,...l}=c,g={...o(l),requestID:r.requestID};if(h&&(g._cacheMetadata=a(h)),u===v)this._debugManager?.log(s,{context:r,result:g,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(r.requestID,g);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:g,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(r.requestID,g)}else{const e=this._pending.get(r.requestID);if(!e)return;this._debugManager?.log(t,{context:r,result:g,stats:{endTime:this._debugManager.now()}}),e.resolve(g)}},this._pending=new Map;const r=[];if(n(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.")),"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._debugManager=e.debugManager??null,this._eventEmitter=new g,this._experimentalDeferStreamSupport=e.experimentalDeferStreamSupport??!1,this._worker=e.worker,this._addEventListener()}get cache(){return this._cache}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(d.MUTATION,e,r))}async query(e,t={},r={}){return this._request(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))}_addEventListener(){this._worker.addEventListener(w,this._onMessage)}_getRequestContext(e,t,r={}){return{debugManager:this._debugManager,experimentalDeferStreamSupport:this._experimentalDeferStreamSupport,fieldTypeMap:new Map,filteredRequest:"",operation:e,operationName:"",originalRequestHash:p(t),parsedRequest:"",queryFiltered:!1,request:t,requestComplexity:null,requestDepth:null,requestID:q(),...r}}async _request(e,t,r){try{return await new Promise((s=>{this._worker.postMessage({context:O._getMessageContext(r),method:M,options:t,request:e,type:x}),this._pending.set(r.requestID,{resolve:s})}))}catch(e){return{errors:[m(e)?e:new Error("@graphql-box/worker-client request had an unexpected error.")],requestID:r.requestID}}}_subscribe(e,t,r){try{this._worker.postMessage({context:O._getMessageContext(r),method:v,options:t,request:e,type:x});const s=new i(this._eventEmitter,r.requestID);return Promise.resolve(s.getIterator())}catch(e){const t=m(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:r.requestID})}}}R([(r,s,n)=>{const o=n.value;o&&(n.value=async function(...r){return new Promise((s=>{(async()=>{const{debugManager:n,...a}=r[2];if(!n)return void s(await o.apply(this,r));const i=D(r[0]),u=n.now();n.log(e,{context:{...a,operationName:i},options:r[1],request:r[0],stats:{startTime:u}});const c=await o.apply(this,r),p=n.now(),h=p-u;s(c),f(c)||n.log(t,{context:{...a,operationName:i},options:r[1],request:r[0],result:c,stats:{duration:h,endTime:p,startTime:u}})})()}))})},I("design:type",Function),I("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),I("design:returntype",Promise)],O.prototype,"_request",null),R([(e,t,s)=>{const n=s.value;n&&(s.value=async function(...e){return new Promise((t=>{(async()=>{const{debugManager:s,...o}=e[2];if(!s)return void t(await n.apply(this,e));const a=D(e[0]),i=s.now();s.log(r,{context:{...o,operationName:a},options:e[1],request:e[0],stats:{startTime:i}});const u=await n.apply(this,e);t(u)})()}))})},I("design:type",Function),I("design:paramtypes",[String,"undefined"==typeof RequestOptions?Object:RequestOptions,"undefined"==typeof RequestContext?Object:RequestContext]),I("design:returntype","undefined"==typeof Promise?Object:Promise)],O.prototype,"_subscribe",null);const T=(e,t)=>{const{context:r,method:s,options:n,request:o}=e;s===M?(async(e,t,r,s,n)=>{const o=await n.request(e,r,s);if(!f(o)){const{_cacheMetadata:e,...r}=o,n=h({...r});return e&&(n._cacheMetadata=l(e)),void globalThis.postMessage({context:s,method:t,result:n,type:x})}_(o,(({_cacheMetadata:e,...r})=>{const n=h({...r});e&&(n._cacheMetadata=l(e)),globalThis.postMessage({context:s,method:t,result:n,type:x})}))})(o,s,n,r,t):(async(e,t,r,s,n)=>{const o=await n.subscribe(e,r,s);f(o)?_(o,(({_cacheMetadata:e,...r})=>{const n=h({...r});e&&(n._cacheMetadata=l(e)),globalThis.postMessage({context:s,method:t,result:n,type:x})})):globalThis.postMessage({context:s,method:t,result:h(o),type:x})})(o,s,n,r,t)},S=({client:e})=>{globalThis.addEventListener(w,(({data:t})=>{t.type===x?T(t,e):b(t,e.cache)}))};export{y as CACHEMAP,x as GRAPHQL_BOX,w as MESSAGE,M as REQUEST,v as SUBSCRIBE,O as WorkerClient,T as handleMessage,S 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 s}from"@graphql-box/core";import{isPlainObject as o,deserializeErrors as n,rehydrateCacheMetadata as a,EventAsyncIterator as i,ArgsError as u,GroupedError as c,hashRequest as p,serializeErrors as h,dehydrateCacheMetadata as l}from"@graphql-box/helpers";import{EventEmitter as g}from"eventemitter3";import{OperationTypeNode as d}from"graphql";import{isError as m}from"lodash-es";import{v4 as _}from"uuid";import{isAsyncIterable as q,forAwaitEach as f}from"iterall";import{handleMessage as w}from"@cachemap/core-worker";const y="cachemap",b="graphqlBox",x="message",M="request",k="subscribe",v=e=>{const t=/(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(e);return t?t[2]:""};function D(e,t,r,s){var o,n=arguments.length,a=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(a=(n<3?o(a):n>3?o(t,r,a):o(t,r))||a);return n>3&&a&&Object.defineProperty(t,r,a),a}function R(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class I{static _getMessageContext({hasDeferOrStream:e=!1,requestID:t}){return{hasDeferOrStream:e,requestID:t}}constructor(e){this._onMessage=({data:e})=>{if(!o(e))return;const{context:r,method:u,result:c,type:p}=e;if(p!==b)return;const{_cacheMetadata:h,...l}=c,g={...n(l),requestID:r.requestID};if(h&&(g._cacheMetadata=a(h)),u===k)this._debugManager?.log(s,{context:r,result:g,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(r.requestID,g);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:g,stats:{endTime:this._debugManager.now()}}),this._eventEmitter.emit(r.requestID,g)}else{const e=this._pending.get(r.requestID);if(!e)return;this._debugManager?.log(t,{context:r,result:g,stats:{endTime:this._debugManager.now()}}),e.resolve(g)}},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.")),"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._debugManager=e.debugManager??null,this._eventEmitter=new g,this._experimentalDeferStreamSupport=e.experimentalDeferStreamSupport??!1,"function"==typeof e.worker?e.worker().then((e=>{this._worker=e,this._addEventListener(),this._releaseMessageQueue()})).catch((e=>{throw e})):(this._worker=e.worker,this._addEventListener())}get cache(){return this._cache}async mutate(e,t={},r={}){return this._request(e,t,this._getRequestContext(d.MUTATION,e,r))}async query(e,t={},r={}){return this._request(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))}_addEventListener(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");this._worker.addEventListener(x,this._onMessage)}_getRequestContext(e,t,r={}){return{debugManager:this._debugManager,experimentalDeferStreamSupport:this._experimentalDeferStreamSupport,fieldTypeMap:new Map,filteredRequest:"",operation:e,operationName:"",originalRequestHash:p(t),parsedRequest:"",queryFiltered:!1,request:t,requestComplexity:null,requestDepth:null,requestID:_(),...r}}_releaseMessageQueue(){if(!this._worker)throw new Error("A worker is required for the WorkerClient to work correctly.");for(const e of this._messageQueue)this._worker.postMessage(e)}async _request(e,t,r){try{return await new Promise((s=>{this._worker?this._worker.postMessage({context:I._getMessageContext(r),method:M,options:t,request:e,type:b}):this._messageQueue.push({context:I._getMessageContext(r),method:M,options:t,request:e,type:b}),this._pending.set(r.requestID,{resolve:s})}))}catch(e){return{errors:[m(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:b}):this._messageQueue.push({context:I._getMessageContext(r),method:k,options:t,request:e,type:b});const s=new i(this._eventEmitter,r.requestID);return Promise.resolve(s.getIterator())}catch(e){const t=m(e)?e:new Error("@graphql-box/worker-client subscribe had an unexpected error.");return Promise.resolve({errors:[t],requestID:r.requestID})}}}D([(r,s,o)=>{const n=o.value;n&&(o.value=async function(...r){return new Promise((s=>{(async()=>{const{debugManager:o,...a}=r[2];if(!o)return void s(await n.apply(this,r));const i=v(r[0]),u=o.now();o.log(e,{context:{...a,operationName:i},options:r[1],request:r[0],stats:{startTime:u}});const c=await n.apply(this,r),p=o.now(),h=p-u;s(c),q(c)||o.log(t,{context:{...a,operationName:i},options:r[1],request:r[0],result:c,stats:{duration:h,endTime:p,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),D([(e,t,s)=>{const o=s.value;o&&(s.value=async function(...e){return new Promise((t=>{(async()=>{const{debugManager:s,...n}=e[2];if(!s)return void t(await o.apply(this,e));const a=v(e[0]),i=s.now();s.log(r,{context:{...n,operationName:a},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:n}=e;s===M?(async(e,t,r,s,o)=>{const n=await o.request(e,r,s);if(!q(n)){const{_cacheMetadata:e,...r}=n,o=h({...r});return e&&(o._cacheMetadata=l(e)),void globalThis.postMessage({context:s,method:t,result:o,type:b})}f(n,(({_cacheMetadata:e,...r})=>{const o=h({...r});e&&(o._cacheMetadata=l(e)),globalThis.postMessage({context:s,method:t,result:o,type:b})}))})(n,s,o,r,t):(async(e,t,r,s,o)=>{const n=await o.subscribe(e,r,s);q(n)?f(n,(({_cacheMetadata:e,...r})=>{const o=h({...r});e&&(o._cacheMetadata=l(e)),globalThis.postMessage({context:s,method:t,result:o,type:b})})):globalThis.postMessage({context:s,method:t,result:h(n),type:b})})(n,s,o,r,t)},O=({client:e})=>{globalThis.addEventListener(x,(({data:t})=>{t.type===b?C(t,e):e.cache&&w(t,e.cache)}))};export{y as CACHEMAP,b as GRAPHQL_BOX,x as MESSAGE,M as REQUEST,k as SUBSCRIBE,I as WorkerClient,C as handleMessage,O 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 {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n REQUEST_RESOLVED,\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 { 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 MessageResponsePayload,\n type PendingResolver,\n type PendingTracker,\n type UserOptions,\n} from './types.ts';\n\nexport class WorkerClient {\n private static _getMessageContext({ hasDeferOrStream = false, requestID }: RequestContext): MessageContext {\n return { hasDeferOrStream, requestID };\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 pending.resolve(response);\n }\n };\n\n private _cache: CoreWorker;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _experimentalDeferStreamSupport: boolean;\n private _pending: PendingTracker = new Map();\n private _worker: Worker;\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 (!('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._debugManager = options.debugManager ?? null;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n this._worker = options.worker;\n this._addEventListener();\n }\n\n get cache(): CoreWorker {\n return this._cache;\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._request(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 private _addEventListener(): void {\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 @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 this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: REQUEST,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n this._pending.set(context.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 this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<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 {\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","requestID","constructor","options","_onMessage","data","isPlainObject","context","method","result","type","_cacheMetadata","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","Map","errors","push","ArgsError","length","GroupedError","_cache","cache","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_worker","worker","_addEventListener","mutate","_request","_getRequestContext","OperationTypeNode","MUTATION","query","QUERY","subscribe","_subscribe","SUBSCRIPTION","addEventListener","operation","fieldTypeMap","filteredRequest","operationName","originalRequestHash","hashRequest","parsedRequest","queryFiltered","requestComplexity","requestDepth","uuid","Promise","postMessage","set","error","isError","Error","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,qbCgCvB,MAAME,EACX,yBAAeC,EAAmBC,iBAAEA,GAAmB,EAAKC,UAAEA,IAC5D,MAAO,CAAED,mBAAkBC,YAC7B,CAmEAC,WAAAA,CAAYC,QAjEJC,WAAa,EAAGC,WACtB,IAAKC,EAAcD,GACjB,OAGF,MAAME,QAAEA,EAAOC,OAAEA,EAAMC,OAAEA,EAAMC,KAAEA,GAASL,EAE1C,GAAIK,IAASpB,EACX,OAGF,MAAMqB,eAAEA,KAAmBC,GAAeH,EACpCI,EAAiC,IAAKC,EAAkBF,GAAaX,UAAWM,EAAQN,WAM9F,GAJIU,IACFE,EAASF,eAAiBI,EAAuBJ,IAG/CH,IAAWf,EACbuB,KAAKC,eAAeC,IAAIC,EAAuB,CAC7CZ,UACAE,OAAQI,EACRO,MAAO,CAAEC,QAASL,KAAKC,cAAcK,SAGvCN,KAAKO,cAAcC,KAAKjB,EAAQN,UAAWY,QACtC,GAAIN,EAAQP,iBAAkB,CACnC,MAAMyB,EAAUT,KAAKU,SAASC,IAAIpB,EAAQN,WAE1C,GAAIwB,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C,KAAMpB,GAAY,IAnBpE0G,WAAWzB,YAAY,CACrBhE,UACAC,SAGAC,OAAQqF,EAAgBK,GACxBzF,KAAMpB,GAcV,EASO8G,CAAmBzG,EAASa,EAAQL,EAASI,EAASqF,EAC7D,EAGWS,EAAiB,EAAGT,aAS/BI,WAAWtC,iBAAiBnE,GARV,EAAGc,WACmBA,ED1FKK,OAASpB,EC2FlDqG,EAActF,EAAMuF,GAEfU,EAAsBjG,EAAMuF,EAAOpD,MAC1C,GAGmC+D"}
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 {\n type DebugManagerDef,\n type PartialRequestContext,\n type PartialRequestResult,\n REQUEST_RESOLVED,\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 { 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({ hasDeferOrStream = false, requestID }: RequestContext): MessageContext {\n return { hasDeferOrStream, requestID };\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 pending.resolve(response);\n }\n };\n\n private _cache: CoreWorker;\n private _debugManager: DebugManagerDef | null;\n private _eventEmitter: EventEmitter;\n private _experimentalDeferStreamSupport: boolean;\n private _messageQueue: MessageRequestPayload[] = [];\n private _pending: PendingTracker = new Map();\n\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 (!('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._debugManager = options.debugManager ?? null;\n this._eventEmitter = new EventEmitter();\n this._experimentalDeferStreamSupport = options.experimentalDeferStreamSupport ?? false;\n\n if (typeof options.worker === 'function') {\n options\n .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 {\n this._worker = options.worker;\n this._addEventListener();\n }\n }\n\n get cache(): CoreWorker {\n return this._cache;\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._request(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 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 _releaseMessageQueue(): void {\n if (!this._worker) {\n throw new Error('A worker is required for the WorkerClient to work correctly.');\n }\n\n for (const message of this._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","requestID","constructor","options","_onMessage","data","isPlainObject","context","method","result","type","_cacheMetadata","otherProps","response","deserializeErrors","rehydrateCacheMetadata","this","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","_messageQueue","Map","errors","push","ArgsError","length","GroupedError","_cache","cache","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","worker","then","_worker","_addEventListener","_releaseMessageQueue","catch","error","mutate","_request","_getRequestContext","OperationTypeNode","MUTATION","query","QUERY","subscribe","_subscribe","SUBSCRIPTION","Error","addEventListener","operation","fieldTypeMap","filteredRequest","operationName","originalRequestHash","hashRequest","parsedRequest","queryFiltered","requestComplexity","requestDepth","uuid","message","postMessage","Promise","set","isError","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,qbCiCvB,MAAME,EACX,yBAAeC,EAAmBC,iBAAEA,GAAmB,EAAKC,UAAEA,IAC5D,MAAO,CAAED,mBAAkBC,YAC7B,CAqEAC,WAAAA,CAAYC,QAnEJC,WAAa,EAAGC,WACtB,IAAKC,EAAcD,GACjB,OAGF,MAAME,QAAEA,EAAOC,OAAEA,EAAMC,OAAEA,EAAMC,KAAEA,GAASL,EAE1C,GAAIK,IAASpB,EACX,OAGF,MAAM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ED1FKK,OAASpB,EC2FlD0G,EAAc3F,EAAM4F,GACXA,EAAOxD,OACXkE,EAAsBtG,EAAM4F,EAAOxD,MAC1C,GAGmCmE"}
@@ -1,50 +1,50 @@
1
1
  -----------------------------
2
2
  Rollup File Analysis
3
3
  -----------------------------
4
- bundle size: 14.371 KB
5
- original size: 15.232 KB
6
- code reduction: 5.65 %
4
+ bundle size: 16.221 KB
5
+ original size: 16.598 KB
6
+ code reduction: 2.27 %
7
7
  module count: 8
8
8
 
9
- ███████████████████████████░░░░░░░░░░░░░░░░░░░░░░░
9
+ █████████████████████████████░░░░░░░░░░░░░░░░░░░░░
10
10
  file: /src/main.ts
11
- bundle space: 55.04 %
12
- rendered size: 7.91 KB
13
- original size: 7.223 KB
11
+ bundle space: 59.32 %
12
+ rendered size: 9.622 KB
13
+ original size: 8.571 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: 19.08 %
21
- rendered size: 2.742 KB
22
- original size: 3.62 KB
23
- code reduction: 24.25 %
20
+ bundle space: 17.61 %
21
+ rendered size: 2.857 KB
22
+ original size: 3.638 KB
23
+ code reduction: 21.47 %
24
24
  dependents: 1
25
25
  - /src/index.ts
26
26
 
27
- ███████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
27
+ ██████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
28
28
  file: /src/debug/logRequest.ts
29
- bundle space: 14.18 %
30
- rendered size: 2.038 KB
29
+ bundle space: 12.67 %
30
+ rendered size: 2.056 KB
31
31
  original size: 2.006 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: 8.97 %
39
- rendered size: 1.289 KB
38
+ bundle space: 7.98 %
39
+ rendered size: 1.294 KB
40
40
  original size: 1.516 KB
41
- code reduction: 14.97 %
41
+ code reduction: 14.64 %
42
42
  dependents: 1
43
43
  - /src/main.ts
44
44
 
45
45
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
46
46
  file: /src/helpers/operationNameRegex.ts
47
- bundle space: 1.13 %
47
+ bundle space: 1 %
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: 1.02 %
57
+ bundle space: 0.91 %
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.57 %
69
+ bundle space: 0.51 %
70
70
  rendered size: 82 Bytes
71
71
  original size: 383 Bytes
72
72
  code reduction: 78.59 %
@@ -8,6 +8,7 @@ export declare class WorkerClient {
8
8
  private _debugManager;
9
9
  private _eventEmitter;
10
10
  private _experimentalDeferStreamSupport;
11
+ private _messageQueue;
11
12
  private _pending;
12
13
  private _worker;
13
14
  constructor(options: UserOptions);
@@ -18,6 +19,7 @@ export declare class WorkerClient {
18
19
  subscribe(request: string, options?: RequestOptions): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;
19
20
  private _addEventListener;
20
21
  private _getRequestContext;
22
+ private _releaseMessageQueue;
21
23
  private _request;
22
24
  private _subscribe;
23
25
  }
@@ -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,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAGzB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAiB3B,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAIjC,OAAO,CAAC,UAAU,CAwDhB;IAEF,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,+BAA+B,CAAU;IACjD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,WAAW;IA2BhC,IAAI,KAAK,IAAI,UAAU,CAEtB;IAEY,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAIzF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAIxF,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAI1F,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAIpE,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,kBAAkB;YAwBZ,QAAQ;IA2BtB,OAAO,CAAC,UAAU;CAwBnB"}
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,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAGzB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAiB3B,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAIjC,OAAO,CAAC,UAAU,CAwDhB;IAEF,OAAO,CAAC,MAAM,CAAa;IAC3B,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;IAE7C,OAAO,CAAC,OAAO,CAAqB;gBAExB,OAAO,EAAE,WAAW;IAyChC,IAAI,KAAK,IAAI,UAAU,CAEtB;IAEY,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAIzF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAIxF,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAI1F,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAIpE,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,oBAAoB;YAWd,QAAQ;IAqCtB,OAAO,CAAC,UAAU;CAkCnB"}
@@ -18,7 +18,7 @@ export interface UserOptions {
18
18
  /**
19
19
  * The web worker instance.
20
20
  */
21
- worker: Worker;
21
+ worker: Worker | (() => Promise<Worker>);
22
22
  }
23
23
  export type MethodNames = 'request' | 'subscribe';
24
24
  export type PendingResolver = (value: PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/types.cts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,EAAE,UAAU,CAAC;IAElB;;OAEG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC;IAE/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAEzC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG,CAC5B,KAAK,EAAE,oBAAoB,GAAG,qBAAqB,CAAC,oBAAoB,GAAG,SAAS,CAAC,KAClF,IAAI,CAAC;AAEV,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,cAAc,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,EAAE,YAAY,GAAG,UAAU,C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ACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -8,6 +8,7 @@ export declare class WorkerClient {
8
8
  private _debugManager;
9
9
  private _eventEmitter;
10
10
  private _experimentalDeferStreamSupport;
11
+ private _messageQueue;
11
12
  private _pending;
12
13
  private _worker;
13
14
  constructor(options: UserOptions);
@@ -18,6 +19,7 @@ export declare class WorkerClient {
18
19
  subscribe(request: string, options?: RequestOptions): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;
19
20
  private _addEventListener;
20
21
  private _getRequestContext;
22
+ private _releaseMessageQueue;
21
23
  private _request;
22
24
  private _subscribe;
23
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAGzB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAiB3B,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAIjC,OAAO,CAAC,UAAU,CAwDhB;IAEF,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,+BAA+B,CAAU;IACjD,OAAO,CAAC,QAAQ,CAA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,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAIzF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAIxF,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,EAAE,OAAO,GAAE,qBAA0B;IAI1F,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAIpE,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,oBAAoB;YAWd,QAAQ;IAqCtB,OAAO,CAAC,UAAU;CAkCnB"}
@@ -18,7 +18,7 @@ export interface UserOptions {
18
18
  /**
19
19
  * The web worker instance.
20
20
  */
21
- worker: Worker;
21
+ worker: Worker | (() => Promise<Worker>);
22
22
  }
23
23
  export type MethodNames = 'request' | 'subscribe';
24
24
  export type PendingResolver = (value: PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,EAAE,UAAU,CAAC;IAElB;;OAEG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC;IAE/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAEzC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAElD,MAA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