@graphql-box/worker-client 4.1.5 → 5.0.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/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.js +0 -6
- package/lib/module/consts/index.js.map +0 -1
- package/lib/module/debug/log-request/index.js +0 -64
- package/lib/module/debug/log-request/index.js.map +0 -1
- package/lib/module/debug/log-subscription/index.js +0 -43
- package/lib/module/debug/log-subscription/index.js.map +0 -1
- package/lib/module/defs/index.js +0 -2
- package/lib/module/defs/index.js.map +0 -1
- package/lib/module/helpers/operationNameRegex.js +0 -5
- package/lib/module/helpers/operationNameRegex.js.map +0 -1
- package/lib/module/index.js +0 -4
- package/lib/module/index.js.map +0 -1
- package/lib/module/main/index.js +0 -236
- package/lib/module/main/index.js.map +0 -1
- package/lib/module/register-worker/index.js +0 -126
- package/lib/module/register-worker/index.js.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,81 +0,0 @@
|
|
|
1
|
-
-----------------------------
|
|
2
|
-
Rollup File Analysis
|
|
3
|
-
-----------------------------
|
|
4
|
-
bundle size: 32.23 KB
|
|
5
|
-
original size: 14.626 KB
|
|
6
|
-
code reduction: 0 %
|
|
7
|
-
module count: 8
|
|
8
|
-
|
|
9
|
-
███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
10
|
-
file: /src/main/index.ts
|
|
11
|
-
bundle space: 47.21 %
|
|
12
|
-
rendered size: 15.217 KB
|
|
13
|
-
original size: 6.368 KB
|
|
14
|
-
code reduction: 0 %
|
|
15
|
-
dependents: 1
|
|
16
|
-
- /src/index.ts
|
|
17
|
-
|
|
18
|
-
█████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
19
|
-
file: /src/register-worker/index.ts
|
|
20
|
-
bundle space: 19.75 %
|
|
21
|
-
rendered size: 6.366 KB
|
|
22
|
-
original size: 3.377 KB
|
|
23
|
-
code reduction: 0 %
|
|
24
|
-
dependents: 1
|
|
25
|
-
- /src/index.ts
|
|
26
|
-
|
|
27
|
-
████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
28
|
-
file: /src/debug/log-request/index.ts
|
|
29
|
-
bundle space: 17.68 %
|
|
30
|
-
rendered size: 5.698 KB
|
|
31
|
-
original size: 1.762 KB
|
|
32
|
-
code reduction: 0 %
|
|
33
|
-
dependents: 1
|
|
34
|
-
- /src/main/index.ts
|
|
35
|
-
|
|
36
|
-
███████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
37
|
-
file: /src/debug/log-subscription/index.ts
|
|
38
|
-
bundle space: 14.42 %
|
|
39
|
-
rendered size: 4.647 KB
|
|
40
|
-
original size: 1.274 KB
|
|
41
|
-
code reduction: 0 %
|
|
42
|
-
dependents: 1
|
|
43
|
-
- /src/main/index.ts
|
|
44
|
-
|
|
45
|
-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
46
|
-
file: /src/helpers/operationNameRegex.ts
|
|
47
|
-
bundle space: 0.51 %
|
|
48
|
-
rendered size: 165 Bytes
|
|
49
|
-
original size: 158 Bytes
|
|
50
|
-
code reduction: 0 %
|
|
51
|
-
dependents: 2
|
|
52
|
-
- /src/debug/log-request/index.ts
|
|
53
|
-
- /src/debug/log-subscription/index.ts
|
|
54
|
-
|
|
55
|
-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
56
|
-
file: /src/consts/index.ts
|
|
57
|
-
bundle space: 0.43 %
|
|
58
|
-
rendered size: 137 Bytes
|
|
59
|
-
original size: 185 Bytes
|
|
60
|
-
code reduction: 25.95 %
|
|
61
|
-
dependents: 2
|
|
62
|
-
- /src/main/index.ts
|
|
63
|
-
- /src/register-worker/index.ts
|
|
64
|
-
|
|
65
|
-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
66
|
-
file: /src/defs/index.ts
|
|
67
|
-
bundle space: 0 %
|
|
68
|
-
rendered size: 0 Byte
|
|
69
|
-
original size: 1.381 KB
|
|
70
|
-
code reduction: 100 %
|
|
71
|
-
dependents: 1
|
|
72
|
-
- /src/index.ts
|
|
73
|
-
|
|
74
|
-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
75
|
-
file: /src/index.ts
|
|
76
|
-
bundle space: 0 %
|
|
77
|
-
rendered size: 0 Byte
|
|
78
|
-
original size: 121 Bytes
|
|
79
|
-
code reduction: 100 %
|
|
80
|
-
dependents: 0
|
|
81
|
-
|
package/lib/main/consts/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CACHEMAP = exports.GRAPHQL_BOX = exports.MESSAGE = exports.SUBSCRIBE = exports.REQUEST = void 0;
|
|
7
|
-
const REQUEST = "request";
|
|
8
|
-
exports.REQUEST = REQUEST;
|
|
9
|
-
const SUBSCRIBE = "subscribe";
|
|
10
|
-
exports.SUBSCRIBE = SUBSCRIBE;
|
|
11
|
-
const MESSAGE = "message";
|
|
12
|
-
exports.MESSAGE = MESSAGE;
|
|
13
|
-
const GRAPHQL_BOX = "graphqlBox";
|
|
14
|
-
exports.GRAPHQL_BOX = GRAPHQL_BOX;
|
|
15
|
-
const CACHEMAP = "cachemap";
|
|
16
|
-
exports.CACHEMAP = CACHEMAP;
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/consts/index.ts"],"names":["REQUEST","SUBSCRIBE","MESSAGE","GRAPHQL_BOX","CACHEMAP"],"mappings":";;;;;;AAAO,MAAMA,OAAO,GAAG,SAAhB;;AACA,MAAMC,SAAS,GAAG,WAAlB;;AAEA,MAAMC,OAAO,GAAG,SAAhB;;AAEA,MAAMC,WAAW,GAAG,YAApB;;AACA,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.js"}
|
|
@@ -1,77 +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.default = logRequest;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.promise.js");
|
|
11
|
-
|
|
12
|
-
var _core = require("@graphql-box/core");
|
|
13
|
-
|
|
14
|
-
var _iterall = require("iterall");
|
|
15
|
-
|
|
16
|
-
var _operationNameRegex = _interopRequireDefault(require("../../helpers/operationNameRegex"));
|
|
17
|
-
|
|
18
|
-
function logRequest() {
|
|
19
|
-
return (_target, _propertyName, descriptor) => {
|
|
20
|
-
const method = descriptor.value;
|
|
21
|
-
if (!method) return;
|
|
22
|
-
|
|
23
|
-
descriptor.value = async function descriptorValue(...args) {
|
|
24
|
-
try {
|
|
25
|
-
return new Promise(async resolve => {
|
|
26
|
-
const {
|
|
27
|
-
debugManager,
|
|
28
|
-
...otherContext
|
|
29
|
-
} = args[2];
|
|
30
|
-
|
|
31
|
-
if (!debugManager) {
|
|
32
|
-
resolve(await method.apply(this, args));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const derivedOperationName = (0, _operationNameRegex.default)(args[0]);
|
|
37
|
-
const startTime = debugManager.now();
|
|
38
|
-
debugManager.log(_core.REQUEST_EXECUTED, {
|
|
39
|
-
context: { ...otherContext,
|
|
40
|
-
operationName: derivedOperationName
|
|
41
|
-
},
|
|
42
|
-
options: args[1],
|
|
43
|
-
request: args[0],
|
|
44
|
-
stats: {
|
|
45
|
-
startTime
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
const result = await method.apply(this, args);
|
|
49
|
-
const endTime = debugManager.now();
|
|
50
|
-
const duration = endTime - startTime;
|
|
51
|
-
resolve(result);
|
|
52
|
-
|
|
53
|
-
if ((0, _iterall.isAsyncIterable)(result)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
debugManager.log(_core.REQUEST_RESOLVED, {
|
|
58
|
-
context: { ...otherContext,
|
|
59
|
-
operationName: derivedOperationName
|
|
60
|
-
},
|
|
61
|
-
options: args[1],
|
|
62
|
-
request: args[0],
|
|
63
|
-
result,
|
|
64
|
-
stats: {
|
|
65
|
-
duration,
|
|
66
|
-
endTime,
|
|
67
|
-
startTime
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
} catch (error) {
|
|
72
|
-
return Promise.reject(error);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/debug/log-request/index.ts"],"names":["logRequest","_target","_propertyName","descriptor","method","value","descriptorValue","args","Promise","resolve","debugManager","otherContext","apply","derivedOperationName","startTime","now","log","REQUEST_EXECUTED","context","operationName","options","request","stats","result","endTime","duration","REQUEST_RESOLVED","error","reject"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEe,SAASA,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,GAAG,iCAAmBN,IAAI,CAAC,CAAD,CAAvB,CAA7B;AACA,gBAAMO,SAAS,GAAGJ,YAAY,CAACK,GAAb,EAAlB;AAEAL,UAAAA,YAAY,CAACM,GAAb,CAAiBC,sBAAjB,EAAmC;AACjCC,YAAAA,OAAO,EAAE,EAAE,GAAGP,YAAL;AAAmBQ,cAAAA,aAAa,EAAEN;AAAlC,aADwB;AAEjCO,YAAAA,OAAO,EAAEb,IAAI,CAAC,CAAD,CAFoB;AAGjCc,YAAAA,OAAO,EAAEd,IAAI,CAAC,CAAD,CAHoB;AAIjCe,YAAAA,KAAK,EAAE;AAAER,cAAAA;AAAF;AAJ0B,WAAnC;AAOA,gBAAMS,MAAM,GAAG,MAAMnB,MAAM,CAACQ,KAAP,CAAa,IAAb,EAAmBL,IAAnB,CAArB;AACA,gBAAMiB,OAAO,GAAGd,YAAY,CAACK,GAAb,EAAhB;AACA,gBAAMU,QAAQ,GAAGD,OAAO,GAAGV,SAA3B;AACAL,UAAAA,OAAO,CAACc,MAAD,CAAP;;AAEA,cAAI,8BAAgBA,MAAhB,CAAJ,EAA6B;AAC3B;AACD;;AAEDb,UAAAA,YAAY,CAACM,GAAb,CAAiBU,sBAAjB,EAAmC;AACjCR,YAAAA,OAAO,EAAE,EAAE,GAAGP,YAAL;AAAmBQ,cAAAA,aAAa,EAAEN;AAAlC,aADwB;AAEjCO,YAAAA,OAAO,EAAEb,IAAI,CAAC,CAAD,CAFoB;AAGjCc,YAAAA,OAAO,EAAEd,IAAI,CAAC,CAAD,CAHoB;AAIjCgB,YAAAA,MAJiC;AAKjCD,YAAAA,KAAK,EAAE;AAAEG,cAAAA,QAAF;AAAYD,cAAAA,OAAZ;AAAqBV,cAAAA;AAArB;AAL0B,WAAnC;AAOD,SAlCM,CAAP;AAmCD,OApCD,CAoCE,OAAOa,KAAP,EAAc;AACd,eAAOnB,OAAO,CAACoB,MAAR,CAAeD,KAAf,CAAP;AACD;AACF,KAxCD;AAyCD,GAjDD;AAkDD","sourcesContent":["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.js"}
|
|
@@ -1,55 +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.default = logSubscription;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.promise.js");
|
|
11
|
-
|
|
12
|
-
var _core = require("@graphql-box/core");
|
|
13
|
-
|
|
14
|
-
var _operationNameRegex = _interopRequireDefault(require("../../helpers/operationNameRegex"));
|
|
15
|
-
|
|
16
|
-
function logSubscription() {
|
|
17
|
-
return (_target, _propertyName, descriptor) => {
|
|
18
|
-
const method = descriptor.value;
|
|
19
|
-
if (!method) return;
|
|
20
|
-
|
|
21
|
-
descriptor.value = async function descriptorValue(...args) {
|
|
22
|
-
try {
|
|
23
|
-
return new Promise(async resolve => {
|
|
24
|
-
const {
|
|
25
|
-
debugManager,
|
|
26
|
-
...otherContext
|
|
27
|
-
} = args[2];
|
|
28
|
-
|
|
29
|
-
if (!debugManager) {
|
|
30
|
-
resolve(await method.apply(this, args));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const derivedOperationName = (0, _operationNameRegex.default)(args[0]);
|
|
35
|
-
const startTime = debugManager.now();
|
|
36
|
-
debugManager.log(_core.SUBSCRIPTION_EXECUTED, {
|
|
37
|
-
context: { ...otherContext,
|
|
38
|
-
operationName: derivedOperationName
|
|
39
|
-
},
|
|
40
|
-
options: args[1],
|
|
41
|
-
request: args[0],
|
|
42
|
-
stats: {
|
|
43
|
-
startTime
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
const result = await method.apply(this, args);
|
|
47
|
-
resolve(result);
|
|
48
|
-
});
|
|
49
|
-
} catch (error) {
|
|
50
|
-
return Promise.reject(error);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/debug/log-subscription/index.ts"],"names":["logSubscription","_target","_propertyName","descriptor","method","value","descriptorValue","args","Promise","resolve","debugManager","otherContext","apply","derivedOperationName","startTime","now","log","SUBSCRIPTION_EXECUTED","context","operationName","options","request","stats","result","error","reject"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEe,SAASA,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,GAAG,iCAAmBN,IAAI,CAAC,CAAD,CAAvB,CAA7B;AACA,gBAAMO,SAAS,GAAGJ,YAAY,CAACK,GAAb,EAAlB;AAEAL,UAAAA,YAAY,CAACM,GAAb,CAAiBC,2BAAjB,EAAwC;AACtCC,YAAAA,OAAO,EAAE,EAAE,GAAGP,YAAL;AAAmBQ,cAAAA,aAAa,EAAEN;AAAlC,aAD6B;AAEtCO,YAAAA,OAAO,EAAEb,IAAI,CAAC,CAAD,CAFyB;AAGtCc,YAAAA,OAAO,EAAEd,IAAI,CAAC,CAAD,CAHyB;AAItCe,YAAAA,KAAK,EAAE;AAAER,cAAAA;AAAF;AAJ+B,WAAxC;AAOA,gBAAMS,MAAM,GAAG,MAAMnB,MAAM,CAACQ,KAAP,CAAa,IAAb,EAAmBL,IAAnB,CAArB;AACAE,UAAAA,OAAO,CAACc,MAAD,CAAP;AACD,SApBM,CAAP;AAqBD,OAtBD,CAsBE,OAAOC,KAAP,EAAc;AACd,eAAOhB,OAAO,CAACiB,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.js"}
|
package/lib/main/defs/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.js"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _default = request => {
|
|
9
|
-
const output = /(query|mutation|subscription) ([A-Za-z]+)(\(| {)/.exec(request);
|
|
10
|
-
return output ? output[2] : "";
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
exports.default = _default;
|
|
14
|
-
//# sourceMappingURL=operationNameRegex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/helpers/operationNameRegex.ts"],"names":["request","output","exec"],"mappings":";;;;;;;eAAgBA,OAAD,IAAqB;AAClC,QAAMC,MAAM,GAAG,mDAAmDC,IAAnD,CAAwDF,OAAxD,CAAf;AACA,SAAOC,MAAM,GAAGA,MAAM,CAAC,CAAD,CAAT,GAAe,EAA5B;AACD,C","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.js"}
|
package/lib/main/index.js
DELETED
|
@@ -1,41 +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
|
-
var _exportNames = {
|
|
9
|
-
registerWorker: true
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "default", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return _main.default;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "registerWorker", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _registerWorker.default;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
var _defs = require("./defs");
|
|
25
|
-
|
|
26
|
-
Object.keys(_defs).forEach(function (key) {
|
|
27
|
-
if (key === "default" || key === "__esModule") return;
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
29
|
-
if (key in exports && exports[key] === _defs[key]) return;
|
|
30
|
-
Object.defineProperty(exports, key, {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _defs[key];
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
var _main = _interopRequireDefault(require("./main"));
|
|
39
|
-
|
|
40
|
-
var _registerWorker = _interopRequireDefault(require("./register-worker"));
|
|
41
|
-
//# sourceMappingURL=index.js.map
|
package/lib/main/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA","sourcesContent":["export * from \"./defs\";\nexport { default } from \"./main\";\nexport { default as registerWorker } from \"./register-worker\";\n"],"file":"index.js"}
|
package/lib/main/main/index.js
DELETED
|
@@ -1,249 +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.default = void 0;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.promise.js");
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
15
|
-
|
|
16
|
-
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
17
|
-
|
|
18
|
-
var _castArray2 = _interopRequireDefault(require("lodash/castArray"));
|
|
19
|
-
|
|
20
|
-
var _core = require("@graphql-box/core");
|
|
21
|
-
|
|
22
|
-
var _helpers = require("@graphql-box/helpers");
|
|
23
|
-
|
|
24
|
-
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
25
|
-
|
|
26
|
-
var _uuid = require("uuid");
|
|
27
|
-
|
|
28
|
-
var _consts = require("../consts");
|
|
29
|
-
|
|
30
|
-
var _logRequest = _interopRequireDefault(require("../debug/log-request"));
|
|
31
|
-
|
|
32
|
-
var _logSubscription = _interopRequireDefault(require("../debug/log-subscription"));
|
|
33
|
-
|
|
34
|
-
var _dec, _dec2, _class;
|
|
35
|
-
|
|
36
|
-
let WorkerClient = (_dec = (0, _logRequest.default)(), _dec2 = (0, _logSubscription.default)(), (_class = class WorkerClient {
|
|
37
|
-
static _getMessageContext({
|
|
38
|
-
hasDeferOrStream = false,
|
|
39
|
-
requestID
|
|
40
|
-
}) {
|
|
41
|
-
return {
|
|
42
|
-
hasDeferOrStream,
|
|
43
|
-
requestID
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
constructor(options) {
|
|
48
|
-
var _options$debugManager, _options$experimental;
|
|
49
|
-
|
|
50
|
-
(0, _defineProperty2.default)(this, "_cache", void 0);
|
|
51
|
-
(0, _defineProperty2.default)(this, "_debugManager", void 0);
|
|
52
|
-
(0, _defineProperty2.default)(this, "_eventEmitter", void 0);
|
|
53
|
-
(0, _defineProperty2.default)(this, "_experimentalDeferStreamSupport", void 0);
|
|
54
|
-
(0, _defineProperty2.default)(this, "_pending", new Map());
|
|
55
|
-
(0, _defineProperty2.default)(this, "_worker", void 0);
|
|
56
|
-
(0, _defineProperty2.default)(this, "_onMessage", async ({
|
|
57
|
-
data
|
|
58
|
-
}) => {
|
|
59
|
-
if (!(0, _isPlainObject2.default)(data)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const {
|
|
64
|
-
context,
|
|
65
|
-
method,
|
|
66
|
-
result,
|
|
67
|
-
type
|
|
68
|
-
} = data;
|
|
69
|
-
|
|
70
|
-
if (type !== _consts.GRAPHQL_BOX || !(0, _isPlainObject2.default)(result)) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const {
|
|
75
|
-
_cacheMetadata,
|
|
76
|
-
...otherProps
|
|
77
|
-
} = result;
|
|
78
|
-
const response = (0, _helpers.deserializeErrors)({ ...otherProps,
|
|
79
|
-
requestID: context.requestID
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (_cacheMetadata) {
|
|
83
|
-
response._cacheMetadata = (0, _helpers.rehydrateCacheMetadata)(_cacheMetadata);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (method === _consts.SUBSCRIBE) {
|
|
87
|
-
var _this$_debugManager, _this$_debugManager2;
|
|
88
|
-
|
|
89
|
-
(_this$_debugManager = this._debugManager) === null || _this$_debugManager === void 0 ? void 0 : _this$_debugManager.log(_core.SUBSCRIPTION_RESOLVED, {
|
|
90
|
-
context,
|
|
91
|
-
result: response,
|
|
92
|
-
stats: {
|
|
93
|
-
endTime: (_this$_debugManager2 = this._debugManager) === null || _this$_debugManager2 === void 0 ? void 0 : _this$_debugManager2.now()
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
this._eventEmitter.emit(context.requestID, response);
|
|
98
|
-
} else if (context.hasDeferOrStream) {
|
|
99
|
-
var _this$_debugManager3, _this$_debugManager4;
|
|
100
|
-
|
|
101
|
-
const pending = this._pending.get(context.requestID);
|
|
102
|
-
|
|
103
|
-
if (pending) {
|
|
104
|
-
const eventAsyncIterator = new _helpers.EventAsyncIterator(this._eventEmitter, context.requestID);
|
|
105
|
-
pending.resolve(eventAsyncIterator.getIterator());
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
(_this$_debugManager3 = this._debugManager) === null || _this$_debugManager3 === void 0 ? void 0 : _this$_debugManager3.log(_core.REQUEST_RESOLVED, {
|
|
109
|
-
context,
|
|
110
|
-
result: response,
|
|
111
|
-
stats: {
|
|
112
|
-
endTime: (_this$_debugManager4 = this._debugManager) === null || _this$_debugManager4 === void 0 ? void 0 : _this$_debugManager4.now()
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
this._eventEmitter.emit(context.requestID, response);
|
|
117
|
-
} else {
|
|
118
|
-
var _this$_debugManager5, _this$_debugManager6;
|
|
119
|
-
|
|
120
|
-
const pending = this._pending.get(context.requestID);
|
|
121
|
-
|
|
122
|
-
if (!pending) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
(_this$_debugManager5 = this._debugManager) === null || _this$_debugManager5 === void 0 ? void 0 : _this$_debugManager5.log(_core.REQUEST_RESOLVED, {
|
|
127
|
-
context,
|
|
128
|
-
result: response,
|
|
129
|
-
stats: {
|
|
130
|
-
endTime: (_this$_debugManager6 = this._debugManager) === null || _this$_debugManager6 === void 0 ? void 0 : _this$_debugManager6.now()
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
pending.resolve(response);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
const errors = [];
|
|
137
|
-
|
|
138
|
-
if (!(0, _isPlainObject2.default)(options)) {
|
|
139
|
-
errors.push(new TypeError("@graphql-box/client expected options to ba a plain object."));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!options.cache) {
|
|
143
|
-
errors.push(new TypeError("@graphql-box/client expected options.cache."));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (!options.worker) {
|
|
147
|
-
errors.push(new TypeError("@graphql-box/client expected options.worker."));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (errors.length) {
|
|
151
|
-
throw errors;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
this._cache = options.cache;
|
|
155
|
-
this._debugManager = (_options$debugManager = options.debugManager) !== null && _options$debugManager !== void 0 ? _options$debugManager : null;
|
|
156
|
-
this._eventEmitter = new _eventemitter.default();
|
|
157
|
-
this._experimentalDeferStreamSupport = (_options$experimental = options.experimentalDeferStreamSupport) !== null && _options$experimental !== void 0 ? _options$experimental : false;
|
|
158
|
-
this._worker = options.worker;
|
|
159
|
-
|
|
160
|
-
this._addEventListener();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
get cache() {
|
|
164
|
-
return this._cache;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async mutate(request, options = {}, context = {}) {
|
|
168
|
-
return this._request(request, options, this._getRequestContext(_core.MUTATION, request, context));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async query(request, options = {}, context = {}) {
|
|
172
|
-
return this._request(request, options, this._getRequestContext(_core.QUERY, request, context));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async request(request, options = {}, context = {}) {
|
|
176
|
-
return this._request(request, options, this._getRequestContext(_core.QUERY, request, context));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async subscribe(request, options = {}) {
|
|
180
|
-
return this._subscribe(request, options, this._getRequestContext(_core.SUBSCRIPTION, request));
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
_addEventListener() {
|
|
184
|
-
this._worker.addEventListener(_consts.MESSAGE, this._onMessage);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
_getRequestContext(operation, request, context = {}) {
|
|
188
|
-
return {
|
|
189
|
-
debugManager: this._debugManager,
|
|
190
|
-
experimentalDeferStreamSupport: this._experimentalDeferStreamSupport,
|
|
191
|
-
fieldTypeMap: new Map(),
|
|
192
|
-
filteredRequest: "",
|
|
193
|
-
operation,
|
|
194
|
-
operationName: "",
|
|
195
|
-
originalRequestHash: (0, _helpers.hashRequest)(request),
|
|
196
|
-
parsedRequest: "",
|
|
197
|
-
queryFiltered: false,
|
|
198
|
-
request,
|
|
199
|
-
requestComplexity: null,
|
|
200
|
-
requestDepth: null,
|
|
201
|
-
requestID: (0, _uuid.v1)(),
|
|
202
|
-
...context
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async _request(request, options, context) {
|
|
207
|
-
try {
|
|
208
|
-
return await new Promise(resolve => {
|
|
209
|
-
this._worker.postMessage({
|
|
210
|
-
context: WorkerClient._getMessageContext(context),
|
|
211
|
-
method: _consts.REQUEST,
|
|
212
|
-
options,
|
|
213
|
-
request,
|
|
214
|
-
type: _consts.GRAPHQL_BOX
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
this._pending.set(context.requestID, {
|
|
218
|
-
resolve
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
} catch (error) {
|
|
222
|
-
return {
|
|
223
|
-
errors: (0, _castArray2.default)(error)
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
async _subscribe(request, options, context) {
|
|
229
|
-
try {
|
|
230
|
-
this._worker.postMessage({
|
|
231
|
-
context: WorkerClient._getMessageContext(context),
|
|
232
|
-
method: _consts.SUBSCRIBE,
|
|
233
|
-
options,
|
|
234
|
-
request,
|
|
235
|
-
type: _consts.GRAPHQL_BOX
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const eventAsyncIterator = new _helpers.EventAsyncIterator(this._eventEmitter, context.requestID);
|
|
239
|
-
return eventAsyncIterator.getIterator();
|
|
240
|
-
} catch (error) {
|
|
241
|
-
return {
|
|
242
|
-
errors: (0, _castArray2.default)(error)
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
}, ((0, _applyDecoratedDescriptor2.default)(_class.prototype, "_request", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "_request"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_subscribe", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "_subscribe"), _class.prototype)), _class));
|
|
248
|
-
exports.default = WorkerClient;
|
|
249
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/main/index.ts"],"names":["WorkerClient","_getMessageContext","hasDeferOrStream","requestID","constructor","options","Map","data","context","method","result","type","GRAPHQL_BOX","_cacheMetadata","otherProps","response","SUBSCRIBE","_debugManager","log","SUBSCRIPTION_RESOLVED","stats","endTime","now","_eventEmitter","emit","pending","_pending","get","eventAsyncIterator","EventAsyncIterator","resolve","getIterator","REQUEST_RESOLVED","errors","push","TypeError","cache","worker","length","_cache","debugManager","EventEmitter","_experimentalDeferStreamSupport","experimentalDeferStreamSupport","_worker","_addEventListener","mutate","request","_request","_getRequestContext","MUTATION","query","QUERY","subscribe","_subscribe","SUBSCRIPTION","addEventListener","MESSAGE","_onMessage","operation","fieldTypeMap","filteredRequest","operationName","originalRequestHash","parsedRequest","queryFiltered","requestComplexity","requestDepth","Promise","postMessage","REQUEST","set","error"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;;AAaA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;IAGqBA,Y,WAgJlB,0B,UAmBA,+B,YAnKY,MAAMA,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,oDAHC,IAAIC,GAAJ,EAGD;AAAA;AAAA,sDA0Eb,OAAO;AAAEC,MAAAA;AAAF,KA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CAACL,SAA1B,EAAqC;AAAE2B,UAAAA;AAAF,SAArC;AACD,OAVY,CAAb;AAWD,KAZD,CAYE,OAAO0C,KAAP,EAAc;AACd,aAAO;AAAEvC,QAAAA,MAAM,EAAE,yBAAUuC,KAAV;AAAV,OAAP;AACD;AACF;;AAGuB,QAAVlB,UAAU,CAACP,OAAD,EAAkB1C,OAAlB,EAA2CG,OAA3C,EAAoE;AAC1F,QAAI;AACF,WAAKoC,OAAL,CAAayB,WAAb,CAAyB;AACvB7D,QAAAA,OAAO,EAAER,YAAY,CAACC,kBAAb,CAAgCO,OAAhC,CADc;AAEvBC,QAAAA,MAAM,EAAEO,iBAFe;AAGvBX,QAAAA,OAHuB;AAIvB0C,QAAAA,OAJuB;AAKvBpC,QAAAA,IAAI,EAAEC;AALiB,OAAzB;;AAQA,YAAMgB,kBAAkB,GAAG,IAAIC,2BAAJ,CAA2C,KAAKN,aAAhD,EAA+Df,OAAO,CAACL,SAAvE,CAA3B;AACA,aAAOyB,kBAAkB,CAACG,WAAnB,EAAP;AACD,KAXD,CAWE,OAAOyC,KAAP,EAAc;AACd,aAAO;AAAEvC,QAAAA,MAAM,EAAE,yBAAUuC,KAAV;AAAV,OAAP;AACD;AACF;;AAnL+B,C","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.js"}
|