@graphql-box/worker-client 4.1.6 → 5.0.1
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/README.md +1 -5
- package/dist/cjs/index.cjs +410 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +401 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/cjs/constants.d.cts +6 -0
- package/dist/types/cjs/constants.d.cts.map +1 -0
- package/dist/types/cjs/debug/logRequest.d.cts +6 -0
- package/dist/types/cjs/debug/logRequest.d.cts.map +1 -0
- package/dist/types/cjs/debug/logSubscription.d.cts +6 -0
- package/dist/types/cjs/debug/logSubscription.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isGraphqlBoxMessageRequestPayload.d.cts +4 -0
- package/dist/types/cjs/helpers/isGraphqlBoxMessageRequestPayload.d.cts.map +1 -0
- package/dist/types/cjs/helpers/operationNameRegex.d.cts +2 -0
- package/dist/types/cjs/helpers/operationNameRegex.d.cts.map +1 -0
- package/dist/types/cjs/index.d.cts +5 -0
- package/dist/types/cjs/index.d.cts.map +1 -0
- package/dist/types/cjs/main.d.cts +24 -0
- package/dist/types/cjs/main.d.cts.map +1 -0
- package/dist/types/cjs/registerWorker.d.cts +5 -0
- package/dist/types/cjs/registerWorker.d.cts.map +1 -0
- package/dist/types/cjs/types.d.cts +49 -0
- package/dist/types/cjs/types.d.cts.map +1 -0
- package/dist/types/esm/constants.d.ts +6 -0
- package/dist/types/esm/constants.d.ts.map +1 -0
- package/dist/types/esm/debug/logRequest.d.ts +6 -0
- package/dist/types/esm/debug/logRequest.d.ts.map +1 -0
- package/dist/types/esm/debug/logSubscription.d.ts +6 -0
- package/dist/types/esm/debug/logSubscription.d.ts.map +1 -0
- package/dist/types/esm/helpers/isGraphqlBoxMessageRequestPayload.d.ts +4 -0
- package/dist/types/esm/helpers/isGraphqlBoxMessageRequestPayload.d.ts.map +1 -0
- package/dist/types/esm/helpers/operationNameRegex.d.ts +2 -0
- package/dist/types/esm/helpers/operationNameRegex.d.ts.map +1 -0
- package/dist/types/esm/index.d.ts +5 -0
- package/dist/types/esm/index.d.ts.map +1 -0
- package/dist/types/esm/main.d.ts +24 -0
- package/dist/types/esm/main.d.ts.map +1 -0
- package/dist/types/esm/registerWorker.d.ts +5 -0
- package/dist/types/esm/registerWorker.d.ts.map +1 -0
- package/{lib/types/defs/index.d.ts → dist/types/esm/types.d.ts} +11 -11
- package/dist/types/esm/types.d.ts.map +1 -0
- package/dist/types/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +57 -45
- package/src/constants.ts +5 -0
- package/src/debug/{log-request/index.ts → logRequest.ts} +30 -20
- package/src/debug/logSubscription.ts +50 -0
- package/src/helpers/isGraphqlBoxMessageRequestPayload.ts +7 -0
- package/src/helpers/operationNameRegex.test.ts +26 -14
- package/src/helpers/operationNameRegex.ts +2 -2
- package/src/index.ts +4 -3
- package/src/{main/index.ts → main.ts} +135 -108
- package/src/registerWorker.ts +107 -0
- package/src/{defs/index.ts → types.ts} +14 -9
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +17 -0
- package/lib/browser/index.js +0 -2
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/production.analysis.txt +0 -81
- package/lib/main/consts/index.js +0 -17
- package/lib/main/consts/index.js.map +0 -1
- package/lib/main/debug/log-request/index.js +0 -77
- package/lib/main/debug/log-request/index.js.map +0 -1
- package/lib/main/debug/log-subscription/index.js +0 -55
- package/lib/main/debug/log-subscription/index.js.map +0 -1
- package/lib/main/defs/index.js +0 -2
- package/lib/main/defs/index.js.map +0 -1
- package/lib/main/helpers/operationNameRegex.js +0 -14
- package/lib/main/helpers/operationNameRegex.js.map +0 -1
- package/lib/main/index.js +0 -41
- package/lib/main/index.js.map +0 -1
- package/lib/main/main/index.js +0 -249
- package/lib/main/main/index.js.map +0 -1
- package/lib/main/register-worker/index.js +0 -143
- package/lib/main/register-worker/index.js.map +0 -1
- package/lib/module/consts/index.mjs +0 -6
- package/lib/module/consts/index.mjs.map +0 -1
- package/lib/module/debug/log-request/index.mjs +0 -64
- package/lib/module/debug/log-request/index.mjs.map +0 -1
- package/lib/module/debug/log-subscription/index.mjs +0 -43
- package/lib/module/debug/log-subscription/index.mjs.map +0 -1
- package/lib/module/defs/index.mjs +0 -2
- package/lib/module/defs/index.mjs.map +0 -1
- package/lib/module/helpers/operationNameRegex.mjs +0 -5
- package/lib/module/helpers/operationNameRegex.mjs.map +0 -1
- package/lib/module/index.mjs +0 -4
- package/lib/module/index.mjs.map +0 -1
- package/lib/module/main/index.mjs +0 -236
- package/lib/module/main/index.mjs.map +0 -1
- package/lib/module/register-worker/index.mjs +0 -126
- package/lib/module/register-worker/index.mjs.map +0 -1
- package/lib/types/consts/index.d.ts +0 -6
- package/lib/types/consts/index.d.ts.map +0 -1
- package/lib/types/debug/log-request/index.d.ts +0 -2
- package/lib/types/debug/log-request/index.d.ts.map +0 -1
- package/lib/types/debug/log-subscription/index.d.ts +0 -2
- package/lib/types/debug/log-subscription/index.d.ts.map +0 -1
- package/lib/types/defs/index.d.ts.map +0 -1
- package/lib/types/helpers/operationNameRegex.d.ts +0 -3
- package/lib/types/helpers/operationNameRegex.d.ts.map +0 -1
- package/lib/types/helpers/operationNameRegex.test.d.ts +0 -2
- package/lib/types/helpers/operationNameRegex.test.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -4
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/main/index.d.ts +0 -32
- package/lib/types/main/index.d.ts.map +0 -1
- package/lib/types/register-worker/index.d.ts +0 -5
- package/lib/types/register-worker/index.d.ts.map +0 -1
- package/src/consts/index.ts +0 -7
- package/src/debug/log-subscription/index.ts +0 -41
- package/src/register-worker/index.ts +0 -95
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.handleMessage = handleMessage;
|
|
9
|
-
exports.default = registerWorker;
|
|
10
|
-
|
|
11
|
-
require("core-js/modules/es.promise.js");
|
|
12
|
-
|
|
13
|
-
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
14
|
-
|
|
15
|
-
var _coreWorker = require("@cachemap/core-worker");
|
|
16
|
-
|
|
17
|
-
var _helpers = require("@graphql-box/helpers");
|
|
18
|
-
|
|
19
|
-
var _iterall = require("iterall");
|
|
20
|
-
|
|
21
|
-
var _consts = require("../consts");
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
addEventListener,
|
|
25
|
-
postMessage
|
|
26
|
-
} = self;
|
|
27
|
-
|
|
28
|
-
async function handleRequest(request, method, options, context, client) {
|
|
29
|
-
const requestResult = await client.request(request, options, context);
|
|
30
|
-
|
|
31
|
-
if (!(0, _iterall.isAsyncIterable)(requestResult)) {
|
|
32
|
-
const {
|
|
33
|
-
_cacheMetadata,
|
|
34
|
-
...otherProps
|
|
35
|
-
} = requestResult;
|
|
36
|
-
const result = { ...otherProps
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
if (_cacheMetadata) {
|
|
40
|
-
result._cacheMetadata = (0, _helpers.dehydrateCacheMetadata)(_cacheMetadata);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
postMessage({
|
|
44
|
-
context,
|
|
45
|
-
method,
|
|
46
|
-
result: (0, _helpers.serializeErrors)(result),
|
|
47
|
-
type: _consts.GRAPHQL_BOX
|
|
48
|
-
});
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
(0, _iterall.forAwaitEach)(requestResult, ({
|
|
53
|
-
_cacheMetadata,
|
|
54
|
-
...otherProps
|
|
55
|
-
}) => {
|
|
56
|
-
const result = { ...otherProps
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if (_cacheMetadata) {
|
|
60
|
-
result._cacheMetadata = (0, _helpers.dehydrateCacheMetadata)(_cacheMetadata);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
postMessage({
|
|
64
|
-
context,
|
|
65
|
-
method,
|
|
66
|
-
result: (0, _helpers.serializeErrors)(result),
|
|
67
|
-
type: _consts.GRAPHQL_BOX
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function handleSubscription(request, method, options, context, client) {
|
|
73
|
-
const subscribeResult = await client.subscribe(request, options, context);
|
|
74
|
-
|
|
75
|
-
if (!(0, _iterall.isAsyncIterable)(subscribeResult)) {
|
|
76
|
-
postMessage({
|
|
77
|
-
context,
|
|
78
|
-
method,
|
|
79
|
-
result: (0, _helpers.serializeErrors)(subscribeResult),
|
|
80
|
-
type: _consts.GRAPHQL_BOX
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
(0, _iterall.forAwaitEach)(subscribeResult, ({
|
|
86
|
-
_cacheMetadata,
|
|
87
|
-
...otherProps
|
|
88
|
-
}) => {
|
|
89
|
-
const result = { ...otherProps
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
if (_cacheMetadata) {
|
|
93
|
-
result._cacheMetadata = (0, _helpers.dehydrateCacheMetadata)(_cacheMetadata);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
postMessage({
|
|
97
|
-
context,
|
|
98
|
-
method,
|
|
99
|
-
result: (0, _helpers.serializeErrors)(result),
|
|
100
|
-
type: _consts.GRAPHQL_BOX
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function handleMessage(data, client) {
|
|
106
|
-
const {
|
|
107
|
-
context,
|
|
108
|
-
method,
|
|
109
|
-
options,
|
|
110
|
-
request
|
|
111
|
-
} = data;
|
|
112
|
-
|
|
113
|
-
if (method === _consts.REQUEST) {
|
|
114
|
-
handleRequest(request, method, options, context, client);
|
|
115
|
-
} else if (method === _consts.SUBSCRIBE) {
|
|
116
|
-
handleSubscription(request, method, options, context, client);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function registerWorker({
|
|
121
|
-
client
|
|
122
|
-
}) {
|
|
123
|
-
function onMessage({
|
|
124
|
-
data
|
|
125
|
-
}) {
|
|
126
|
-
if (!(0, _isPlainObject2.default)(data)) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const {
|
|
131
|
-
type
|
|
132
|
-
} = data;
|
|
133
|
-
|
|
134
|
-
if (type === _consts.GRAPHQL_BOX) {
|
|
135
|
-
handleMessage(data, client);
|
|
136
|
-
} else if (type === _consts.CACHEMAP && client.cache) {
|
|
137
|
-
(0, _coreWorker.handleMessage)(data, client.cache);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
addEventListener(_consts.MESSAGE, onMessage);
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/register-worker/index.ts"],"names":["addEventListener","postMessage","self","handleRequest","request","method","options","context","client","requestResult","_cacheMetadata","otherProps","result","type","GRAPHQL_BOX","handleSubscription","subscribeResult","subscribe","handleMessage","data","REQUEST","SUBSCRIBE","registerWorker","onMessage","CACHEMAP","cache","MESSAGE"],"mappings":";;;;;;;;;;;;;;AAAA;;AAGA;;AACA;;AAEA;;AAGA,MAAM;AAAEA,EAAAA,gBAAF;AAAoBC,EAAAA;AAApB,IAAqCC,IAA3C;;AAEA,eAAeC,aAAf,CACEC,OADF,EAEEC,MAFF,EAGEC,OAHF,EAIEC,OAJF,EAKEC,MALF,EAMiB;AACf,QAAMC,aAAa,GAAG,MAAMD,MAAM,CAACJ,OAAP,CAAeA,OAAf,EAAwBE,OAAxB,EAAiCC,OAAjC,CAA5B;;AAEA,MAAI,CAAC,8BAAgBE,aAAhB,CAAL,EAAq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,MAEO,IAAIK,IAAI,KAAKW,gBAAT,IAAqBhB,MAAM,CAACiB,KAAhC,EAAuC;AAC5C,qCAAsBN,IAAtB,EAA4BX,MAAM,CAACiB,KAAnC;AACD;AACF;;AAEDzB,EAAAA,gBAAgB,CAAC0B,eAAD,EAAUH,SAAV,CAAhB;AACD","sourcesContent":["import { handleMessage as handleCachemapMessage } from \"@cachemap/core-worker\";\nimport Client from \"@graphql-box/client\";\nimport { MaybeRequestResult, MaybeRequestResultWithDehydratedCacheMetadata, RequestOptions } from \"@graphql-box/core\";\nimport { dehydrateCacheMetadata, serializeErrors } from \"@graphql-box/helpers\";\nimport { forAwaitEach, isAsyncIterable } from \"iterall\";\nimport { isPlainObject } from \"lodash\";\nimport { CACHEMAP, GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport { MessageContext, MessageRequestPayload, MethodNames, RegisterWorkerOptions } from \"../defs\";\n\nconst { addEventListener, postMessage } = (self as unknown) as DedicatedWorkerGlobalScope;\n\nasync function handleRequest(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const requestResult = await client.request(request, options, context);\n\n if (!isAsyncIterable(requestResult)) {\n const { _cacheMetadata, ...otherProps } = requestResult as MaybeRequestResult;\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(requestResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nasync function handleSubscription(\n request: string,\n method: MethodNames,\n options: RequestOptions,\n context: MessageContext,\n client: Client,\n): Promise<void> {\n const subscribeResult = await client.subscribe(request, options, context);\n\n if (!isAsyncIterable(subscribeResult)) {\n postMessage({ context, method, result: serializeErrors(subscribeResult as MaybeRequestResult), type: GRAPHQL_BOX });\n return;\n }\n\n forAwaitEach(subscribeResult, ({ _cacheMetadata, ...otherProps }: MaybeRequestResult) => {\n const result: MaybeRequestResultWithDehydratedCacheMetadata = { ...otherProps };\n\n if (_cacheMetadata) {\n result._cacheMetadata = dehydrateCacheMetadata(_cacheMetadata);\n }\n\n postMessage({ context, method, result: serializeErrors(result), type: GRAPHQL_BOX });\n });\n}\n\nexport function handleMessage(data: MessageRequestPayload, client: Client): void {\n const { context, method, options, request } = data as MessageRequestPayload;\n\n if (method === REQUEST) {\n handleRequest(request, method, options, context, client);\n } else if (method === SUBSCRIBE) {\n handleSubscription(request, method, options, context, client);\n }\n}\n\nexport default async function registerWorker({ client }: RegisterWorkerOptions): Promise<void> {\n function onMessage({ data }: MessageEvent): void {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { type } = data as MessageRequestPayload;\n\n if (type === GRAPHQL_BOX) {\n handleMessage(data, client);\n } else if (type === CACHEMAP && client.cache) {\n handleCachemapMessage(data, client.cache);\n }\n }\n\n addEventListener(MESSAGE, onMessage);\n}\n"],"file":"index.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/consts/index.ts"],"names":["REQUEST","SUBSCRIBE","MESSAGE","GRAPHQL_BOX","CACHEMAP"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAG,SAAhB;AACP,OAAO,MAAMC,SAAS,GAAG,WAAlB;AAEP,OAAO,MAAMC,OAAO,GAAG,SAAhB;AAEP,OAAO,MAAMC,WAAW,GAAG,YAApB;AACP,OAAO,MAAMC,QAAQ,GAAG,UAAjB","sourcesContent":["export const REQUEST = \"request\";\nexport const SUBSCRIBE = \"subscribe\";\n\nexport const MESSAGE = \"message\";\n\nexport const GRAPHQL_BOX = \"graphqlBox\";\nexport const CACHEMAP = \"cachemap\";\n"],"file":"index.mjs"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.promise.js";
|
|
2
|
-
import { REQUEST_EXECUTED, REQUEST_RESOLVED } from "@graphql-box/core";
|
|
3
|
-
import { isAsyncIterable } from "iterall";
|
|
4
|
-
import operationNameRegex from "../../helpers/operationNameRegex";
|
|
5
|
-
export default function logRequest() {
|
|
6
|
-
return (_target, _propertyName, descriptor) => {
|
|
7
|
-
const method = descriptor.value;
|
|
8
|
-
if (!method) return;
|
|
9
|
-
|
|
10
|
-
descriptor.value = async function descriptorValue(...args) {
|
|
11
|
-
try {
|
|
12
|
-
return new Promise(async resolve => {
|
|
13
|
-
const {
|
|
14
|
-
debugManager,
|
|
15
|
-
...otherContext
|
|
16
|
-
} = args[2];
|
|
17
|
-
|
|
18
|
-
if (!debugManager) {
|
|
19
|
-
resolve(await method.apply(this, args));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const derivedOperationName = operationNameRegex(args[0]);
|
|
24
|
-
const startTime = debugManager.now();
|
|
25
|
-
debugManager.log(REQUEST_EXECUTED, {
|
|
26
|
-
context: { ...otherContext,
|
|
27
|
-
operationName: derivedOperationName
|
|
28
|
-
},
|
|
29
|
-
options: args[1],
|
|
30
|
-
request: args[0],
|
|
31
|
-
stats: {
|
|
32
|
-
startTime
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const result = await method.apply(this, args);
|
|
36
|
-
const endTime = debugManager.now();
|
|
37
|
-
const duration = endTime - startTime;
|
|
38
|
-
resolve(result);
|
|
39
|
-
|
|
40
|
-
if (isAsyncIterable(result)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
debugManager.log(REQUEST_RESOLVED, {
|
|
45
|
-
context: { ...otherContext,
|
|
46
|
-
operationName: derivedOperationName
|
|
47
|
-
},
|
|
48
|
-
options: args[1],
|
|
49
|
-
request: args[0],
|
|
50
|
-
result,
|
|
51
|
-
stats: {
|
|
52
|
-
duration,
|
|
53
|
-
endTime,
|
|
54
|
-
startTime
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
} catch (error) {
|
|
59
|
-
return Promise.reject(error);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/debug/log-request/index.ts"],"names":["REQUEST_EXECUTED","REQUEST_RESOLVED","isAsyncIterable","operationNameRegex","logRequest","_target","_propertyName","descriptor","method","value","descriptorValue","args","Promise","resolve","debugManager","otherContext","apply","derivedOperationName","startTime","now","log","context","operationName","options","request","stats","result","endTime","duration","error","reject"],"mappings":";AAAA,SAASA,gBAAT,EAA2BC,gBAA3B,QAAmE,mBAAnE;AACA,SAASC,eAAT,QAAgC,SAAhC;AACA,OAAOC,kBAAP,MAA+B,kCAA/B;AAEA,eAAe,SAASC,UAAT,GAAsB;AACnC,SAAO,CACLC,OADK,EAELC,aAFK,EAGLC,UAHK,KAII;AACT,UAAMC,MAAM,GAAGD,UAAU,CAACE,KAA1B;AACA,QAAI,CAACD,MAAL,EAAa;;AAEbD,IAAAA,UAAU,CAACE,KAAX,GAAmB,eAAeC,eAAf,CAA+B,GAAGC,IAAlC,EAA6D;AAC9E,UAAI;AACF,eAAO,IAAIC,OAAJ,CAAY,MAAMC,OAAN,IAAiB;AAClC,gBAAM;AAAEC,YAAAA,YAAF;AAAgB,eAAGC;AAAnB,cAAoCJ,IAAI,CAAC,CAAD,CAA9C;;AAEA,cAAI,CAACG,YAAL,EAAmB;AACjBD,YAAAA,OAAO,CAAC,MAAML,MAAM,CAACQ,KAAP,CAAa,IAAb,EAAmBL,IAAnB,CAAP,CAAP;AACA;AACD;;AAED,gBAAMM,oBAAoB,GAAGd,kBAAkB,CAACQ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ourcesContent":["import { REQUEST_EXECUTED, REQUEST_RESOLVED, RequestContext } from \"@graphql-box/core\";\nimport { isAsyncIterable } from \"iterall\";\nimport operationNameRegex from \"../../helpers/operationNameRegex\";\n\nexport default function logRequest() {\n return (\n _target: any,\n _propertyName: string,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>,\n ): void => {\n const method = descriptor.value;\n if (!method) return;\n\n descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {\n try {\n return new Promise(async resolve => {\n const { debugManager, ...otherContext } = args[2] as RequestContext;\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const 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 } catch (error) {\n return Promise.reject(error);\n }\n };\n };\n}\n"],"file":"index.mjs"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.promise.js";
|
|
2
|
-
import { SUBSCRIPTION_EXECUTED } from "@graphql-box/core";
|
|
3
|
-
import operationNameRegex from "../../helpers/operationNameRegex";
|
|
4
|
-
export default function logSubscription() {
|
|
5
|
-
return (_target, _propertyName, descriptor) => {
|
|
6
|
-
const method = descriptor.value;
|
|
7
|
-
if (!method) return;
|
|
8
|
-
|
|
9
|
-
descriptor.value = async function descriptorValue(...args) {
|
|
10
|
-
try {
|
|
11
|
-
return new Promise(async resolve => {
|
|
12
|
-
const {
|
|
13
|
-
debugManager,
|
|
14
|
-
...otherContext
|
|
15
|
-
} = args[2];
|
|
16
|
-
|
|
17
|
-
if (!debugManager) {
|
|
18
|
-
resolve(await method.apply(this, args));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const derivedOperationName = operationNameRegex(args[0]);
|
|
23
|
-
const startTime = debugManager.now();
|
|
24
|
-
debugManager.log(SUBSCRIPTION_EXECUTED, {
|
|
25
|
-
context: { ...otherContext,
|
|
26
|
-
operationName: derivedOperationName
|
|
27
|
-
},
|
|
28
|
-
options: args[1],
|
|
29
|
-
request: args[0],
|
|
30
|
-
stats: {
|
|
31
|
-
startTime
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
const result = await method.apply(this, args);
|
|
35
|
-
resolve(result);
|
|
36
|
-
});
|
|
37
|
-
} catch (error) {
|
|
38
|
-
return Promise.reject(error);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/debug/log-subscription/index.ts"],"names":["SUBSCRIPTION_EXECUTED","operationNameRegex","logSubscription","_target","_propertyName","descriptor","method","value","descriptorValue","args","Promise","resolve","debugManager","otherContext","apply","derivedOperationName","startTime","now","log","context","operationName","options","request","stats","result","error","reject"],"mappings":";AAAA,SAAyBA,qBAAzB,QAAsD,mBAAtD;AACA,OAAOC,kBAAP,MAA+B,kCAA/B;AAEA,eAAe,SAASC,eAAT,GAA2B;AACxC,SAAO,CACLC,OADK,EAELC,aAFK,EAGLC,UAHK,KAII;AACT,UAAMC,MAAM,GAAGD,UAAU,CAACE,KAA1B;AACA,QAAI,CAACD,MAAL,EAAa;;AAEbD,IAAAA,UAAU,CAACE,KAAX,GAAmB,eAAeC,eAAf,CAA+B,GAAGC,IAAlC,EAA6D;AAC9E,UAAI;AACF,eAAO,IAAIC,OAAJ,CAAY,MAAMC,OAAN,IAAiB;AAClC,gBAAM;AAAEC,YAAAA,YAAF;AAAgB,eAAGC;AAAnB,cAAoCJ,IAAI,CAAC,CAAD,CAA9C;;AAEA,cAAI,CAACG,YAAL,EAAmB;AACjBD,YAAAA,OAAO,CAAC,MAAML,MAAM,CAACQ,KAAP,CAAa,IAAb,EAAmBL,IAAnB,CAAP,CAAP;AACA;AACD;;AAED,gBAAMM,oBAAoB,GAAGd,kBAAkB,CAACQ,IAAI,CAAC,CAAD,CAAL,CAA/C;AACA,gBAAMO,SAAS,GAAGJ,YAAY,CAACK,GAAb,EAAlB;AAEAL,UAAAA,YAAY,CAACM,GAAb,CAAiBlB,qBAAjB,EAAwC;AACtCmB,YAAAA,OAAO,EAAE,EAAE,GAAGN,YAAL;AAAmBO,cAAAA,aAAa,EAAEL;AAAlC,aAD6B;AAEtCM,YAAAA,OAAO,EAAEZ,IAAI,CAAC,CAAD,CAFyB;AAGtCa,YAAAA,OAAO,EAAEb,IAAI,CAAC,CAAD,CAHyB;AAItCc,YAAAA,KAAK,EAAE;AAAEP,cAAAA;AAAF;AAJ+B,WAAxC;AAOA,gBAAMQ,MAAM,GAAG,MAAMlB,MAAM,CAACQ,KAAP,CAAa,IAAb,EAAmBL,IAAnB,CAArB;AACAE,UAAAA,OAAO,CAACa,MAAD,CAAP;AACD,SApBM,CAAP;AAqBD,OAtBD,CAsBE,OAAOC,KAAP,EAAc;AACd,eAAOf,OAAO,CAACgB,MAAR,CAAeD,KAAf,CAAP;AACD;AACF,KA1BD;AA2BD,GAnCD;AAoCD","sourcesContent":["import { RequestContext, SUBSCRIPTION_EXECUTED } from \"@graphql-box/core\";\nimport operationNameRegex from \"../../helpers/operationNameRegex\";\n\nexport default function logSubscription() {\n return (\n _target: any,\n _propertyName: string,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>,\n ): void => {\n const method = descriptor.value;\n if (!method) return;\n\n descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {\n try {\n return new Promise(async resolve => {\n const { debugManager, ...otherContext } = args[2] as RequestContext;\n\n if (!debugManager) {\n resolve(await method.apply(this, args));\n return;\n }\n\n const 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 } catch (error) {\n return Promise.reject(error);\n }\n };\n };\n}\n"],"file":"index.mjs"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.mjs"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/helpers/operationNameRegex.ts"],"names":["request","output","exec"],"mappings":"AAAA,gBAAgBA,OAAD,IAAqB;AAClC,QAAMC,MAAM,GAAG,mDAAmDC,IAAnD,CAAwDF,OAAxD,CAAf;AACA,SAAOC,MAAM,GAAGA,MAAM,CAAC,CAAD,CAAT,GAAe,EAA5B;AACD,CAHD","sourcesContent":["export default (request: string) => {\n const output = /(query|mutation|subscription) ([A-Za-z]+)(\\(| {)/.exec(request);\n return output ? output[2] : \"\";\n};\n"],"file":"operationNameRegex.mjs"}
|
package/lib/module/index.mjs
DELETED
package/lib/module/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["default","registerWorker"],"mappings":"AAAA,cAAc,QAAd;AACA,SAASA,OAAT,QAAwB,QAAxB;AACA,SAASA,OAAO,IAAIC,cAApB,QAA0C,mBAA1C","sourcesContent":["export * from \"./defs\";\nexport { default } from \"./main\";\nexport { default as registerWorker } from \"./register-worker\";\n"],"file":"index.mjs"}
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
|
|
3
|
-
import _isPlainObject from "lodash/isPlainObject";
|
|
4
|
-
import _castArray from "lodash/castArray";
|
|
5
|
-
|
|
6
|
-
var _dec, _dec2, _class;
|
|
7
|
-
|
|
8
|
-
import "core-js/modules/es.promise.js";
|
|
9
|
-
import { MUTATION, QUERY, REQUEST_RESOLVED, SUBSCRIPTION, SUBSCRIPTION_RESOLVED } from "@graphql-box/core";
|
|
10
|
-
import { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from "@graphql-box/helpers";
|
|
11
|
-
import EventEmitter from "eventemitter3";
|
|
12
|
-
import { v1 as uuid } from "uuid";
|
|
13
|
-
import { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from "../consts";
|
|
14
|
-
import logRequest from "../debug/log-request";
|
|
15
|
-
import logSubscription from "../debug/log-subscription";
|
|
16
|
-
let WorkerClient = (_dec = logRequest(), _dec2 = logSubscription(), (_class = class WorkerClient {
|
|
17
|
-
static _getMessageContext({
|
|
18
|
-
hasDeferOrStream = false,
|
|
19
|
-
requestID
|
|
20
|
-
}) {
|
|
21
|
-
return {
|
|
22
|
-
hasDeferOrStream,
|
|
23
|
-
requestID
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(options) {
|
|
28
|
-
var _options$debugManager, _options$experimental;
|
|
29
|
-
|
|
30
|
-
_defineProperty(this, "_cache", void 0);
|
|
31
|
-
|
|
32
|
-
_defineProperty(this, "_debugManager", void 0);
|
|
33
|
-
|
|
34
|
-
_defineProperty(this, "_eventEmitter", void 0);
|
|
35
|
-
|
|
36
|
-
_defineProperty(this, "_experimentalDeferStreamSupport", void 0);
|
|
37
|
-
|
|
38
|
-
_defineProperty(this, "_pending", new Map());
|
|
39
|
-
|
|
40
|
-
_defineProperty(this, "_worker", void 0);
|
|
41
|
-
|
|
42
|
-
_defineProperty(this, "_onMessage", async ({
|
|
43
|
-
data
|
|
44
|
-
}) => {
|
|
45
|
-
if (!_isPlainObject(data)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const {
|
|
50
|
-
context,
|
|
51
|
-
method,
|
|
52
|
-
result,
|
|
53
|
-
type
|
|
54
|
-
} = data;
|
|
55
|
-
|
|
56
|
-
if (type !== GRAPHQL_BOX || !_isPlainObject(result)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
_cacheMetadata,
|
|
62
|
-
...otherProps
|
|
63
|
-
} = result;
|
|
64
|
-
const response = deserializeErrors({ ...otherProps,
|
|
65
|
-
requestID: context.requestID
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (_cacheMetadata) {
|
|
69
|
-
response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (method === SUBSCRIBE) {
|
|
73
|
-
var _this$_debugManager, _this$_debugManager2;
|
|
74
|
-
|
|
75
|
-
(_this$_debugManager = this._debugManager) === null || _this$_debugManager === void 0 ? void 0 : _this$_debugManager.log(SUBSCRIPTION_RESOLVED, {
|
|
76
|
-
context,
|
|
77
|
-
result: response,
|
|
78
|
-
stats: {
|
|
79
|
-
endTime: (_this$_debugManager2 = this._debugManager) === null || _this$_debugManager2 === void 0 ? void 0 : _this$_debugManager2.now()
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
this._eventEmitter.emit(context.requestID, response);
|
|
84
|
-
} else if (context.hasDeferOrStream) {
|
|
85
|
-
var _this$_debugManager3, _this$_debugManager4;
|
|
86
|
-
|
|
87
|
-
const pending = this._pending.get(context.requestID);
|
|
88
|
-
|
|
89
|
-
if (pending) {
|
|
90
|
-
const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, context.requestID);
|
|
91
|
-
pending.resolve(eventAsyncIterator.getIterator());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
(_this$_debugManager3 = this._debugManager) === null || _this$_debugManager3 === void 0 ? void 0 : _this$_debugManager3.log(REQUEST_RESOLVED, {
|
|
95
|
-
context,
|
|
96
|
-
result: response,
|
|
97
|
-
stats: {
|
|
98
|
-
endTime: (_this$_debugManager4 = this._debugManager) === null || _this$_debugManager4 === void 0 ? void 0 : _this$_debugManager4.now()
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this._eventEmitter.emit(context.requestID, response);
|
|
103
|
-
} else {
|
|
104
|
-
var _this$_debugManager5, _this$_debugManager6;
|
|
105
|
-
|
|
106
|
-
const pending = this._pending.get(context.requestID);
|
|
107
|
-
|
|
108
|
-
if (!pending) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
(_this$_debugManager5 = this._debugManager) === null || _this$_debugManager5 === void 0 ? void 0 : _this$_debugManager5.log(REQUEST_RESOLVED, {
|
|
113
|
-
context,
|
|
114
|
-
result: response,
|
|
115
|
-
stats: {
|
|
116
|
-
endTime: (_this$_debugManager6 = this._debugManager) === null || _this$_debugManager6 === void 0 ? void 0 : _this$_debugManager6.now()
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
pending.resolve(response);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const errors = [];
|
|
124
|
-
|
|
125
|
-
if (!_isPlainObject(options)) {
|
|
126
|
-
errors.push(new TypeError("@graphql-box/client expected options to ba a plain object."));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!options.cache) {
|
|
130
|
-
errors.push(new TypeError("@graphql-box/client expected options.cache."));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!options.worker) {
|
|
134
|
-
errors.push(new TypeError("@graphql-box/client expected options.worker."));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (errors.length) {
|
|
138
|
-
throw errors;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
this._cache = options.cache;
|
|
142
|
-
this._debugManager = (_options$debugManager = options.debugManager) !== null && _options$debugManager !== void 0 ? _options$debugManager : null;
|
|
143
|
-
this._eventEmitter = new EventEmitter();
|
|
144
|
-
this._experimentalDeferStreamSupport = (_options$experimental = options.experimentalDeferStreamSupport) !== null && _options$experimental !== void 0 ? _options$experimental : false;
|
|
145
|
-
this._worker = options.worker;
|
|
146
|
-
|
|
147
|
-
this._addEventListener();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
get cache() {
|
|
151
|
-
return this._cache;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async mutate(request, options = {}, context = {}) {
|
|
155
|
-
return this._request(request, options, this._getRequestContext(MUTATION, request, context));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async query(request, options = {}, context = {}) {
|
|
159
|
-
return this._request(request, options, this._getRequestContext(QUERY, request, context));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async request(request, options = {}, context = {}) {
|
|
163
|
-
return this._request(request, options, this._getRequestContext(QUERY, request, context));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async subscribe(request, options = {}) {
|
|
167
|
-
return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
_addEventListener() {
|
|
171
|
-
this._worker.addEventListener(MESSAGE, this._onMessage);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
_getRequestContext(operation, request, context = {}) {
|
|
175
|
-
return {
|
|
176
|
-
debugManager: this._debugManager,
|
|
177
|
-
experimentalDeferStreamSupport: this._experimentalDeferStreamSupport,
|
|
178
|
-
fieldTypeMap: new Map(),
|
|
179
|
-
filteredRequest: "",
|
|
180
|
-
operation,
|
|
181
|
-
operationName: "",
|
|
182
|
-
originalRequestHash: hashRequest(request),
|
|
183
|
-
parsedRequest: "",
|
|
184
|
-
queryFiltered: false,
|
|
185
|
-
request,
|
|
186
|
-
requestComplexity: null,
|
|
187
|
-
requestDepth: null,
|
|
188
|
-
requestID: uuid(),
|
|
189
|
-
...context
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async _request(request, options, context) {
|
|
194
|
-
try {
|
|
195
|
-
return await new Promise(resolve => {
|
|
196
|
-
this._worker.postMessage({
|
|
197
|
-
context: WorkerClient._getMessageContext(context),
|
|
198
|
-
method: REQUEST,
|
|
199
|
-
options,
|
|
200
|
-
request,
|
|
201
|
-
type: GRAPHQL_BOX
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
this._pending.set(context.requestID, {
|
|
205
|
-
resolve
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
} catch (error) {
|
|
209
|
-
return {
|
|
210
|
-
errors: _castArray(error)
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async _subscribe(request, options, context) {
|
|
216
|
-
try {
|
|
217
|
-
this._worker.postMessage({
|
|
218
|
-
context: WorkerClient._getMessageContext(context),
|
|
219
|
-
method: SUBSCRIBE,
|
|
220
|
-
options,
|
|
221
|
-
request,
|
|
222
|
-
type: GRAPHQL_BOX
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, context.requestID);
|
|
226
|
-
return eventAsyncIterator.getIterator();
|
|
227
|
-
} catch (error) {
|
|
228
|
-
return {
|
|
229
|
-
errors: _castArray(error)
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
}, (_applyDecoratedDescriptor(_class.prototype, "_request", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "_request"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_subscribe", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "_subscribe"), _class.prototype)), _class));
|
|
235
|
-
export { WorkerClient as default };
|
|
236
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/main/index.ts"],"names":["MUTATION","QUERY","REQUEST_RESOLVED","SUBSCRIPTION","SUBSCRIPTION_RESOLVED","EventAsyncIterator","deserializeErrors","hashRequest","rehydrateCacheMetadata","EventEmitter","v1","uuid","GRAPHQL_BOX","MESSAGE","REQUEST","SUBSCRIBE","logRequest","logSubscription","WorkerClient","_getMessageContext","hasDeferOrStream","requestID","constructor","options","Map","data","context","method","result","type","_cacheMetadata","otherProps","response","_debugManager","log","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","resolve","getIterator","errors","push","TypeError","cache","worker","length","_cache","debugManager","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_worker","_addEventListener","mutate","request","_request","_getRequestContext","query","subscribe","_subscribe","addEventListener","_onMessage","operation","fieldTypeMap","filteredRequest","operationName","originalRequestHash","parsedRequest","queryFiltered","requestComplexity","requestDepth","Promise","postMessage","set","error"],"mappings":";;;;;;;;AACA,SAEEA,QAFF,EAKEC,KALF,EAMEC,gBANF,EASEC,YATF,EAUEC,qBAVF,QAYO,mBAZP;AAaA,SAASC,kBAAT,EAA6BC,iBAA7B,EAAgDC,WAAhD,EAA6DC,sBAA7D,QAA2F,sBAA3F;AACA,OAAOC,YAAP,MAAyB,eAAzB;AAEA,SAASC,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,OAA/B,EAAwCC,SAAxC,QAAyD,WAAzD;AACA,OAAOC,UAAP,MAAuB,sBAAvB;AACA,OAAOC,eAAP,MAA4B,2BAA5B;IAGqBC,Y,WAgJlBF,UAAU,E,UAmBVC,eAAe,E,YAnKH,MAAMC,YAAN,CAAmB;AACC,SAAlBC,kBAAkB,CAAC;AAAEC,IAAAA,gBAAgB,GAAG,KAArB;AAA4BC,IAAAA;AAA5B,GAAD,EAA0E;AACzG,WAAO;AAAED,MAAAA,gBAAF;AAAoBC,MAAAA;AAApB,KAAP;AACD;;AASDC,EAAAA,WAAW,CAACC,OAAD,EAAuB;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,sCAHC,IAAI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JuB;AAKvB9B,UAAAA,IAAI,EAAEjB;AALiB,SAAzB;;AAQA,aAAK6B,QAAL,CAAcqC,GAAd,CAAkBpD,OAAO,CAACL,SAA1B,EAAqC;AAAEuB,UAAAA;AAAF,SAArC;AACD,OAVY,CAAb;AAWD,KAZD,CAYE,OAAOmC,KAAP,EAAc;AACd,aAAO;AAAEjC,QAAAA,MAAM,EAAE,WAAUiC,KAAV;AAAV,OAAP;AACD;AACF;;AAGuB,QAAVf,UAAU,CAACL,OAAD,EAAkBpC,OAAlB,EAA2CG,OAA3C,EAAoE;AAC1F,QAAI;AACF,WAAK8B,OAAL,CAAaqB,WAAb,CAAyB;AACvBnD,QAAAA,OAAO,EAAER,YAAY,CAACC,kBAAb,CAAgCO,OAAhC,CADc;AAEvBC,QAAAA,MAAM,EAAEZ,SAFe;AAGvBQ,QAAAA,OAHuB;AAIvBoC,QAAAA,OAJuB;AAKvB9B,QAAAA,IAAI,EAAEjB;AALiB,OAAzB;;AAQA,YAAM+B,kBAAkB,GAAG,IAAItC,kBAAJ,CAA2C,KAAKiC,aAAhD,EAA+DZ,OAAO,CAACL,SAAvE,CAA3B;AACA,aAAOsB,kBAAkB,CAACE,WAAnB,EAAP;AACD,KAXD,CAWE,OAAOkC,KAAP,EAAc;AACd,aAAO;AAAEjC,QAAAA,MAAM,EAAE,WAAUiC,KAAV;AAAV,OAAP;AACD;AACF;;AAnL+B,C;SAAb7D,Y","sourcesContent":["import WorkerCachemap from \"@cachemap/core-worker\";\nimport {\n DebugManagerDef,\n MUTATION,\n MaybeRequestContext,\n MaybeRequestResult,\n QUERY,\n REQUEST_RESOLVED,\n RequestContext,\n RequestOptions,\n SUBSCRIPTION,\n SUBSCRIPTION_RESOLVED,\n ValidOperations,\n} from \"@graphql-box/core\";\nimport { EventAsyncIterator, deserializeErrors, hashRequest, rehydrateCacheMetadata } from \"@graphql-box/helpers\";\nimport EventEmitter from \"eventemitter3\";\nimport { castArray, isPlainObject } from \"lodash\";\nimport { v1 as uuid } from \"uuid\";\nimport { GRAPHQL_BOX, MESSAGE, REQUEST, SUBSCRIBE } from \"../consts\";\nimport logRequest from \"../debug/log-request\";\nimport logSubscription from \"../debug/log-subscription\";\nimport { MessageContext, MessageResponsePayload, PendingResolver, PendingTracker, UserOptions } from \"../defs\";\n\nexport default class WorkerClient {\n private static _getMessageContext({ hasDeferOrStream = false, requestID }: RequestContext): MessageContext {\n return { hasDeferOrStream, requestID };\n }\n\n private _cache: WorkerCachemap;\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: TypeError[] = [];\n\n if (!isPlainObject(options)) {\n errors.push(new TypeError(\"@graphql-box/client expected options to ba a plain object.\"));\n }\n\n if (!options.cache) {\n errors.push(new TypeError(\"@graphql-box/client expected options.cache.\"));\n }\n\n if (!options.worker) {\n errors.push(new TypeError(\"@graphql-box/client expected options.worker.\"));\n }\n\n if (errors.length) {\n throw errors;\n }\n\n this._cache = options.cache;\n this._debugManager = options.debugManager ?? 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(): WorkerCachemap {\n return this._cache;\n }\n\n public async mutate(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(MUTATION, request, context));\n }\n\n public async query(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async request(request: string, options: RequestOptions = {}, context: MaybeRequestContext = {}) {\n return this._request(request, options, this._getRequestContext(QUERY, request, context));\n }\n\n public async subscribe(request: string, options: RequestOptions = {}) {\n return this._subscribe(request, options, this._getRequestContext(SUBSCRIPTION, request));\n }\n\n private _addEventListener(): void {\n this._worker.addEventListener(MESSAGE, this._onMessage);\n }\n\n private _getRequestContext(\n operation: ValidOperations,\n request: string,\n context: MaybeRequestContext = {},\n ): RequestContext {\n return {\n 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 _onMessage = async ({ data }: MessageEvent): Promise<void> => {\n if (!isPlainObject(data)) {\n return;\n }\n\n const { context, method, result, type } = data as MessageResponsePayload;\n\n if (type !== GRAPHQL_BOX || !isPlainObject(result)) {\n return;\n }\n\n const { _cacheMetadata, ...otherProps } = result;\n const response: MaybeRequestResult = deserializeErrors({ ...otherProps, requestID: context.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<MaybeRequestResult>(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 @logRequest()\n private async _request(request: string, options: RequestOptions, context: RequestContext) {\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 return { errors: castArray(error) };\n }\n }\n\n @logSubscription()\n private async _subscribe(request: string, options: RequestOptions, context: RequestContext) {\n try {\n this._worker.postMessage({\n context: WorkerClient._getMessageContext(context),\n method: SUBSCRIBE,\n options,\n request,\n type: GRAPHQL_BOX,\n });\n\n const eventAsyncIterator = new EventAsyncIterator<MaybeRequestResult>(this._eventEmitter, context.requestID);\n return eventAsyncIterator.getIterator();\n } catch (error) {\n return { errors: castArray(error) };\n }\n }\n}\n"],"file":"index.mjs"}
|