@graphql-mesh/utils 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420220344-25b6b92bf
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/cjs/apply-transforms.js +35 -0
- package/cjs/defaultImportFn.js +57 -0
- package/cjs/extract-resolvers.js +23 -0
- package/cjs/fileURLToPath.js +50 -0
- package/cjs/fs-operations.js +65 -0
- package/cjs/getHeadersObj.js +61 -0
- package/cjs/global-lru-cache.js +9 -0
- package/cjs/group-transforms.js +17 -0
- package/cjs/index.js +20 -0
- package/cjs/load-from-module-export-expression.js +29 -0
- package/cjs/logger.js +127 -0
- package/cjs/package.json +1 -0
- package/cjs/parseAndPrintWithCache.js +42 -0
- package/cjs/pubsub.js +57 -0
- package/cjs/read-file-or-url.js +132 -0
- package/cjs/resolve-additional-resolvers.js +350 -0
- package/cjs/sanitize-name-for-graphql.js +96 -0
- package/cjs/with-cancel.js +34 -0
- package/cjs/with-cookies.js +18 -0
- package/cjs/with-filter.js +53 -0
- package/esm/apply-transforms.js +29 -0
- package/esm/defaultImportFn.js +32 -0
- package/esm/extract-resolvers.js +19 -0
- package/esm/fileURLToPath.js +46 -0
- package/esm/fs-operations.js +57 -0
- package/esm/getHeadersObj.js +57 -0
- package/esm/global-lru-cache.js +4 -0
- package/esm/group-transforms.js +13 -0
- package/esm/index.js +17 -0
- package/esm/load-from-module-export-expression.js +25 -0
- package/esm/logger.js +118 -0
- package/esm/parseAndPrintWithCache.js +37 -0
- package/esm/pubsub.js +53 -0
- package/esm/read-file-or-url.js +124 -0
- package/esm/resolve-additional-resolvers.js +344 -0
- package/esm/sanitize-name-for-graphql.js +91 -0
- package/esm/with-cancel.js +30 -0
- package/esm/with-cookies.js +14 -0
- package/esm/with-filter.js +49 -0
- package/package.json +28 -23
- package/typings/apply-transforms.d.cts +6 -0
- package/{apply-transforms.d.ts → typings/apply-transforms.d.ts} +3 -3
- package/typings/defaultImportFn.d.cts +2 -0
- package/typings/defaultImportFn.d.ts +2 -0
- package/typings/extract-resolvers.d.ts +2 -0
- package/typings/fileURLToPath.d.ts +1 -0
- package/typings/fs-operations.d.ts +7 -0
- package/typings/getHeadersObj.d.cts +1 -0
- package/typings/getHeadersObj.d.ts +1 -0
- package/typings/global-lru-cache.d.cts +3 -0
- package/{global-lru-cache.d.ts → typings/global-lru-cache.d.ts} +2 -2
- package/typings/group-transforms.d.ts +5 -0
- package/typings/index.d.cts +17 -0
- package/typings/index.d.ts +17 -0
- package/typings/load-from-module-export-expression.d.cts +8 -0
- package/{load-from-module-export-expression.d.ts → typings/load-from-module-export-expression.d.ts} +1 -1
- package/typings/logger.d.cts +22 -0
- package/{logger.d.ts → typings/logger.d.ts} +1 -1
- package/typings/parseAndPrintWithCache.d.ts +4 -0
- package/typings/pubsub.d.cts +13 -0
- package/{pubsub.d.ts → typings/pubsub.d.ts} +3 -2
- package/typings/read-file-or-url.d.cts +14 -0
- package/{read-file-or-url.d.ts → typings/read-file-or-url.d.ts} +3 -3
- package/typings/resolve-additional-resolvers.d.cts +4 -0
- package/{resolve-additional-resolvers.d.ts → typings/resolve-additional-resolvers.d.ts} +1 -1
- package/typings/sanitize-name-for-graphql.d.cts +2 -0
- package/{sanitize-name-for-graphql.d.ts → typings/sanitize-name-for-graphql.d.ts} +1 -0
- package/typings/with-cancel.d.cts +1 -0
- package/typings/with-cancel.d.ts +1 -0
- package/typings/with-cookies.d.cts +3 -0
- package/typings/with-cookies.d.ts +3 -0
- package/typings/with-filter.d.cts +4 -0
- package/typings/with-filter.d.ts +4 -0
- package/defaultImportFn.d.ts +0 -1
- package/getHeadersObj.d.ts +0 -1
- package/index.d.ts +0 -16
- package/index.js +0 -1112
- package/index.mjs +0 -1054
- package/with-cancel.d.ts +0 -1
- package/with-filter.d.ts +0 -4
- /package/{extract-resolvers.d.ts → typings/extract-resolvers.d.cts} +0 -0
- /package/{fileURLToPath.d.ts → typings/fileURLToPath.d.cts} +0 -0
- /package/{fs-operations.d.ts → typings/fs-operations.d.cts} +0 -0
- /package/{group-transforms.d.ts → typings/group-transforms.d.cts} +0 -0
- /package/{parseAndPrintWithCache.d.ts → typings/parseAndPrintWithCache.d.cts} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyResultTransforms = exports.applyRequestTransforms = exports.applySchemaTransforms = void 0;
|
|
4
|
+
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, transforms) {
|
|
5
|
+
if (transforms === null || transforms === void 0 ? void 0 : transforms.length) {
|
|
6
|
+
return transforms.reduce((schema, transform) => 'transformSchema' in transform
|
|
7
|
+
? transform.transformSchema(schema, subschemaConfig)
|
|
8
|
+
: schema, originalWrappingSchema);
|
|
9
|
+
}
|
|
10
|
+
return originalWrappingSchema;
|
|
11
|
+
}
|
|
12
|
+
exports.applySchemaTransforms = applySchemaTransforms;
|
|
13
|
+
function applyRequestTransforms(originalRequest, delegationContext, transformationContext, transforms) {
|
|
14
|
+
transformationContext.contextMap = transformationContext.contextMap || new WeakMap();
|
|
15
|
+
const contextMap = transformationContext.contextMap;
|
|
16
|
+
transforms === null || transforms === void 0 ? void 0 : transforms.forEach(transform => {
|
|
17
|
+
if (!contextMap.has(transform)) {
|
|
18
|
+
contextMap.set(transform, {
|
|
19
|
+
nextIndex: 0,
|
|
20
|
+
paths: {},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return transforms.reduceRight((request, transform) => 'transformRequest' in transform
|
|
25
|
+
? transform.transformRequest(request, delegationContext, contextMap.get(transform))
|
|
26
|
+
: request, originalRequest);
|
|
27
|
+
}
|
|
28
|
+
exports.applyRequestTransforms = applyRequestTransforms;
|
|
29
|
+
function applyResultTransforms(originalResult, delegationContext, transformationContext, transforms) {
|
|
30
|
+
const contextMap = transformationContext.contextMap;
|
|
31
|
+
return transforms.reduce((result, transform) => 'transformResult' in transform
|
|
32
|
+
? transform.transformResult(result, delegationContext, contextMap.get(transform))
|
|
33
|
+
: result, originalResult);
|
|
34
|
+
}
|
|
35
|
+
exports.applyResultTransforms = applyResultTransforms;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.defaultImportFn = void 0;
|
|
27
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
28
|
+
async function defaultImportFn(path) {
|
|
29
|
+
let module = await Promise.resolve(`${path}`).then(s => __importStar(require(s))).catch(e => {
|
|
30
|
+
if (e.code === 'ERR_REQUIRE_ESM') {
|
|
31
|
+
// eslint-disable-next-line no-new-func
|
|
32
|
+
return new Function(`return import(${JSON.stringify(path)})`)();
|
|
33
|
+
}
|
|
34
|
+
throw e;
|
|
35
|
+
})
|
|
36
|
+
.catch(e => {
|
|
37
|
+
if (cross_helpers_1.path.isAbsolute(path) && !path.endsWith('.js') && !path.endsWith('.ts')) {
|
|
38
|
+
return defaultImportFn(`${path}.ts`);
|
|
39
|
+
}
|
|
40
|
+
throw e;
|
|
41
|
+
});
|
|
42
|
+
if (module.default != null) {
|
|
43
|
+
module = module.default;
|
|
44
|
+
}
|
|
45
|
+
if (typeof module === 'object' && module != null) {
|
|
46
|
+
const prototypeOfObject = Object.getPrototypeOf(module);
|
|
47
|
+
if (prototypeOfObject == null || prototypeOfObject === Object.prototype) {
|
|
48
|
+
const normalizedVal = {};
|
|
49
|
+
for (const key in module) {
|
|
50
|
+
normalizedVal[key] = module[key];
|
|
51
|
+
}
|
|
52
|
+
return normalizedVal;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return module;
|
|
56
|
+
}
|
|
57
|
+
exports.defaultImportFn = defaultImportFn;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractResolvers = void 0;
|
|
4
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
5
|
+
function extractResolvers(schema) {
|
|
6
|
+
const allResolvers = (0, utils_1.getResolversFromSchema)(schema);
|
|
7
|
+
const filteredResolvers = {};
|
|
8
|
+
for (const prop in allResolvers) {
|
|
9
|
+
if (!prop.startsWith('_')) {
|
|
10
|
+
filteredResolvers[prop] = allResolvers[prop];
|
|
11
|
+
}
|
|
12
|
+
if (typeof filteredResolvers === 'object') {
|
|
13
|
+
for (const fieldName in filteredResolvers[prop]) {
|
|
14
|
+
if (!prop.startsWith('_resolveType')) {
|
|
15
|
+
filteredResolvers[prop][fieldName] =
|
|
16
|
+
allResolvers[prop][fieldName];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return filteredResolvers;
|
|
22
|
+
}
|
|
23
|
+
exports.extractResolvers = extractResolvers;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fileURLToPath = void 0;
|
|
4
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
5
|
+
function fileUriToPath(uri) {
|
|
6
|
+
if (typeof uri !== 'string' || uri.length <= 7 || uri.substring(0, 7) !== 'file://') {
|
|
7
|
+
throw new TypeError('must pass in a file:// URI to convert to a file path');
|
|
8
|
+
}
|
|
9
|
+
const rest = decodeURI(uri.substring(7));
|
|
10
|
+
const firstSlash = rest.indexOf('/');
|
|
11
|
+
let host = rest.substring(0, firstSlash);
|
|
12
|
+
let path = rest.substring(firstSlash + 1);
|
|
13
|
+
// 2. Scheme Definition
|
|
14
|
+
// As a special case, <host> can be the string "localhost" or the empty
|
|
15
|
+
// string; this is interpreted as "the machine from which the URL is
|
|
16
|
+
// being interpreted".
|
|
17
|
+
if (host === 'localhost') {
|
|
18
|
+
host = '';
|
|
19
|
+
}
|
|
20
|
+
if (host) {
|
|
21
|
+
host = cross_helpers_1.path.sep + cross_helpers_1.path.sep + host;
|
|
22
|
+
}
|
|
23
|
+
// 3.2 Drives, drive letters, mount points, file system root
|
|
24
|
+
// Drive letters are mapped into the top of a file URI in various ways,
|
|
25
|
+
// depending on the implementation; some applications substitute
|
|
26
|
+
// vertical bar ("|") for the colon after the drive letter, yielding
|
|
27
|
+
// "file:///c|/tmp/test.txt". In some cases, the colon is left
|
|
28
|
+
// unchanged, as in "file:///c:/tmp/test.txt". In other cases, the
|
|
29
|
+
// colon is simply omitted, as in "file:///c/tmp/test.txt".
|
|
30
|
+
path = path.replace(/^(.+)\|/, '$1:');
|
|
31
|
+
// for Windows, we need to invert the path separators from what a URI uses
|
|
32
|
+
if (cross_helpers_1.path.sep === '\\') {
|
|
33
|
+
path = path.replace(/\//g, '\\');
|
|
34
|
+
}
|
|
35
|
+
if (/^.+:/.test(path)) {
|
|
36
|
+
// has Windows drive at beginning of path
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// unix path…
|
|
40
|
+
path = cross_helpers_1.path.sep + path;
|
|
41
|
+
}
|
|
42
|
+
return host + path;
|
|
43
|
+
}
|
|
44
|
+
function fileURLToPath(url) {
|
|
45
|
+
if (url === null || url === void 0 ? void 0 : url.startsWith('file://')) {
|
|
46
|
+
return fileUriToPath(url);
|
|
47
|
+
}
|
|
48
|
+
return url || '';
|
|
49
|
+
}
|
|
50
|
+
exports.fileURLToPath = fileURLToPath;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rmdirs = exports.mkdir = exports.writeFile = exports.writeJSON = exports.pathExists = void 0;
|
|
4
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
5
|
+
async function pathExists(path) {
|
|
6
|
+
if (!path) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
await cross_helpers_1.fs.promises.stat(path);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
if (e.toString().includes('ENOENT')) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
throw e;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.pathExists = pathExists;
|
|
23
|
+
function writeJSON(path, data, replacer, space) {
|
|
24
|
+
const stringified = JSON.stringify(data, replacer, space);
|
|
25
|
+
return (0, exports.writeFile)(path, stringified, 'utf-8');
|
|
26
|
+
}
|
|
27
|
+
exports.writeJSON = writeJSON;
|
|
28
|
+
const writeFile = async (path, ...args) => {
|
|
29
|
+
if (typeof path === 'string') {
|
|
30
|
+
const containingDir = cross_helpers_1.path.dirname(path);
|
|
31
|
+
if (!(await pathExists(containingDir))) {
|
|
32
|
+
await mkdir(containingDir);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return cross_helpers_1.fs.promises.writeFile(path, ...args);
|
|
36
|
+
};
|
|
37
|
+
exports.writeFile = writeFile;
|
|
38
|
+
async function mkdir(path, options = { recursive: true }) {
|
|
39
|
+
const ifExists = await pathExists(path);
|
|
40
|
+
if (!ifExists) {
|
|
41
|
+
await cross_helpers_1.fs.promises.mkdir(path, options);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.mkdir = mkdir;
|
|
45
|
+
async function rmdirs(dir) {
|
|
46
|
+
if (await pathExists(dir)) {
|
|
47
|
+
const entries = await cross_helpers_1.fs.promises.readdir(dir, { withFileTypes: true });
|
|
48
|
+
const results = await Promise.allSettled(entries.map(entry => {
|
|
49
|
+
const fullPath = cross_helpers_1.path.join(dir, entry.name);
|
|
50
|
+
if (entry.isDirectory()) {
|
|
51
|
+
return rmdirs(fullPath);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return cross_helpers_1.fs.promises.unlink(fullPath);
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
for (const result of results) {
|
|
58
|
+
if (result.status === 'rejected' && result.reason.code !== 'ENOENT') {
|
|
59
|
+
throw result.reason;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await cross_helpers_1.fs.promises.rmdir(dir);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.rmdirs = rmdirs;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHeadersObj = void 0;
|
|
4
|
+
function headersToJSON(headers) {
|
|
5
|
+
return Object.fromEntries(headers.entries());
|
|
6
|
+
}
|
|
7
|
+
function isHeaders(headers) {
|
|
8
|
+
return headers != null && 'get' in headers && typeof headers.get === 'function';
|
|
9
|
+
}
|
|
10
|
+
function getHeadersObj(headers) {
|
|
11
|
+
if (headers == null || !isHeaders(headers)) {
|
|
12
|
+
return headers;
|
|
13
|
+
}
|
|
14
|
+
return new Proxy({}, {
|
|
15
|
+
get(_target, name) {
|
|
16
|
+
if (name === 'toJSON') {
|
|
17
|
+
return () => headersToJSON(headers);
|
|
18
|
+
}
|
|
19
|
+
return headers.get(name.toString().toLowerCase()) || undefined;
|
|
20
|
+
},
|
|
21
|
+
has(_target, name) {
|
|
22
|
+
if (name === 'toJSON') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return headers.has(name.toString().toLowerCase());
|
|
26
|
+
},
|
|
27
|
+
ownKeys(_target) {
|
|
28
|
+
return [...headers.keys()];
|
|
29
|
+
},
|
|
30
|
+
set(_target, name, value) {
|
|
31
|
+
headers.set(name.toString().toLowerCase(), value);
|
|
32
|
+
return true;
|
|
33
|
+
},
|
|
34
|
+
defineProperty(_target, name, descriptor) {
|
|
35
|
+
if (descriptor.value != null) {
|
|
36
|
+
headers.set(name.toString().toLowerCase(), descriptor.value);
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
getOwnPropertyDescriptor(_target, name) {
|
|
41
|
+
const value = headers.get(name.toString().toLowerCase());
|
|
42
|
+
if (value == null) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
configurable: true,
|
|
47
|
+
enumerable: true,
|
|
48
|
+
value,
|
|
49
|
+
writable: true,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
deleteProperty(_target, name) {
|
|
53
|
+
headers.delete(name.toString().toLowerCase());
|
|
54
|
+
return true;
|
|
55
|
+
},
|
|
56
|
+
preventExtensions() {
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.getHeadersObj = getHeadersObj;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLruCache = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tiny_lru_1 = tslib_1.__importDefault(require("tiny-lru"));
|
|
6
|
+
function createLruCache(max, ttl) {
|
|
7
|
+
return (0, tiny_lru_1.default)(max, ttl);
|
|
8
|
+
}
|
|
9
|
+
exports.createLruCache = createLruCache;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupTransforms = void 0;
|
|
4
|
+
function groupTransforms(transforms) {
|
|
5
|
+
const wrapTransforms = [];
|
|
6
|
+
const noWrapTransforms = [];
|
|
7
|
+
transforms === null || transforms === void 0 ? void 0 : transforms.forEach(transform => {
|
|
8
|
+
if (transform.noWrap) {
|
|
9
|
+
noWrapTransforms.push(transform);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
wrapTransforms.push(transform);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return { wrapTransforms, noWrapTransforms };
|
|
16
|
+
}
|
|
17
|
+
exports.groupTransforms = groupTransforms;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./read-file-or-url.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./load-from-module-export-expression.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./with-cancel.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./extract-resolvers.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./group-transforms.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./apply-transforms.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./fs-operations.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./global-lru-cache.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./sanitize-name-for-graphql.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./resolve-additional-resolvers.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./logger.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./parseAndPrintWithCache.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./defaultImportFn.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./pubsub.js"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./fileURLToPath.js"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./getHeadersObj.js"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./with-cookies.js"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadFromModuleExportExpression = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/return-await */
|
|
5
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
6
|
+
const defaultImportFn_js_1 = require("./defaultImportFn.js");
|
|
7
|
+
async function loadFromModuleExportExpression(expression, options) {
|
|
8
|
+
if (typeof expression !== 'string') {
|
|
9
|
+
return Promise.resolve(expression);
|
|
10
|
+
}
|
|
11
|
+
const { defaultExportName, cwd, importFn = defaultImportFn_js_1.defaultImportFn } = options || {};
|
|
12
|
+
const [modulePath, exportName = defaultExportName] = expression.split('#');
|
|
13
|
+
const mod = await tryImport(modulePath, cwd, importFn);
|
|
14
|
+
return mod[exportName] || (mod.default && mod.default[exportName]) || mod.default || mod;
|
|
15
|
+
}
|
|
16
|
+
exports.loadFromModuleExportExpression = loadFromModuleExportExpression;
|
|
17
|
+
async function tryImport(modulePath, cwd, importFn) {
|
|
18
|
+
try {
|
|
19
|
+
return await importFn(modulePath);
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
if (!cross_helpers_1.path.isAbsolute(modulePath)) {
|
|
23
|
+
const absoluteModulePath = cross_helpers_1.path.isAbsolute(modulePath)
|
|
24
|
+
? modulePath
|
|
25
|
+
: cross_helpers_1.path.join(cwd, modulePath);
|
|
26
|
+
return importFn(absoluteModulePath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
package/cjs/logger.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultLogger = exports.titleBold = exports.debugColor = exports.errorColor = exports.infoColor = exports.warnColor = void 0;
|
|
4
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
5
|
+
const ANSI_CODES = {
|
|
6
|
+
black: '\x1b[30m',
|
|
7
|
+
red: '\x1b[31m',
|
|
8
|
+
green: '\x1b[32m',
|
|
9
|
+
yellow: '\x1b[33m',
|
|
10
|
+
blue: '\x1b[34m',
|
|
11
|
+
magenta: '\x1b[35m',
|
|
12
|
+
cyan: '\x1b[36m',
|
|
13
|
+
white: '\x1b[37m',
|
|
14
|
+
reset: '\x1b[0m',
|
|
15
|
+
bold: '\x1b[1m',
|
|
16
|
+
orange: '\x1b[48:5:166m',
|
|
17
|
+
};
|
|
18
|
+
const warnColor = msg => ANSI_CODES.orange + msg + ANSI_CODES.reset;
|
|
19
|
+
exports.warnColor = warnColor;
|
|
20
|
+
const infoColor = msg => ANSI_CODES.cyan + msg + ANSI_CODES.reset;
|
|
21
|
+
exports.infoColor = infoColor;
|
|
22
|
+
const errorColor = msg => ANSI_CODES.red + msg + ANSI_CODES.reset;
|
|
23
|
+
exports.errorColor = errorColor;
|
|
24
|
+
const debugColor = msg => ANSI_CODES.magenta + msg + ANSI_CODES.reset;
|
|
25
|
+
exports.debugColor = debugColor;
|
|
26
|
+
const titleBold = msg => ANSI_CODES.bold + msg + ANSI_CODES.reset;
|
|
27
|
+
exports.titleBold = titleBold;
|
|
28
|
+
class DefaultLogger {
|
|
29
|
+
constructor(name) {
|
|
30
|
+
this.name = name;
|
|
31
|
+
}
|
|
32
|
+
getLoggerMessage({ args = [], trim = !this.isDebug }) {
|
|
33
|
+
return args
|
|
34
|
+
.flat(Infinity)
|
|
35
|
+
.map(arg => {
|
|
36
|
+
if (typeof arg === 'string') {
|
|
37
|
+
if (trim && arg.length > 100) {
|
|
38
|
+
return (arg.slice(0, 100) +
|
|
39
|
+
'...' +
|
|
40
|
+
'<Error message is too long. Enable DEBUG=1 to see the full message.>');
|
|
41
|
+
}
|
|
42
|
+
return arg;
|
|
43
|
+
}
|
|
44
|
+
else if (typeof arg === 'object' && (arg === null || arg === void 0 ? void 0 : arg.stack) != null) {
|
|
45
|
+
return arg.stack;
|
|
46
|
+
}
|
|
47
|
+
return cross_helpers_1.util.inspect(arg);
|
|
48
|
+
})
|
|
49
|
+
.join(` `);
|
|
50
|
+
}
|
|
51
|
+
handleLazyMessage({ lazyArgs, trim }) {
|
|
52
|
+
const flattenedArgs = lazyArgs.flat(Infinity).flatMap(arg => {
|
|
53
|
+
if (typeof arg === 'function') {
|
|
54
|
+
return arg();
|
|
55
|
+
}
|
|
56
|
+
return arg;
|
|
57
|
+
});
|
|
58
|
+
return this.getLoggerMessage({
|
|
59
|
+
args: flattenedArgs,
|
|
60
|
+
trim,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
get isDebug() {
|
|
64
|
+
return (cross_helpers_1.process.env.DEBUG === '1' ||
|
|
65
|
+
globalThis.DEBUG === '1' ||
|
|
66
|
+
this.name.includes(cross_helpers_1.process.env.DEBUG || globalThis.DEBUG));
|
|
67
|
+
}
|
|
68
|
+
get prefix() {
|
|
69
|
+
return this.name ? (0, exports.titleBold)(this.name) : ``;
|
|
70
|
+
}
|
|
71
|
+
log(...args) {
|
|
72
|
+
const message = this.getLoggerMessage({
|
|
73
|
+
args,
|
|
74
|
+
});
|
|
75
|
+
return console.log(`${this.prefix} ${message}`);
|
|
76
|
+
}
|
|
77
|
+
warn(...args) {
|
|
78
|
+
const message = this.getLoggerMessage({
|
|
79
|
+
args,
|
|
80
|
+
});
|
|
81
|
+
const fullMessage = `⚠️ ${this.prefix} ${(0, exports.warnColor)(message)}`;
|
|
82
|
+
if (console.warn) {
|
|
83
|
+
console.warn(fullMessage);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log(fullMessage);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
info(...args) {
|
|
90
|
+
const message = this.getLoggerMessage({
|
|
91
|
+
args,
|
|
92
|
+
});
|
|
93
|
+
const fullMessage = `💡 ${this.prefix} ${(0, exports.infoColor)(message)}`;
|
|
94
|
+
if (console.info) {
|
|
95
|
+
console.info(fullMessage);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log(fullMessage);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
error(...args) {
|
|
102
|
+
const message = this.getLoggerMessage({
|
|
103
|
+
args,
|
|
104
|
+
trim: false,
|
|
105
|
+
});
|
|
106
|
+
const fullMessage = `💥 ${this.prefix} ${(0, exports.errorColor)(message)}`;
|
|
107
|
+
console.log(fullMessage);
|
|
108
|
+
}
|
|
109
|
+
debug(...lazyArgs) {
|
|
110
|
+
if (this.isDebug) {
|
|
111
|
+
const message = this.handleLazyMessage({
|
|
112
|
+
lazyArgs,
|
|
113
|
+
});
|
|
114
|
+
const fullMessage = `🐛 ${this.prefix} ${(0, exports.debugColor)(message)}`;
|
|
115
|
+
if (console.debug) {
|
|
116
|
+
console.debug(fullMessage);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log(fullMessage);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
child(name) {
|
|
124
|
+
return new DefaultLogger(this.name ? `${this.name} - ${name}` : name);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.DefaultLogger = DefaultLogger;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gql = exports.printWithCache = exports.parseWithCache = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
+
const global_lru_cache_js_1 = require("./global-lru-cache.js");
|
|
7
|
+
const parseCache = (0, global_lru_cache_js_1.createLruCache)(1000, 3600);
|
|
8
|
+
const printCache = (0, global_lru_cache_js_1.createLruCache)(1000, 3600);
|
|
9
|
+
function parseWithCache(sdl) {
|
|
10
|
+
const trimmedSdl = sdl.trim();
|
|
11
|
+
let document = parseCache.get(trimmedSdl);
|
|
12
|
+
if (!document) {
|
|
13
|
+
document = (0, graphql_1.parse)(trimmedSdl, { noLocation: true });
|
|
14
|
+
parseCache.set(trimmedSdl, document);
|
|
15
|
+
printCache.set(JSON.stringify(document), trimmedSdl);
|
|
16
|
+
}
|
|
17
|
+
return document;
|
|
18
|
+
}
|
|
19
|
+
exports.parseWithCache = parseWithCache;
|
|
20
|
+
exports.printWithCache = (0, utils_1.memoize1)(function printWithCache(document) {
|
|
21
|
+
const stringifedDocumentJson = JSON.stringify(document);
|
|
22
|
+
let sdl = printCache.get(stringifedDocumentJson);
|
|
23
|
+
if (!sdl) {
|
|
24
|
+
sdl = (0, graphql_1.print)(document).trim();
|
|
25
|
+
printCache.set(stringifedDocumentJson, sdl);
|
|
26
|
+
parseCache.set(sdl, document);
|
|
27
|
+
}
|
|
28
|
+
return sdl;
|
|
29
|
+
});
|
|
30
|
+
function gql([sdl], ...args) {
|
|
31
|
+
let result = sdl;
|
|
32
|
+
for (const arg of args || []) {
|
|
33
|
+
if (typeof arg === 'string') {
|
|
34
|
+
result += arg;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
result += (0, exports.printWithCache)(arg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return parseWithCache(result);
|
|
41
|
+
}
|
|
42
|
+
exports.gql = gql;
|
package/cjs/pubsub.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PubSub = void 0;
|
|
4
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
5
|
+
class PubSub {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.subIdListenerMap = new Map();
|
|
8
|
+
this.listenerEventMap = new Map();
|
|
9
|
+
this.eventNameListenersMap = new Map();
|
|
10
|
+
}
|
|
11
|
+
getEventNames() {
|
|
12
|
+
return this.eventNameListenersMap.keys();
|
|
13
|
+
}
|
|
14
|
+
publish(triggerName, detail) {
|
|
15
|
+
const eventNameListeners = this.eventNameListenersMap.get(triggerName);
|
|
16
|
+
if (eventNameListeners) {
|
|
17
|
+
Promise.allSettled([...eventNameListeners].map(listener => listener(detail))).catch(e => console.error(e));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
subscribe(triggerName, onMessage) {
|
|
21
|
+
let eventNameListeners = this.eventNameListenersMap.get(triggerName);
|
|
22
|
+
if (!eventNameListeners) {
|
|
23
|
+
eventNameListeners = new Set();
|
|
24
|
+
this.eventNameListenersMap.set(triggerName, eventNameListeners);
|
|
25
|
+
}
|
|
26
|
+
const subId = Date.now();
|
|
27
|
+
eventNameListeners.add(onMessage);
|
|
28
|
+
this.subIdListenerMap.set(subId, onMessage);
|
|
29
|
+
this.listenerEventMap.set(onMessage, triggerName);
|
|
30
|
+
return subId;
|
|
31
|
+
}
|
|
32
|
+
unsubscribe(subId) {
|
|
33
|
+
const listener = this.subIdListenerMap.get(subId);
|
|
34
|
+
if (listener) {
|
|
35
|
+
this.subIdListenerMap.delete(subId);
|
|
36
|
+
const eventName = this.listenerEventMap.get(listener);
|
|
37
|
+
if (eventName) {
|
|
38
|
+
const eventNameListeners = this.eventNameListenersMap.get(eventName);
|
|
39
|
+
if (eventNameListeners) {
|
|
40
|
+
eventNameListeners.delete(listener);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.listenerEventMap.delete(listener);
|
|
45
|
+
}
|
|
46
|
+
asyncIterator(triggerName) {
|
|
47
|
+
return (0, utils_1.observableToAsyncIterable)({
|
|
48
|
+
subscribe: observer => {
|
|
49
|
+
const subId = this.subscribe(triggerName, data => observer.next(data));
|
|
50
|
+
return {
|
|
51
|
+
unsubscribe: () => this.unsubscribe(subId),
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.PubSub = PubSub;
|