@graphql-box/worker-client 5.3.2-alpha-54321.1 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graphql-box/worker-client",
3
3
  "description": "The GraphQL Box web worker client module.",
4
- "version": "5.3.2-alpha-54321.1",
4
+ "version": "5.4.0",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/graphql-box",
@@ -15,6 +15,9 @@
15
15
  "main": "./dist/cjs/index.cjs",
16
16
  "module": "./dist/esm/index.mjs",
17
17
  "types": "./dist/types/cjs/index.d.cts",
18
+ "imports": {
19
+ "#*": "./src/*"
20
+ },
18
21
  "exports": {
19
22
  ".": {
20
23
  "types": {
@@ -29,33 +32,27 @@
29
32
  "access": "public"
30
33
  },
31
34
  "dependencies": {
32
- "@types/uuid": "^9.0.3",
35
+ "@cachemap/core": "^5.2.2",
36
+ "@cachemap/core-worker": "^5.2.2",
37
+ "@types/lodash-es": "^4.17.12",
38
+ "@types/uuid": "^10.0.0",
39
+ "core-js": "^3.39.0",
33
40
  "eventemitter3": "^5.0.1",
34
41
  "iterall": "^1.3.0",
35
- "uuid": "^9.0.1",
36
- "@graphql-box/core": "5.3.1",
37
- "@graphql-box/helpers": "5.3.2-alpha-54321.1"
42
+ "lodash-es": "^4.17.21",
43
+ "uuid": "^11.0.3",
44
+ "@graphql-box/core": "5.4.0",
45
+ "@graphql-box/helpers": "5.4.0"
38
46
  },
39
47
  "peerDependencies": {
40
- "@babel/runtime": "<8",
41
- "@cachemap/core": "<6",
42
- "@cachemap/core-worker": "<6",
43
- "core-js": "<4",
44
48
  "graphql": "<17",
45
- "lodash-es": "<5",
46
- "@graphql-box/client": "5.3.2-alpha-54321.1"
49
+ "@graphql-box/client": "5.4.0"
47
50
  },
48
51
  "devDependencies": {
49
- "@babel/runtime": "^7.20.13",
50
- "@cachemap/core": "^5.0.9",
51
- "@cachemap/core-worker": "^5.0.9",
52
- "@types/lodash-es": "^4.14.191",
53
- "core-js": "^3.27.2",
54
- "cts-types": "^0.0.6",
55
- "del-cli": "^5.1.0",
56
- "graphql": "^16.8.1",
57
- "lodash-es": "^4.17.21",
58
- "@graphql-box/client": "5.3.2-alpha-54321.1"
52
+ "cts-types": "^0.0.8",
53
+ "del-cli": "^6.0.0",
54
+ "graphql": "^16.9.0",
55
+ "@graphql-box/client": "5.4.0"
59
56
  },
60
57
  "keywords": [
61
58
  "client",
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
- export const CACHEMAP = 'cachemap' as const;
2
- export const GRAPHQL_BOX = 'graphqlBox' as const;
3
- export const MESSAGE = 'message' as const;
4
- export const REQUEST = 'request' as const;
5
- export const SUBSCRIBE = 'subscribe' as const;
1
+ export const CACHEMAP = 'cachemap';
2
+ export const GRAPHQL_BOX = 'graphqlBox';
3
+ export const MESSAGE = 'message';
4
+ export const REQUEST = 'request';
5
+ export const SUBSCRIBE = 'subscribe';
@@ -12,7 +12,7 @@ import { type WorkerClient } from '../main.ts';
12
12
  type Descriptor = (
13
13
  request: string,
14
14
  options: RequestOptions,
15
- context: RequestContext
15
+ context: RequestContext,
16
16
  ) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;
17
17
 
18
18
  export const logRequest = () => {
@@ -10,7 +10,7 @@ import { type WorkerClient } from '../main.ts';
10
10
  type Descriptor = (
11
11
  request: string,
12
12
  options: RequestOptions,
13
- context: RequestContext
13
+ context: RequestContext,
14
14
  ) => Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>>;
15
15
 
16
16
  export const logSubscription = () => {
@@ -3,5 +3,5 @@ import { GRAPHQL_BOX } from '../constants.ts';
3
3
  import { type MessageRequestPayload } from '../types.ts';
4
4
 
5
5
  export const isGraphqlBoxMessageRequestPayload = (
6
- payload: MessageRequestPayload | CachemapMessageRequestPayload
6
+ payload: MessageRequestPayload | CachemapMessageRequestPayload,
7
7
  ): payload is MessageRequestPayload => payload.type === GRAPHQL_BOX;
package/src/main.ts CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  import { EventEmitter } from 'eventemitter3';
21
21
  import { OperationTypeNode } from 'graphql';
22
22
  import { isError } from 'lodash-es';
23
- import { v4 as uuidv4 } from 'uuid';
23
+ import { v4 as uuid } from 'uuid';
24
24
  import { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from './constants.ts';
25
25
  import { logRequest } from './debug/logRequest.ts';
26
26
  import { logSubscription } from './debug/logSubscription.ts';
@@ -156,7 +156,7 @@ export class WorkerClient {
156
156
  private _getRequestContext(
157
157
  operation: OperationTypeNode,
158
158
  request: string,
159
- context: PartialRequestContext = {}
159
+ context: PartialRequestContext = {},
160
160
  ): RequestContext {
161
161
  return {
162
162
  debugManager: this._debugManager,
@@ -171,7 +171,7 @@ export class WorkerClient {
171
171
  request,
172
172
  requestComplexity: null,
173
173
  requestDepth: null,
174
- requestID: uuidv4(),
174
+ requestID: uuid(),
175
175
  ...context,
176
176
  };
177
177
  }
@@ -180,7 +180,7 @@ export class WorkerClient {
180
180
  private async _request(
181
181
  request: string,
182
182
  options: RequestOptions,
183
- context: RequestContext
183
+ context: RequestContext,
184
184
  ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {
185
185
  try {
186
186
  return await new Promise((resolve: PendingResolver) => {
@@ -207,7 +207,7 @@ export class WorkerClient {
207
207
  private _subscribe(
208
208
  request: string,
209
209
  options: RequestOptions,
210
- context: RequestContext
210
+ context: RequestContext,
211
211
  ): Promise<PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>> {
212
212
  try {
213
213
  this._worker.postMessage({
@@ -15,18 +15,18 @@ import {
15
15
  type RegisterWorkerOptions,
16
16
  } from './types.ts';
17
17
 
18
- const globalScope = self as unknown as DedicatedWorkerGlobalScope;
19
-
20
18
  const handleRequest = async (
21
19
  request: string,
22
20
  method: MethodNames,
23
21
  options: RequestOptions,
24
22
  context: MessageContext,
25
- client: Client
23
+ client: Client,
26
24
  ): Promise<void> => {
27
25
  const requestResult = await client.request(request, options, context);
28
26
 
29
27
  if (!isAsyncIterable(requestResult)) {
28
+ // Need to replace this casting with a type guard
29
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
30
30
  const { _cacheMetadata, ...otherProps } = requestResult as PartialRequestResult;
31
31
  const result: PartialDehydratedRequestResult = serializeErrors({ ...otherProps });
32
32
 
@@ -34,7 +34,7 @@ const handleRequest = async (
34
34
  result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
35
35
  }
36
36
 
37
- globalScope.postMessage({ context, method, result, type: GRAPHQL_BOX });
37
+ globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });
38
38
  return;
39
39
  }
40
40
 
@@ -45,7 +45,7 @@ const handleRequest = async (
45
45
  result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
46
46
  }
47
47
 
48
- globalScope.postMessage({ context, method, result, type: GRAPHQL_BOX });
48
+ globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });
49
49
  });
50
50
  };
51
51
 
@@ -54,14 +54,16 @@ const handleSubscription = async (
54
54
  method: MethodNames,
55
55
  options: RequestOptions,
56
56
  context: MessageContext,
57
- client: Client
57
+ client: Client,
58
58
  ): Promise<void> => {
59
59
  const subscribeResult = await client.subscribe(request, options, context);
60
60
 
61
61
  if (!isAsyncIterable(subscribeResult)) {
62
- globalScope.postMessage({
62
+ globalThis.postMessage({
63
63
  context,
64
64
  method,
65
+ // Need to replace this casting with a type guard
66
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
65
67
  result: serializeErrors(subscribeResult as PartialRequestResult),
66
68
  type: GRAPHQL_BOX,
67
69
  });
@@ -76,7 +78,7 @@ const handleSubscription = async (
76
78
  result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);
77
79
  }
78
80
 
79
- globalScope.postMessage({ context, method, result, type: GRAPHQL_BOX });
81
+ globalThis.postMessage({ context, method, result, type: GRAPHQL_BOX });
80
82
  });
81
83
  };
82
84
 
@@ -99,5 +101,5 @@ export const registerWorker = ({ client }: RegisterWorkerOptions): void => {
99
101
  }
100
102
  };
101
103
 
102
- globalScope.addEventListener(MESSAGE, onMessage);
104
+ globalThis.addEventListener(MESSAGE, onMessage);
103
105
  };
package/src/types.ts CHANGED
@@ -33,7 +33,7 @@ export interface UserOptions {
33
33
  export type MethodNames = 'request' | 'subscribe';
34
34
 
35
35
  export type PendingResolver = (
36
- value: PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>
36
+ value: PartialRequestResult | AsyncIterableIterator<PartialRequestResult | undefined>,
37
37
  ) => void;
38
38
 
39
39
  export interface PendingData {