@graphql-mesh/utils 0.95.4 → 0.95.5-alpha-20230925214453-9a632b760
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/read-file-or-url.js
CHANGED
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.readUrl = exports.readFile = exports.loadYaml = exports.readFileOrUrl = exports.isUrl = void 0;
|
|
4
4
|
const js_yaml_1 = require("js-yaml");
|
|
5
5
|
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
6
|
+
const fetch_1 = require("@whatwg-node/fetch");
|
|
6
7
|
const load_from_module_export_expression_js_1 = require("./load-from-module-export-expression.js");
|
|
7
8
|
function isUrl(str) {
|
|
8
|
-
return /^https?:\/\//.test(str);
|
|
9
|
+
return /^https?:\/\//.test(str) || /^file:\/\//.test(str);
|
|
9
10
|
}
|
|
10
11
|
exports.isUrl = isUrl;
|
|
11
12
|
async function readFileOrUrl(filePathOrUrl, config) {
|
|
@@ -68,7 +69,7 @@ function loadYaml(filepath, content, logger) {
|
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
exports.loadYaml = loadYaml;
|
|
71
|
-
async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger }) {
|
|
72
|
+
async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger, fetch }) {
|
|
72
73
|
const [filePath] = fileExpression.split('#');
|
|
73
74
|
if (/js$/.test(filePath) || /ts$/.test(filePath)) {
|
|
74
75
|
return (0, load_from_module_export_expression_js_1.loadFromModuleExportExpression)(fileExpression, {
|
|
@@ -78,19 +79,23 @@ async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackF
|
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
const actualPath = cross_helpers_1.path.isAbsolute(filePath) ? filePath : cross_helpers_1.path.join(cwd, filePath);
|
|
81
|
-
const
|
|
82
|
+
const url = new fetch_1.URL(`file:///${actualPath}`);
|
|
83
|
+
const res = await fetch(url.href);
|
|
82
84
|
if (/json$/.test(actualPath)) {
|
|
83
|
-
return
|
|
85
|
+
return res.json();
|
|
84
86
|
}
|
|
85
87
|
if (/yaml$/.test(actualPath) || /yml$/.test(actualPath)) {
|
|
88
|
+
const rawResult = await res.text();
|
|
86
89
|
return loadYaml(actualPath, rawResult, logger);
|
|
87
90
|
}
|
|
88
91
|
else if (fallbackFormat) {
|
|
89
92
|
switch (fallbackFormat) {
|
|
90
93
|
case 'json':
|
|
91
|
-
return
|
|
92
|
-
case 'yaml':
|
|
94
|
+
return res.json();
|
|
95
|
+
case 'yaml': {
|
|
96
|
+
const rawResult = await res.text();
|
|
93
97
|
return loadYaml(actualPath, rawResult, logger);
|
|
98
|
+
}
|
|
94
99
|
case 'ts':
|
|
95
100
|
case 'js':
|
|
96
101
|
return importFn(actualPath);
|
|
@@ -100,7 +105,7 @@ async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackF
|
|
|
100
105
|
throw new Error(`Failed to parse JSON/YAML. Ensure file '${filePath}' has ` +
|
|
101
106
|
`the correct extension (i.e. '.json', '.yaml', or '.yml).`);
|
|
102
107
|
}
|
|
103
|
-
return
|
|
108
|
+
return res.text();
|
|
104
109
|
}
|
|
105
110
|
exports.readFile = readFile;
|
|
106
111
|
async function readUrl(path, config) {
|
package/esm/read-file-or-url.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DEFAULT_SCHEMA, load as loadYamlFromJsYaml, Type } from 'js-yaml';
|
|
2
2
|
import { fs, path as pathModule } from '@graphql-mesh/cross-helpers';
|
|
3
|
+
import { URL } from '@whatwg-node/fetch';
|
|
3
4
|
import { loadFromModuleExportExpression } from './load-from-module-export-expression.js';
|
|
4
5
|
export function isUrl(str) {
|
|
5
|
-
return /^https?:\/\//.test(str);
|
|
6
|
+
return /^https?:\/\//.test(str) || /^file:\/\//.test(str);
|
|
6
7
|
}
|
|
7
8
|
export async function readFileOrUrl(filePathOrUrl, config) {
|
|
8
9
|
if (isUrl(filePathOrUrl)) {
|
|
@@ -62,7 +63,7 @@ export function loadYaml(filepath, content, logger) {
|
|
|
62
63
|
},
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
|
-
export async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger }) {
|
|
66
|
+
export async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger, fetch }) {
|
|
66
67
|
const [filePath] = fileExpression.split('#');
|
|
67
68
|
if (/js$/.test(filePath) || /ts$/.test(filePath)) {
|
|
68
69
|
return loadFromModuleExportExpression(fileExpression, {
|
|
@@ -72,19 +73,23 @@ export async function readFile(fileExpression, { allowUnknownExtensions, cwd, fa
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
const actualPath = pathModule.isAbsolute(filePath) ? filePath : pathModule.join(cwd, filePath);
|
|
75
|
-
const
|
|
76
|
+
const url = new URL(`file:///${actualPath}`);
|
|
77
|
+
const res = await fetch(url.href);
|
|
76
78
|
if (/json$/.test(actualPath)) {
|
|
77
|
-
return
|
|
79
|
+
return res.json();
|
|
78
80
|
}
|
|
79
81
|
if (/yaml$/.test(actualPath) || /yml$/.test(actualPath)) {
|
|
82
|
+
const rawResult = await res.text();
|
|
80
83
|
return loadYaml(actualPath, rawResult, logger);
|
|
81
84
|
}
|
|
82
85
|
else if (fallbackFormat) {
|
|
83
86
|
switch (fallbackFormat) {
|
|
84
87
|
case 'json':
|
|
85
|
-
return
|
|
86
|
-
case 'yaml':
|
|
88
|
+
return res.json();
|
|
89
|
+
case 'yaml': {
|
|
90
|
+
const rawResult = await res.text();
|
|
87
91
|
return loadYaml(actualPath, rawResult, logger);
|
|
92
|
+
}
|
|
88
93
|
case 'ts':
|
|
89
94
|
case 'js':
|
|
90
95
|
return importFn(actualPath);
|
|
@@ -94,7 +99,7 @@ export async function readFile(fileExpression, { allowUnknownExtensions, cwd, fa
|
|
|
94
99
|
throw new Error(`Failed to parse JSON/YAML. Ensure file '${filePath}' has ` +
|
|
95
100
|
`the correct extension (i.e. '.json', '.yaml', or '.yml).`);
|
|
96
101
|
}
|
|
97
|
-
return
|
|
102
|
+
return res.text();
|
|
98
103
|
}
|
|
99
104
|
export async function readUrl(path, config) {
|
|
100
105
|
const { allowUnknownExtensions, fallbackFormat } = config || {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/utils",
|
|
3
|
-
"version": "0.95.
|
|
3
|
+
"version": "0.95.5-alpha-20230925214453-9a632b760",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "
|
|
7
|
-
"@graphql-mesh/types": "
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.1-alpha-20230925214453-9a632b760",
|
|
7
|
+
"@graphql-mesh/types": "0.95.5-alpha-20230925214453-9a632b760",
|
|
8
8
|
"@graphql-tools/utils": "^9.2.1 || ^10.0.0",
|
|
9
9
|
"graphql": "*",
|
|
10
10
|
"tslib": "^2.4.0"
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@graphql-mesh/string-interpolation": "^0.5.1",
|
|
14
14
|
"@graphql-tools/delegate": "^10.0.0",
|
|
15
|
+
"@whatwg-node/fetch": "^0.9.13",
|
|
15
16
|
"dset": "^3.1.2",
|
|
16
17
|
"js-yaml": "^4.1.0",
|
|
17
18
|
"lodash.get": "^4.4.2",
|
|
@@ -10,5 +10,5 @@ export interface ReadFileOrUrlOptions extends MeshFetchRequestInit {
|
|
|
10
10
|
export declare function isUrl(str: string): boolean;
|
|
11
11
|
export declare function readFileOrUrl<T>(filePathOrUrl: string, config: ReadFileOrUrlOptions): Promise<T>;
|
|
12
12
|
export declare function loadYaml(filepath: string, content: string, logger: Logger): any;
|
|
13
|
-
export declare function readFile<T>(fileExpression: string, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger }: ReadFileOrUrlOptions): Promise<T>;
|
|
13
|
+
export declare function readFile<T>(fileExpression: string, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger, fetch }: ReadFileOrUrlOptions): Promise<T>;
|
|
14
14
|
export declare function readUrl<T>(path: string, config: ReadFileOrUrlOptions): Promise<T>;
|
|
@@ -10,5 +10,5 @@ export interface ReadFileOrUrlOptions extends MeshFetchRequestInit {
|
|
|
10
10
|
export declare function isUrl(str: string): boolean;
|
|
11
11
|
export declare function readFileOrUrl<T>(filePathOrUrl: string, config: ReadFileOrUrlOptions): Promise<T>;
|
|
12
12
|
export declare function loadYaml(filepath: string, content: string, logger: Logger): any;
|
|
13
|
-
export declare function readFile<T>(fileExpression: string, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger }: ReadFileOrUrlOptions): Promise<T>;
|
|
13
|
+
export declare function readFile<T>(fileExpression: string, { allowUnknownExtensions, cwd, fallbackFormat, importFn, logger, fetch }: ReadFileOrUrlOptions): Promise<T>;
|
|
14
14
|
export declare function readUrl<T>(path: string, config: ReadFileOrUrlOptions): Promise<T>;
|