@hyper-fetch/cli 7.2.5 → 7.3.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 +0 -3
- package/dist/index.d.ts +5 -2
- package/dist/{cli.cjs.js → index.js} +103 -96
- package/dist/index.js.map +7 -0
- package/package.json +4 -4
- package/src/cli/index.ts +2 -0
- package/src/codegen/openapi/generator.ts +35 -13
- package/src/commands/generate.ts +2 -2
- package/src/commands/init.ts +7 -7
- package/src/config/get-config.ts +2 -2
- package/src/preflights/preflight-add.ts +2 -2
- package/src/preflights/preflight-generate.ts +2 -2
- package/src/utils/handle-error.ts +3 -1
- package/dist/cli.cjs.js.map +0 -7
package/README.md
CHANGED
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
<a href="https://www.npmjs.com/package/hyper-fetch">
|
|
14
14
|
<img src="https://custom-icon-badges.demolab.com/npm/v/hyper-fetch.svg?logo=npm&color=e76f51" />
|
|
15
15
|
</a>
|
|
16
|
-
<a href="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage">
|
|
17
|
-
<img src="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage" />
|
|
18
|
-
</a>
|
|
19
16
|
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
20
17
|
<img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
|
|
21
18
|
</a>
|
package/dist/index.d.ts
CHANGED
|
@@ -59,14 +59,16 @@ declare class OpenapiRequestGenerator {
|
|
|
59
59
|
sdkSchema: string;
|
|
60
60
|
createSdkFn: string;
|
|
61
61
|
}>;
|
|
62
|
-
static generateRequestInstanceType({ id, path: endpoint }: {
|
|
62
|
+
static generateRequestInstanceType({ id, path: endpoint, queryParamsRequired }: {
|
|
63
63
|
id: string;
|
|
64
64
|
path: string;
|
|
65
|
+
queryParamsRequired?: boolean;
|
|
65
66
|
}, types: Record<string, string>): string;
|
|
66
|
-
static generateHyperFetchRequest({ id, path: relPath, method }: {
|
|
67
|
+
static generateHyperFetchRequest({ id, path: relPath, method, queryParamsRequired, }: {
|
|
67
68
|
id: string;
|
|
68
69
|
path: string;
|
|
69
70
|
method: string;
|
|
71
|
+
queryParamsRequired?: boolean;
|
|
70
72
|
}, types: Record<string, string>): string;
|
|
71
73
|
static generateTypes({ id, pathParametersType, queryParametersType, requestBodyType, errorType, responseType, }: {
|
|
72
74
|
id: string;
|
|
@@ -89,6 +91,7 @@ declare class OpenapiRequestGenerator {
|
|
|
89
91
|
responseType: string;
|
|
90
92
|
path: string;
|
|
91
93
|
method: string;
|
|
94
|
+
queryParamsRequired: boolean | undefined;
|
|
92
95
|
};
|
|
93
96
|
static validateSchema(openapiDocument: Document): void;
|
|
94
97
|
static prepareSchema(openapiDocument: Document): Promise<{
|
|
@@ -42,12 +42,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
42
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
43
|
mod
|
|
44
44
|
));
|
|
45
|
-
var __publicField = (obj, key, value) =>
|
|
46
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
47
|
-
return value;
|
|
48
|
-
};
|
|
45
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
49
46
|
var __async = (__this, __arguments, generator) => {
|
|
50
|
-
return new Promise((
|
|
47
|
+
return new Promise((resolve3, reject) => {
|
|
51
48
|
var fulfilled = (value) => {
|
|
52
49
|
try {
|
|
53
50
|
step(generator.next(value));
|
|
@@ -62,7 +59,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
62
59
|
reject(e);
|
|
63
60
|
}
|
|
64
61
|
};
|
|
65
|
-
var step = (x) => x.done ?
|
|
62
|
+
var step = (x) => x.done ? resolve3(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
66
63
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
67
64
|
});
|
|
68
65
|
};
|
|
@@ -73,13 +70,13 @@ var require_filesystem = __commonJS({
|
|
|
73
70
|
"use strict";
|
|
74
71
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
75
72
|
exports2.removeExtension = exports2.fileExistsAsync = exports2.readJsonFromDiskAsync = exports2.readJsonFromDiskSync = exports2.fileExistsSync = void 0;
|
|
76
|
-
var
|
|
73
|
+
var fs6 = require("fs");
|
|
77
74
|
function fileExistsSync(path6) {
|
|
78
|
-
if (!
|
|
75
|
+
if (!fs6.existsSync(path6)) {
|
|
79
76
|
return false;
|
|
80
77
|
}
|
|
81
78
|
try {
|
|
82
|
-
var stats =
|
|
79
|
+
var stats = fs6.statSync(path6);
|
|
83
80
|
return stats.isFile();
|
|
84
81
|
} catch (err) {
|
|
85
82
|
return false;
|
|
@@ -87,14 +84,14 @@ var require_filesystem = __commonJS({
|
|
|
87
84
|
}
|
|
88
85
|
exports2.fileExistsSync = fileExistsSync;
|
|
89
86
|
function readJsonFromDiskSync(packageJsonPath) {
|
|
90
|
-
if (!
|
|
87
|
+
if (!fs6.existsSync(packageJsonPath)) {
|
|
91
88
|
return void 0;
|
|
92
89
|
}
|
|
93
90
|
return require(packageJsonPath);
|
|
94
91
|
}
|
|
95
92
|
exports2.readJsonFromDiskSync = readJsonFromDiskSync;
|
|
96
93
|
function readJsonFromDiskAsync(path6, callback) {
|
|
97
|
-
|
|
94
|
+
fs6.readFile(path6, "utf8", function(err, result) {
|
|
98
95
|
if (err || !result) {
|
|
99
96
|
return callback();
|
|
100
97
|
}
|
|
@@ -104,7 +101,7 @@ var require_filesystem = __commonJS({
|
|
|
104
101
|
}
|
|
105
102
|
exports2.readJsonFromDiskAsync = readJsonFromDiskAsync;
|
|
106
103
|
function fileExistsAsync(path22, callback2) {
|
|
107
|
-
|
|
104
|
+
fs6.stat(path22, function(err, stats) {
|
|
108
105
|
if (err) {
|
|
109
106
|
return callback2(void 0, false);
|
|
110
107
|
}
|
|
@@ -1579,9 +1576,8 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1579
1576
|
__assign = Object.assign || function(t) {
|
|
1580
1577
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1581
1578
|
s = arguments[i];
|
|
1582
|
-
for (var p in s)
|
|
1583
|
-
|
|
1584
|
-
t[p] = s[p];
|
|
1579
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1580
|
+
t[p] = s[p];
|
|
1585
1581
|
}
|
|
1586
1582
|
return t;
|
|
1587
1583
|
};
|
|
@@ -1590,7 +1586,7 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1590
1586
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1591
1587
|
exports2.loadTsconfig = exports2.walkForTsConfig = exports2.tsConfigLoader = void 0;
|
|
1592
1588
|
var path6 = require("path");
|
|
1593
|
-
var
|
|
1589
|
+
var fs6 = require("fs");
|
|
1594
1590
|
var JSON5 = require_lib();
|
|
1595
1591
|
var StripBom = require_strip_bom();
|
|
1596
1592
|
function tsConfigLoader(_a) {
|
|
@@ -1619,10 +1615,10 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1619
1615
|
}
|
|
1620
1616
|
function resolveConfigPath(cwd, filename) {
|
|
1621
1617
|
if (filename) {
|
|
1622
|
-
var absolutePath =
|
|
1618
|
+
var absolutePath = fs6.lstatSync(filename).isDirectory() ? path6.resolve(filename, "./tsconfig.json") : path6.resolve(cwd, filename);
|
|
1623
1619
|
return absolutePath;
|
|
1624
1620
|
}
|
|
1625
|
-
if (
|
|
1621
|
+
if (fs6.statSync(cwd).isFile()) {
|
|
1626
1622
|
return path6.resolve(cwd);
|
|
1627
1623
|
}
|
|
1628
1624
|
var configAbsolutePath = walkForTsConfig(cwd);
|
|
@@ -1630,7 +1626,7 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1630
1626
|
}
|
|
1631
1627
|
function walkForTsConfig(directory, readdirSync) {
|
|
1632
1628
|
if (readdirSync === void 0) {
|
|
1633
|
-
readdirSync =
|
|
1629
|
+
readdirSync = fs6.readdirSync;
|
|
1634
1630
|
}
|
|
1635
1631
|
var files = readdirSync(directory);
|
|
1636
1632
|
var filesToCheck = ["tsconfig.json", "jsconfig.json"];
|
|
@@ -1647,19 +1643,19 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1647
1643
|
return walkForTsConfig(parentDirectory, readdirSync);
|
|
1648
1644
|
}
|
|
1649
1645
|
exports2.walkForTsConfig = walkForTsConfig;
|
|
1650
|
-
function loadTsconfig(configFilePath,
|
|
1651
|
-
if (
|
|
1652
|
-
|
|
1646
|
+
function loadTsconfig(configFilePath, existsSync5, readFileSync4) {
|
|
1647
|
+
if (existsSync5 === void 0) {
|
|
1648
|
+
existsSync5 = fs6.existsSync;
|
|
1653
1649
|
}
|
|
1654
|
-
if (
|
|
1655
|
-
|
|
1656
|
-
return
|
|
1650
|
+
if (readFileSync4 === void 0) {
|
|
1651
|
+
readFileSync4 = function(filename) {
|
|
1652
|
+
return fs6.readFileSync(filename, "utf8");
|
|
1657
1653
|
};
|
|
1658
1654
|
}
|
|
1659
|
-
if (!
|
|
1655
|
+
if (!existsSync5(configFilePath)) {
|
|
1660
1656
|
return void 0;
|
|
1661
1657
|
}
|
|
1662
|
-
var configString =
|
|
1658
|
+
var configString = readFileSync4(configFilePath);
|
|
1663
1659
|
var cleanedJson = StripBom(configString);
|
|
1664
1660
|
var config;
|
|
1665
1661
|
try {
|
|
@@ -1672,27 +1668,27 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1672
1668
|
var base = void 0;
|
|
1673
1669
|
if (Array.isArray(extendedConfig)) {
|
|
1674
1670
|
base = extendedConfig.reduce(function(currBase, extendedConfigElement) {
|
|
1675
|
-
return mergeTsconfigs(currBase, loadTsconfigFromExtends(configFilePath, extendedConfigElement,
|
|
1671
|
+
return mergeTsconfigs(currBase, loadTsconfigFromExtends(configFilePath, extendedConfigElement, existsSync5, readFileSync4));
|
|
1676
1672
|
}, {});
|
|
1677
1673
|
} else {
|
|
1678
|
-
base = loadTsconfigFromExtends(configFilePath, extendedConfig,
|
|
1674
|
+
base = loadTsconfigFromExtends(configFilePath, extendedConfig, existsSync5, readFileSync4);
|
|
1679
1675
|
}
|
|
1680
1676
|
return mergeTsconfigs(base, config);
|
|
1681
1677
|
}
|
|
1682
1678
|
return config;
|
|
1683
1679
|
}
|
|
1684
1680
|
exports2.loadTsconfig = loadTsconfig;
|
|
1685
|
-
function loadTsconfigFromExtends(configFilePath, extendedConfigValue,
|
|
1681
|
+
function loadTsconfigFromExtends(configFilePath, extendedConfigValue, existsSync5, readFileSync4) {
|
|
1686
1682
|
var _a;
|
|
1687
1683
|
if (typeof extendedConfigValue === "string" && extendedConfigValue.indexOf(".json") === -1) {
|
|
1688
1684
|
extendedConfigValue += ".json";
|
|
1689
1685
|
}
|
|
1690
1686
|
var currentDir = path6.dirname(configFilePath);
|
|
1691
1687
|
var extendedConfigPath = path6.join(currentDir, extendedConfigValue);
|
|
1692
|
-
if (extendedConfigValue.indexOf("/") !== -1 && extendedConfigValue.indexOf(".") !== -1 && !
|
|
1688
|
+
if (extendedConfigValue.indexOf("/") !== -1 && extendedConfigValue.indexOf(".") !== -1 && !existsSync5(extendedConfigPath)) {
|
|
1693
1689
|
extendedConfigPath = path6.join(currentDir, "node_modules", extendedConfigValue);
|
|
1694
1690
|
}
|
|
1695
|
-
var config = loadTsconfig(extendedConfigPath,
|
|
1691
|
+
var config = loadTsconfig(extendedConfigPath, existsSync5, readFileSync4) || {};
|
|
1696
1692
|
if ((_a = config.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl) {
|
|
1697
1693
|
var extendsDir = path6.dirname(extendedConfigValue);
|
|
1698
1694
|
config.compilerOptions.baseUrl = path6.join(extendsDir, config.compilerOptions.baseUrl);
|
|
@@ -1988,14 +1984,12 @@ var require_register = __commonJS({
|
|
|
1988
1984
|
"../../node_modules/tsconfig-paths/lib/register.js"(exports2) {
|
|
1989
1985
|
"use strict";
|
|
1990
1986
|
var __spreadArray = exports2 && exports2.__spreadArray || function(to, from, pack) {
|
|
1991
|
-
if (pack || arguments.length === 2)
|
|
1992
|
-
|
|
1993
|
-
if (ar
|
|
1994
|
-
|
|
1995
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
1996
|
-
ar[i] = from[i];
|
|
1997
|
-
}
|
|
1987
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1988
|
+
if (ar || !(i in from)) {
|
|
1989
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1990
|
+
ar[i] = from[i];
|
|
1998
1991
|
}
|
|
1992
|
+
}
|
|
1999
1993
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2000
1994
|
};
|
|
2001
1995
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -2140,8 +2134,8 @@ var package_default = {
|
|
|
2140
2134
|
types: "dist/index.d.ts",
|
|
2141
2135
|
source: "src/index.ts",
|
|
2142
2136
|
cli: "src/cli/index.ts",
|
|
2143
|
-
climain: "dist/
|
|
2144
|
-
bin: "dist/
|
|
2137
|
+
climain: "dist/index.js",
|
|
2138
|
+
bin: "dist/index.js",
|
|
2145
2139
|
scripts: {
|
|
2146
2140
|
clean: "npx rimraf dist",
|
|
2147
2141
|
test: "node --experimental-vm-modules ../../node_modules/jest/bin/jest --watchAll --maxWorkers=3 --forceExit",
|
|
@@ -2170,7 +2164,7 @@ var package_default = {
|
|
|
2170
2164
|
url: "https://github.com/BetterTyped/hyper-fetch/issues"
|
|
2171
2165
|
},
|
|
2172
2166
|
dependencies: {
|
|
2173
|
-
"@anttiviljami/dtsgenerator": "^3.
|
|
2167
|
+
"@anttiviljami/dtsgenerator": "^3.20.0",
|
|
2174
2168
|
"@apidevtools/json-schema-ref-parser": "^11.9.3",
|
|
2175
2169
|
"@hyper-fetch/core": "*",
|
|
2176
2170
|
"@inquirer/prompts": "^7.6.0",
|
|
@@ -2209,8 +2203,8 @@ var package_default = {
|
|
|
2209
2203
|
// src/commands/generate.ts
|
|
2210
2204
|
var import_commander = require("commander");
|
|
2211
2205
|
var import_zod4 = require("zod");
|
|
2212
|
-
var
|
|
2213
|
-
var
|
|
2206
|
+
var path4 = __toESM(require("node:path"));
|
|
2207
|
+
var fs4 = __toESM(require("fs-extra"));
|
|
2214
2208
|
var import_prompts = require("@inquirer/prompts");
|
|
2215
2209
|
|
|
2216
2210
|
// src/utils/handle-error.ts
|
|
@@ -2242,7 +2236,7 @@ function handleError(error) {
|
|
|
2242
2236
|
logger.break();
|
|
2243
2237
|
logger.error(`Something went wrong. Please check the error below for more details.`);
|
|
2244
2238
|
logger.error(`If the problem persists, please open an issue on GitHub.`);
|
|
2245
|
-
logger.
|
|
2239
|
+
logger.break();
|
|
2246
2240
|
if (typeof error === "string") {
|
|
2247
2241
|
logger.error(error);
|
|
2248
2242
|
logger.break();
|
|
@@ -2261,20 +2255,21 @@ function handleError(error) {
|
|
|
2261
2255
|
logger.break();
|
|
2262
2256
|
process.exit(1);
|
|
2263
2257
|
}
|
|
2258
|
+
logger.error(JSON.stringify({ error }));
|
|
2264
2259
|
logger.break();
|
|
2265
2260
|
process.exit(1);
|
|
2266
2261
|
}
|
|
2267
2262
|
|
|
2268
2263
|
// src/preflights/preflight-generate.ts
|
|
2269
|
-
var
|
|
2270
|
-
var
|
|
2264
|
+
var path2 = __toESM(require("node:path"));
|
|
2265
|
+
var fs2 = __toESM(require("fs-extra"));
|
|
2271
2266
|
|
|
2272
2267
|
// src/utils/errors.ts
|
|
2273
2268
|
var MISSING_DIR_OR_EMPTY_PROJECT = "1";
|
|
2274
2269
|
|
|
2275
2270
|
// src/config/get-config.ts
|
|
2276
|
-
var
|
|
2277
|
-
var
|
|
2271
|
+
var path = __toESM(require("node:path"));
|
|
2272
|
+
var fs = __toESM(require("fs-extra"));
|
|
2278
2273
|
var import_tsconfig_paths2 = __toESM(require_lib2());
|
|
2279
2274
|
|
|
2280
2275
|
// ../../node_modules/kleur/colors.mjs
|
|
@@ -2294,8 +2289,7 @@ function init(x, y) {
|
|
|
2294
2289
|
let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
|
|
2295
2290
|
let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
|
|
2296
2291
|
return function(txt) {
|
|
2297
|
-
if (!$.enabled || txt == null)
|
|
2298
|
-
return txt;
|
|
2292
|
+
if (!$.enabled || txt == null) return txt;
|
|
2299
2293
|
return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
|
|
2300
2294
|
};
|
|
2301
2295
|
}
|
|
@@ -2391,7 +2385,7 @@ function resolveConfigPaths(cwd, config) {
|
|
|
2391
2385
|
}
|
|
2392
2386
|
function getConfig(cwd) {
|
|
2393
2387
|
return __async(this, null, function* () {
|
|
2394
|
-
if (!
|
|
2388
|
+
if (!fs.existsSync(path.resolve(cwd, "api.json"))) {
|
|
2395
2389
|
logger.break();
|
|
2396
2390
|
logger.error(
|
|
2397
2391
|
`An invalid ${highlighter.info("api.json")} file was found at ${highlighter.info(
|
|
@@ -2404,7 +2398,7 @@ Before you can add or generate SDKs, you must create a valid ${highlighter.info(
|
|
|
2404
2398
|
logger.break();
|
|
2405
2399
|
process.exit(1);
|
|
2406
2400
|
}
|
|
2407
|
-
const { data, error } = yield configSchema.omit({ resolvedPaths: true }).safeParseAsync(JSON.parse(
|
|
2401
|
+
const { data, error } = yield configSchema.omit({ resolvedPaths: true }).safeParseAsync(JSON.parse(fs.readFileSync(path.resolve(cwd, "api.json"), "utf8")));
|
|
2408
2402
|
if (error) {
|
|
2409
2403
|
handleError(error);
|
|
2410
2404
|
}
|
|
@@ -2419,7 +2413,7 @@ Before you can add or generate SDKs, you must create a valid ${highlighter.info(
|
|
|
2419
2413
|
function preFlightGenerate(options) {
|
|
2420
2414
|
return __async(this, null, function* () {
|
|
2421
2415
|
const errors = {};
|
|
2422
|
-
if (!
|
|
2416
|
+
if (!fs2.existsSync(options.cwd) || !fs2.existsSync(path2.resolve(options.cwd, "package.json"))) {
|
|
2423
2417
|
errors[MISSING_DIR_OR_EMPTY_PROJECT] = true;
|
|
2424
2418
|
handleError(errors);
|
|
2425
2419
|
}
|
|
@@ -2449,10 +2443,10 @@ Before you can add SDKs, you must create a valid ${highlighter.info(
|
|
|
2449
2443
|
var import_dtsGenerator = __toESM(require("@anttiviljami/dtsgenerator/dist/core/dtsGenerator"));
|
|
2450
2444
|
var import_json_schema_ref_parser = __toESM(require("@apidevtools/json-schema-ref-parser"));
|
|
2451
2445
|
var import_type = require("@anttiviljami/dtsgenerator/dist/core/type");
|
|
2452
|
-
var
|
|
2446
|
+
var lodash = __toESM(require("lodash"));
|
|
2453
2447
|
var prettier = __toESM(require("prettier"));
|
|
2454
2448
|
var fs3 = __toESM(require("fs-extra"));
|
|
2455
|
-
var path3 = __toESM(require("path"));
|
|
2449
|
+
var path3 = __toESM(require("node:path"));
|
|
2456
2450
|
var import_core = require("@hyper-fetch/core");
|
|
2457
2451
|
|
|
2458
2452
|
// src/codegen/openapi/http-methods.enum.ts
|
|
@@ -2598,14 +2592,20 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2598
2592
|
return generatedPath;
|
|
2599
2593
|
});
|
|
2600
2594
|
}
|
|
2601
|
-
static generateRequestInstanceType({ id, path: endpoint }, types) {
|
|
2595
|
+
static generateRequestInstanceType({ id, path: endpoint, queryParamsRequired }, types) {
|
|
2602
2596
|
const Response = types[`${createTypeBaseName(id)}ResponseType`] ? `${createTypeBaseName(id)}ResponseType` : void 0;
|
|
2603
2597
|
const Payload = types[`${createTypeBaseName(id)}RequestBody`] ? `${createTypeBaseName(id)}RequestBody` : void 0;
|
|
2604
2598
|
const LocalError = types[`${createTypeBaseName(id)}ErrorType`] ? `${createTypeBaseName(id)}ErrorType` : void 0;
|
|
2605
2599
|
const QueryParams = types[`${createTypeBaseName(id)}QueryParams`] ? `${createTypeBaseName(id)}QueryParams` : void 0;
|
|
2606
|
-
|
|
2600
|
+
const QueryParamsGeneric = QueryParams && queryParamsRequired === false ? `${QueryParams} | undefined` : QueryParams;
|
|
2601
|
+
return `Request<${Response}, ${Payload}, ${QueryParamsGeneric}, ${LocalError}, "${endpoint}", Client>`;
|
|
2607
2602
|
}
|
|
2608
|
-
static generateHyperFetchRequest({
|
|
2603
|
+
static generateHyperFetchRequest({
|
|
2604
|
+
id,
|
|
2605
|
+
path: relPath,
|
|
2606
|
+
method,
|
|
2607
|
+
queryParamsRequired
|
|
2608
|
+
}, types) {
|
|
2609
2609
|
const Response = types[`${createTypeBaseName(id)}ResponseType`] ? `${createTypeBaseName(id)}ResponseType` : void 0;
|
|
2610
2610
|
const Payload = types[`${createTypeBaseName(id)}RequestBody`] ? `${createTypeBaseName(id)}RequestBody` : void 0;
|
|
2611
2611
|
const LocalError = types[`${createTypeBaseName(id)}ErrorType`] ? `${createTypeBaseName(id)}ErrorType` : void 0;
|
|
@@ -2628,7 +2628,8 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2628
2628
|
addToGenericType("error", LocalError);
|
|
2629
2629
|
}
|
|
2630
2630
|
if (QueryParams) {
|
|
2631
|
-
|
|
2631
|
+
const key = queryParamsRequired === false ? "queryParams?" : "queryParams";
|
|
2632
|
+
addToGenericType(key, QueryParams);
|
|
2632
2633
|
}
|
|
2633
2634
|
if (genericType) {
|
|
2634
2635
|
genericType = `<{${genericType}}>`;
|
|
@@ -2668,19 +2669,27 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2668
2669
|
var _a, _b, _c;
|
|
2669
2670
|
const { operationId, method, path: relPath } = operation;
|
|
2670
2671
|
const normalizedOperationId = normalizeOperationId(operationId);
|
|
2671
|
-
const pathParametersType = (_a =
|
|
2672
|
+
const pathParametersType = (_a = lodash.find(exportTypes, {
|
|
2672
2673
|
schemaRef: `#/paths/${normalizedOperationId}/pathParameters`
|
|
2673
2674
|
})) == null ? void 0 : _a.path;
|
|
2674
|
-
const queryParametersType = (_b =
|
|
2675
|
+
const queryParametersType = (_b = lodash.find(exportTypes, {
|
|
2675
2676
|
schemaRef: `#/paths/${normalizedOperationId}/queryParameters`
|
|
2676
2677
|
})) == null ? void 0 : _b.path;
|
|
2677
|
-
const requestBodyType = (_c =
|
|
2678
|
-
|
|
2679
|
-
|
|
2678
|
+
const requestBodyType = (_c = lodash.find(exportTypes, {
|
|
2679
|
+
schemaRef: `#/paths/${normalizedOperationId}/requestBody`
|
|
2680
|
+
})) == null ? void 0 : _c.path;
|
|
2681
|
+
const responseTypePaths = lodash.chain(exportTypes).filter(({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/2`)).map(({ path: responsePath }) => responsePath).value();
|
|
2682
|
+
const errorTypePaths = lodash.chain(exportTypes).filter(
|
|
2680
2683
|
({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/4`) || schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/5`)
|
|
2681
2684
|
).map(({ path: errorPath }) => errorPath).value();
|
|
2682
|
-
const responseType = !
|
|
2683
|
-
const errorType = !
|
|
2685
|
+
const responseType = !lodash.isEmpty(responseTypePaths) ? responseTypePaths.join(" | ") : "any";
|
|
2686
|
+
const errorType = !lodash.isEmpty(errorTypePaths) ? errorTypePaths.join(" | ") : "undefined";
|
|
2687
|
+
const queryParamsRequired = Array.isArray(operation.parameters) ? operation.parameters.every((p) => {
|
|
2688
|
+
if ("in" in p && p.in === "query" && p.required === false) {
|
|
2689
|
+
return true;
|
|
2690
|
+
}
|
|
2691
|
+
return false;
|
|
2692
|
+
}) : void 0;
|
|
2684
2693
|
return {
|
|
2685
2694
|
id: normalizedOperationId,
|
|
2686
2695
|
pathParametersType,
|
|
@@ -2689,14 +2698,14 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2689
2698
|
errorType,
|
|
2690
2699
|
responseType,
|
|
2691
2700
|
path: adjustPathParamsFormat(relPath),
|
|
2692
|
-
method: method ? method.toUpperCase() : "get" /* GET
|
|
2701
|
+
method: method ? method.toUpperCase() : "get" /* GET */,
|
|
2702
|
+
queryParamsRequired
|
|
2693
2703
|
};
|
|
2694
2704
|
}
|
|
2695
2705
|
static validateSchema(openapiDocument) {
|
|
2696
2706
|
const errors = [];
|
|
2697
2707
|
function validateRefs(obj, refPath = "") {
|
|
2698
|
-
if (!obj || typeof obj !== "object")
|
|
2699
|
-
return;
|
|
2708
|
+
if (!obj || typeof obj !== "object") return;
|
|
2700
2709
|
if (obj.$ref && typeof obj.$ref === "string" && obj.$ref.endsWith("/")) {
|
|
2701
2710
|
errors.push({
|
|
2702
2711
|
path: refPath,
|
|
@@ -2728,7 +2737,7 @@ ${errorMessages.join("\n")}`);
|
|
|
2728
2737
|
});
|
|
2729
2738
|
}
|
|
2730
2739
|
};
|
|
2731
|
-
__publicField(_OpenapiRequestGenerator, "getSchemaFromUrl", (_0) => __async(
|
|
2740
|
+
__publicField(_OpenapiRequestGenerator, "getSchemaFromUrl", (_0) => __async(null, [_0], function* ({ url, config }) {
|
|
2732
2741
|
if (isUrl(url)) {
|
|
2733
2742
|
const client = (0, import_core.createClient)({ url });
|
|
2734
2743
|
const getSchema = client.createRequest()({ endpoint: "" });
|
|
@@ -2804,7 +2813,7 @@ var generateOptionsSchema = import_zod4.z.object({
|
|
|
2804
2813
|
cwd: import_zod4.z.string().describe("The working directory. defaults to the current directory."),
|
|
2805
2814
|
overwrite: import_zod4.z.boolean().optional().describe("Overwrite existing files.")
|
|
2806
2815
|
});
|
|
2807
|
-
var generate = new import_commander.Command().name("Generate").description("Generate SDK from a schema, url or service").option("-t, --template <template>", "API provider template to use").option("-u, --url <url>", "The URL to generate the schema from").option("-f, --fileName <fileName>", "The output file for the SDK.").option("-o, --overwrite", "overwrite existing files.").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-h, --help <help>", "display help for command").action((opts) => __async(
|
|
2816
|
+
var generate = new import_commander.Command().name("Generate").description("Generate SDK from a schema, url or service").option("-t, --template <template>", "API provider template to use").option("-u, --url <url>", "The URL to generate the schema from").option("-f, --fileName <fileName>", "The output file for the SDK.").option("-o, --overwrite", "overwrite existing files.").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-h, --help <help>", "display help for command").action((opts) => __async(null, null, function* () {
|
|
2808
2817
|
try {
|
|
2809
2818
|
const help = process.argv.includes("--help") || process.argv.includes("-h");
|
|
2810
2819
|
if (help) {
|
|
@@ -2825,8 +2834,7 @@ var generate = new import_commander.Command().name("Generate").description("Gene
|
|
|
2825
2834
|
message: "Enter the URL to generate the schema from:",
|
|
2826
2835
|
validate: (value) => {
|
|
2827
2836
|
const result = import_zod4.z.url("Please enter a valid URL.").safeParse(value);
|
|
2828
|
-
if (result.success)
|
|
2829
|
-
return true;
|
|
2837
|
+
if (result.success) return true;
|
|
2830
2838
|
return result.error.message;
|
|
2831
2839
|
}
|
|
2832
2840
|
});
|
|
@@ -2837,7 +2845,7 @@ var generate = new import_commander.Command().name("Generate").description("Gene
|
|
|
2837
2845
|
default: `api-${opts.template}.sdk.ts`
|
|
2838
2846
|
});
|
|
2839
2847
|
}
|
|
2840
|
-
const fileExists =
|
|
2848
|
+
const fileExists = fs4.existsSync(path4.join(opts.cwd, opts.fileName));
|
|
2841
2849
|
if (opts.overwrite === void 0 && fileExists) {
|
|
2842
2850
|
opts.overwrite = yield (0, import_prompts.confirm)({ message: "Overwrite existing files?" });
|
|
2843
2851
|
}
|
|
@@ -2875,8 +2883,8 @@ var generate = new import_commander.Command().name("Generate").description("Gene
|
|
|
2875
2883
|
var import_commander2 = require("commander");
|
|
2876
2884
|
var import_prompts2 = require("@inquirer/prompts");
|
|
2877
2885
|
var import_zod5 = require("zod");
|
|
2878
|
-
var
|
|
2879
|
-
var
|
|
2886
|
+
var path5 = __toESM(require("node:path"));
|
|
2887
|
+
var fs5 = __toESM(require("fs-extra"));
|
|
2880
2888
|
|
|
2881
2889
|
// src/config/get-ts-alias.ts
|
|
2882
2890
|
var import_tsconfig_paths3 = __toESM(require_lib2());
|
|
@@ -2901,7 +2909,7 @@ var initOptionsSchema = import_zod5.z.object({
|
|
|
2901
2909
|
yes: import_zod5.z.boolean().optional().describe("skip confirmation prompt."),
|
|
2902
2910
|
cwd: import_zod5.z.string().describe("the working directory. defaults to the current directory.")
|
|
2903
2911
|
});
|
|
2904
|
-
var init2 = new import_commander2.Command().name("Init").description("Initialize HyperFetch Client configuration.").option("-y, --yes", "skip confirmation prompt.", false).option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-h, --help <help>", "display help for command").action((opts) => __async(
|
|
2912
|
+
var init2 = new import_commander2.Command().name("Init").description("Initialize HyperFetch Client configuration.").option("-y, --yes", "skip confirmation prompt.", false).option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-h, --help <help>", "display help for command").action((opts) => __async(null, null, function* () {
|
|
2905
2913
|
try {
|
|
2906
2914
|
const help = process.argv.includes("--help") || process.argv.includes("-h");
|
|
2907
2915
|
if (help) {
|
|
@@ -2927,8 +2935,7 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2927
2935
|
mainPath = yield (0, import_prompts2.input)({
|
|
2928
2936
|
message: "Enter the path to the main directory:",
|
|
2929
2937
|
validate: (value) => {
|
|
2930
|
-
if (!value)
|
|
2931
|
-
return "Path cannot be empty.";
|
|
2938
|
+
if (!value) return "Path cannot be empty.";
|
|
2932
2939
|
return true;
|
|
2933
2940
|
}
|
|
2934
2941
|
});
|
|
@@ -2937,15 +2944,14 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2937
2944
|
message: "Enter the name of the API directory:",
|
|
2938
2945
|
default: "api",
|
|
2939
2946
|
validate: (value) => {
|
|
2940
|
-
if (!value)
|
|
2941
|
-
return "Directory name cannot be empty.";
|
|
2947
|
+
if (!value) return "Directory name cannot be empty.";
|
|
2942
2948
|
return true;
|
|
2943
2949
|
}
|
|
2944
2950
|
});
|
|
2945
2951
|
}
|
|
2946
|
-
const fullPath =
|
|
2947
|
-
const relativePath =
|
|
2948
|
-
const configPath =
|
|
2952
|
+
const fullPath = path5.join(cwd, mainPath, apiDir);
|
|
2953
|
+
const relativePath = path5.join(mainPath, apiDir);
|
|
2954
|
+
const configPath = path5.join(cwd, "api.json");
|
|
2949
2955
|
const aliasPrefix = (yield getTsConfigAliasPrefix(cwd)) || "";
|
|
2950
2956
|
const alias = aliasPrefix ? `${aliasPrefix}/` : "";
|
|
2951
2957
|
const defaultAliases = {
|
|
@@ -2963,17 +2969,17 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2963
2969
|
const steps = [
|
|
2964
2970
|
{
|
|
2965
2971
|
name: `Initialize API directory at ${relativePath}`,
|
|
2966
|
-
action: () => __async(
|
|
2967
|
-
if (!
|
|
2968
|
-
yield
|
|
2972
|
+
action: () => __async(null, null, function* () {
|
|
2973
|
+
if (!fs5.existsSync(fullPath)) {
|
|
2974
|
+
yield fs5.mkdir(fullPath, { recursive: true });
|
|
2969
2975
|
}
|
|
2970
2976
|
})
|
|
2971
2977
|
},
|
|
2972
2978
|
{
|
|
2973
2979
|
name: "Setup configuration",
|
|
2974
|
-
action: (currentConfig) => __async(
|
|
2975
|
-
if (
|
|
2976
|
-
const existingConfig = JSON.parse(
|
|
2980
|
+
action: (currentConfig) => __async(null, null, function* () {
|
|
2981
|
+
if (fs5.existsSync(configPath)) {
|
|
2982
|
+
const existingConfig = JSON.parse(fs5.readFileSync(configPath, "utf8"));
|
|
2977
2983
|
const { success, error, data } = configSchema.omit({ resolvedPaths: true }).safeParse(__spreadProps(__spreadValues(__spreadValues({}, defaultConfig), existingConfig), {
|
|
2978
2984
|
aliases: __spreadValues(__spreadValues({}, defaultConfig.aliases), existingConfig.aliases)
|
|
2979
2985
|
}));
|
|
@@ -2992,7 +2998,7 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2992
2998
|
},
|
|
2993
2999
|
{
|
|
2994
3000
|
name: "Setup Aliases",
|
|
2995
|
-
action: (currentConfig) => __async(
|
|
3001
|
+
action: (currentConfig) => __async(null, null, function* () {
|
|
2996
3002
|
if (currentConfig.aliases) {
|
|
2997
3003
|
return currentConfig;
|
|
2998
3004
|
}
|
|
@@ -3003,12 +3009,12 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
3003
3009
|
},
|
|
3004
3010
|
{
|
|
3005
3011
|
name: `Create api.json configuration file`,
|
|
3006
|
-
action: (currentConfig) => __async(
|
|
3012
|
+
action: (currentConfig) => __async(null, null, function* () {
|
|
3007
3013
|
const finalConfig = __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), currentConfig), {
|
|
3008
3014
|
aliases: __spreadValues(__spreadValues({}, defaultConfig.aliases), currentConfig.aliases)
|
|
3009
3015
|
});
|
|
3010
3016
|
configSchema.omit({ resolvedPaths: true }).parse(finalConfig);
|
|
3011
|
-
yield
|
|
3017
|
+
yield fs5.writeFile(configPath, JSON.stringify(finalConfig, null, 2));
|
|
3012
3018
|
})
|
|
3013
3019
|
}
|
|
3014
3020
|
];
|
|
@@ -3041,7 +3047,7 @@ var commands = {
|
|
|
3041
3047
|
Object.values(commands).forEach((command) => {
|
|
3042
3048
|
program.addCommand(command);
|
|
3043
3049
|
});
|
|
3044
|
-
var main = () => __async(
|
|
3050
|
+
var main = () => __async(null, null, function* () {
|
|
3045
3051
|
try {
|
|
3046
3052
|
let chosenCommand;
|
|
3047
3053
|
if (process.argv[2] && Object.keys(commands).includes(process.argv[2])) {
|
|
@@ -3060,6 +3066,7 @@ var main = () => __async(exports, null, function* () {
|
|
|
3060
3066
|
}
|
|
3061
3067
|
yield program.parseAsync([process.argv[0], process.argv[1], chosenCommand]);
|
|
3062
3068
|
} catch (e) {
|
|
3069
|
+
handleError(e);
|
|
3063
3070
|
if (e instanceof Error) {
|
|
3064
3071
|
if (e.message.includes("User force closed the prompt")) {
|
|
3065
3072
|
process.exit(0);
|
|
@@ -3069,4 +3076,4 @@ var main = () => __async(exports, null, function* () {
|
|
|
3069
3076
|
}
|
|
3070
3077
|
});
|
|
3071
3078
|
main();
|
|
3072
|
-
//# sourceMappingURL=
|
|
3079
|
+
//# sourceMappingURL=index.js.map
|