@hyper-fetch/cli 7.2.4 → 7.2.6
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/dist/index.d.ts +1 -1
- package/dist/{cli.cjs.js → index.js} +84 -108
- package/dist/{cli.cjs.js.map → index.js.map} +3 -3
- package/package.json +4 -4
- package/src/codegen/openapi/generator.ts +16 -30
- 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/dist/index.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ declare class OpenapiRequestGenerator {
|
|
|
59
59
|
sdkSchema: string;
|
|
60
60
|
createSdkFn: string;
|
|
61
61
|
}>;
|
|
62
|
-
static generateRequestInstanceType({ id, path:
|
|
62
|
+
static generateRequestInstanceType({ id, path: endpoint }: {
|
|
63
63
|
id: string;
|
|
64
64
|
path: string;
|
|
65
65
|
}, types: Record<string, string>): string;
|
|
@@ -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
|
|
@@ -2266,15 +2260,15 @@ function handleError(error) {
|
|
|
2266
2260
|
}
|
|
2267
2261
|
|
|
2268
2262
|
// src/preflights/preflight-generate.ts
|
|
2269
|
-
var
|
|
2270
|
-
var
|
|
2263
|
+
var path2 = __toESM(require("node:path"));
|
|
2264
|
+
var fs2 = __toESM(require("fs-extra"));
|
|
2271
2265
|
|
|
2272
2266
|
// src/utils/errors.ts
|
|
2273
2267
|
var MISSING_DIR_OR_EMPTY_PROJECT = "1";
|
|
2274
2268
|
|
|
2275
2269
|
// src/config/get-config.ts
|
|
2276
|
-
var
|
|
2277
|
-
var
|
|
2270
|
+
var path = __toESM(require("node:path"));
|
|
2271
|
+
var fs = __toESM(require("fs-extra"));
|
|
2278
2272
|
var import_tsconfig_paths2 = __toESM(require_lib2());
|
|
2279
2273
|
|
|
2280
2274
|
// ../../node_modules/kleur/colors.mjs
|
|
@@ -2294,8 +2288,7 @@ function init(x, y) {
|
|
|
2294
2288
|
let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
|
|
2295
2289
|
let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
|
|
2296
2290
|
return function(txt) {
|
|
2297
|
-
if (!$.enabled || txt == null)
|
|
2298
|
-
return txt;
|
|
2291
|
+
if (!$.enabled || txt == null) return txt;
|
|
2299
2292
|
return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
|
|
2300
2293
|
};
|
|
2301
2294
|
}
|
|
@@ -2391,7 +2384,7 @@ function resolveConfigPaths(cwd, config) {
|
|
|
2391
2384
|
}
|
|
2392
2385
|
function getConfig(cwd) {
|
|
2393
2386
|
return __async(this, null, function* () {
|
|
2394
|
-
if (!
|
|
2387
|
+
if (!fs.existsSync(path.resolve(cwd, "api.json"))) {
|
|
2395
2388
|
logger.break();
|
|
2396
2389
|
logger.error(
|
|
2397
2390
|
`An invalid ${highlighter.info("api.json")} file was found at ${highlighter.info(
|
|
@@ -2404,7 +2397,7 @@ Before you can add or generate SDKs, you must create a valid ${highlighter.info(
|
|
|
2404
2397
|
logger.break();
|
|
2405
2398
|
process.exit(1);
|
|
2406
2399
|
}
|
|
2407
|
-
const { data, error } = yield configSchema.omit({ resolvedPaths: true }).safeParseAsync(JSON.parse(
|
|
2400
|
+
const { data, error } = yield configSchema.omit({ resolvedPaths: true }).safeParseAsync(JSON.parse(fs.readFileSync(path.resolve(cwd, "api.json"), "utf8")));
|
|
2408
2401
|
if (error) {
|
|
2409
2402
|
handleError(error);
|
|
2410
2403
|
}
|
|
@@ -2419,7 +2412,7 @@ Before you can add or generate SDKs, you must create a valid ${highlighter.info(
|
|
|
2419
2412
|
function preFlightGenerate(options) {
|
|
2420
2413
|
return __async(this, null, function* () {
|
|
2421
2414
|
const errors = {};
|
|
2422
|
-
if (!
|
|
2415
|
+
if (!fs2.existsSync(options.cwd) || !fs2.existsSync(path2.resolve(options.cwd, "package.json"))) {
|
|
2423
2416
|
errors[MISSING_DIR_OR_EMPTY_PROJECT] = true;
|
|
2424
2417
|
handleError(errors);
|
|
2425
2418
|
}
|
|
@@ -2449,10 +2442,10 @@ Before you can add SDKs, you must create a valid ${highlighter.info(
|
|
|
2449
2442
|
var import_dtsGenerator = __toESM(require("@anttiviljami/dtsgenerator/dist/core/dtsGenerator"));
|
|
2450
2443
|
var import_json_schema_ref_parser = __toESM(require("@apidevtools/json-schema-ref-parser"));
|
|
2451
2444
|
var import_type = require("@anttiviljami/dtsgenerator/dist/core/type");
|
|
2452
|
-
var
|
|
2445
|
+
var lodash = __toESM(require("lodash"));
|
|
2453
2446
|
var prettier = __toESM(require("prettier"));
|
|
2454
2447
|
var fs3 = __toESM(require("fs-extra"));
|
|
2455
|
-
var path3 = __toESM(require("path"));
|
|
2448
|
+
var path3 = __toESM(require("node:path"));
|
|
2456
2449
|
var import_core = require("@hyper-fetch/core");
|
|
2457
2450
|
|
|
2458
2451
|
// src/codegen/openapi/http-methods.enum.ts
|
|
@@ -2564,7 +2557,7 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2564
2557
|
const defaultFileName = "openapi.client";
|
|
2565
2558
|
const { schemaTypes, generatedTypes, sdkSchema, createSdkFn } = yield this.generateRequestsFromSchema();
|
|
2566
2559
|
const contents = [
|
|
2567
|
-
`import { createSdk as coreCreateSdk, ClientInstance,
|
|
2560
|
+
`import { createSdk as coreCreateSdk, ClientInstance, Request } from "@hyper-fetch/core";`,
|
|
2568
2561
|
"\n\n",
|
|
2569
2562
|
schemaTypes,
|
|
2570
2563
|
"\n\n",
|
|
@@ -2598,27 +2591,12 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2598
2591
|
return generatedPath;
|
|
2599
2592
|
});
|
|
2600
2593
|
}
|
|
2601
|
-
static generateRequestInstanceType({ id, path:
|
|
2594
|
+
static generateRequestInstanceType({ id, path: endpoint }, types) {
|
|
2602
2595
|
const Response = types[`${createTypeBaseName(id)}ResponseType`] ? `${createTypeBaseName(id)}ResponseType` : void 0;
|
|
2603
2596
|
const Payload = types[`${createTypeBaseName(id)}RequestBody`] ? `${createTypeBaseName(id)}RequestBody` : void 0;
|
|
2604
2597
|
const LocalError = types[`${createTypeBaseName(id)}ErrorType`] ? `${createTypeBaseName(id)}ErrorType` : void 0;
|
|
2605
2598
|
const QueryParams = types[`${createTypeBaseName(id)}QueryParams`] ? `${createTypeBaseName(id)}QueryParams` : void 0;
|
|
2606
|
-
|
|
2607
|
-
genericTypes.push(`client: Client`);
|
|
2608
|
-
genericTypes.push(`endpoint: "${relPath}"`);
|
|
2609
|
-
if (Response) {
|
|
2610
|
-
genericTypes.push(`response: ${Response}`);
|
|
2611
|
-
}
|
|
2612
|
-
if (Payload) {
|
|
2613
|
-
genericTypes.push(`payload: ${Payload}`);
|
|
2614
|
-
}
|
|
2615
|
-
if (LocalError) {
|
|
2616
|
-
genericTypes.push(`error: ${LocalError}`);
|
|
2617
|
-
}
|
|
2618
|
-
if (QueryParams) {
|
|
2619
|
-
genericTypes.push(`queryParams: ${QueryParams}`);
|
|
2620
|
-
}
|
|
2621
|
-
return `RequestInstance<{ ${genericTypes.join(", ")} }>`;
|
|
2599
|
+
return `Request<${Response}, ${Payload}, ${QueryParams}, ${LocalError}, "${endpoint}", Client>`;
|
|
2622
2600
|
}
|
|
2623
2601
|
static generateHyperFetchRequest({ id, path: relPath, method }, types) {
|
|
2624
2602
|
const Response = types[`${createTypeBaseName(id)}ResponseType`] ? `${createTypeBaseName(id)}ResponseType` : void 0;
|
|
@@ -2683,19 +2661,21 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2683
2661
|
var _a, _b, _c;
|
|
2684
2662
|
const { operationId, method, path: relPath } = operation;
|
|
2685
2663
|
const normalizedOperationId = normalizeOperationId(operationId);
|
|
2686
|
-
const pathParametersType = (_a =
|
|
2664
|
+
const pathParametersType = (_a = lodash.find(exportTypes, {
|
|
2687
2665
|
schemaRef: `#/paths/${normalizedOperationId}/pathParameters`
|
|
2688
2666
|
})) == null ? void 0 : _a.path;
|
|
2689
|
-
const queryParametersType = (_b =
|
|
2667
|
+
const queryParametersType = (_b = lodash.find(exportTypes, {
|
|
2690
2668
|
schemaRef: `#/paths/${normalizedOperationId}/queryParameters`
|
|
2691
2669
|
})) == null ? void 0 : _b.path;
|
|
2692
|
-
const requestBodyType = (_c =
|
|
2693
|
-
|
|
2694
|
-
|
|
2670
|
+
const requestBodyType = (_c = lodash.find(exportTypes, {
|
|
2671
|
+
schemaRef: `#/paths/${normalizedOperationId}/requestBody`
|
|
2672
|
+
})) == null ? void 0 : _c.path;
|
|
2673
|
+
const responseTypePaths = lodash.chain(exportTypes).filter(({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/2`)).map(({ path: responsePath }) => responsePath).value();
|
|
2674
|
+
const errorTypePaths = lodash.chain(exportTypes).filter(
|
|
2695
2675
|
({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/4`) || schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/5`)
|
|
2696
2676
|
).map(({ path: errorPath }) => errorPath).value();
|
|
2697
|
-
const responseType = !
|
|
2698
|
-
const errorType = !
|
|
2677
|
+
const responseType = !lodash.isEmpty(responseTypePaths) ? responseTypePaths.join(" | ") : "any";
|
|
2678
|
+
const errorType = !lodash.isEmpty(errorTypePaths) ? errorTypePaths.join(" | ") : "undefined";
|
|
2699
2679
|
return {
|
|
2700
2680
|
id: normalizedOperationId,
|
|
2701
2681
|
pathParametersType,
|
|
@@ -2710,8 +2690,7 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
|
|
|
2710
2690
|
static validateSchema(openapiDocument) {
|
|
2711
2691
|
const errors = [];
|
|
2712
2692
|
function validateRefs(obj, refPath = "") {
|
|
2713
|
-
if (!obj || typeof obj !== "object")
|
|
2714
|
-
return;
|
|
2693
|
+
if (!obj || typeof obj !== "object") return;
|
|
2715
2694
|
if (obj.$ref && typeof obj.$ref === "string" && obj.$ref.endsWith("/")) {
|
|
2716
2695
|
errors.push({
|
|
2717
2696
|
path: refPath,
|
|
@@ -2743,7 +2722,7 @@ ${errorMessages.join("\n")}`);
|
|
|
2743
2722
|
});
|
|
2744
2723
|
}
|
|
2745
2724
|
};
|
|
2746
|
-
__publicField(_OpenapiRequestGenerator, "getSchemaFromUrl", (_0) => __async(
|
|
2725
|
+
__publicField(_OpenapiRequestGenerator, "getSchemaFromUrl", (_0) => __async(null, [_0], function* ({ url, config }) {
|
|
2747
2726
|
if (isUrl(url)) {
|
|
2748
2727
|
const client = (0, import_core.createClient)({ url });
|
|
2749
2728
|
const getSchema = client.createRequest()({ endpoint: "" });
|
|
@@ -2819,7 +2798,7 @@ var generateOptionsSchema = import_zod4.z.object({
|
|
|
2819
2798
|
cwd: import_zod4.z.string().describe("The working directory. defaults to the current directory."),
|
|
2820
2799
|
overwrite: import_zod4.z.boolean().optional().describe("Overwrite existing files.")
|
|
2821
2800
|
});
|
|
2822
|
-
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(
|
|
2801
|
+
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* () {
|
|
2823
2802
|
try {
|
|
2824
2803
|
const help = process.argv.includes("--help") || process.argv.includes("-h");
|
|
2825
2804
|
if (help) {
|
|
@@ -2840,8 +2819,7 @@ var generate = new import_commander.Command().name("Generate").description("Gene
|
|
|
2840
2819
|
message: "Enter the URL to generate the schema from:",
|
|
2841
2820
|
validate: (value) => {
|
|
2842
2821
|
const result = import_zod4.z.url("Please enter a valid URL.").safeParse(value);
|
|
2843
|
-
if (result.success)
|
|
2844
|
-
return true;
|
|
2822
|
+
if (result.success) return true;
|
|
2845
2823
|
return result.error.message;
|
|
2846
2824
|
}
|
|
2847
2825
|
});
|
|
@@ -2852,7 +2830,7 @@ var generate = new import_commander.Command().name("Generate").description("Gene
|
|
|
2852
2830
|
default: `api-${opts.template}.sdk.ts`
|
|
2853
2831
|
});
|
|
2854
2832
|
}
|
|
2855
|
-
const fileExists =
|
|
2833
|
+
const fileExists = fs4.existsSync(path4.join(opts.cwd, opts.fileName));
|
|
2856
2834
|
if (opts.overwrite === void 0 && fileExists) {
|
|
2857
2835
|
opts.overwrite = yield (0, import_prompts.confirm)({ message: "Overwrite existing files?" });
|
|
2858
2836
|
}
|
|
@@ -2890,8 +2868,8 @@ var generate = new import_commander.Command().name("Generate").description("Gene
|
|
|
2890
2868
|
var import_commander2 = require("commander");
|
|
2891
2869
|
var import_prompts2 = require("@inquirer/prompts");
|
|
2892
2870
|
var import_zod5 = require("zod");
|
|
2893
|
-
var
|
|
2894
|
-
var
|
|
2871
|
+
var path5 = __toESM(require("node:path"));
|
|
2872
|
+
var fs5 = __toESM(require("fs-extra"));
|
|
2895
2873
|
|
|
2896
2874
|
// src/config/get-ts-alias.ts
|
|
2897
2875
|
var import_tsconfig_paths3 = __toESM(require_lib2());
|
|
@@ -2916,7 +2894,7 @@ var initOptionsSchema = import_zod5.z.object({
|
|
|
2916
2894
|
yes: import_zod5.z.boolean().optional().describe("skip confirmation prompt."),
|
|
2917
2895
|
cwd: import_zod5.z.string().describe("the working directory. defaults to the current directory.")
|
|
2918
2896
|
});
|
|
2919
|
-
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(
|
|
2897
|
+
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* () {
|
|
2920
2898
|
try {
|
|
2921
2899
|
const help = process.argv.includes("--help") || process.argv.includes("-h");
|
|
2922
2900
|
if (help) {
|
|
@@ -2942,8 +2920,7 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2942
2920
|
mainPath = yield (0, import_prompts2.input)({
|
|
2943
2921
|
message: "Enter the path to the main directory:",
|
|
2944
2922
|
validate: (value) => {
|
|
2945
|
-
if (!value)
|
|
2946
|
-
return "Path cannot be empty.";
|
|
2923
|
+
if (!value) return "Path cannot be empty.";
|
|
2947
2924
|
return true;
|
|
2948
2925
|
}
|
|
2949
2926
|
});
|
|
@@ -2952,15 +2929,14 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2952
2929
|
message: "Enter the name of the API directory:",
|
|
2953
2930
|
default: "api",
|
|
2954
2931
|
validate: (value) => {
|
|
2955
|
-
if (!value)
|
|
2956
|
-
return "Directory name cannot be empty.";
|
|
2932
|
+
if (!value) return "Directory name cannot be empty.";
|
|
2957
2933
|
return true;
|
|
2958
2934
|
}
|
|
2959
2935
|
});
|
|
2960
2936
|
}
|
|
2961
|
-
const fullPath =
|
|
2962
|
-
const relativePath =
|
|
2963
|
-
const configPath =
|
|
2937
|
+
const fullPath = path5.join(cwd, mainPath, apiDir);
|
|
2938
|
+
const relativePath = path5.join(mainPath, apiDir);
|
|
2939
|
+
const configPath = path5.join(cwd, "api.json");
|
|
2964
2940
|
const aliasPrefix = (yield getTsConfigAliasPrefix(cwd)) || "";
|
|
2965
2941
|
const alias = aliasPrefix ? `${aliasPrefix}/` : "";
|
|
2966
2942
|
const defaultAliases = {
|
|
@@ -2978,17 +2954,17 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
2978
2954
|
const steps = [
|
|
2979
2955
|
{
|
|
2980
2956
|
name: `Initialize API directory at ${relativePath}`,
|
|
2981
|
-
action: () => __async(
|
|
2982
|
-
if (!
|
|
2983
|
-
yield
|
|
2957
|
+
action: () => __async(null, null, function* () {
|
|
2958
|
+
if (!fs5.existsSync(fullPath)) {
|
|
2959
|
+
yield fs5.mkdir(fullPath, { recursive: true });
|
|
2984
2960
|
}
|
|
2985
2961
|
})
|
|
2986
2962
|
},
|
|
2987
2963
|
{
|
|
2988
2964
|
name: "Setup configuration",
|
|
2989
|
-
action: (currentConfig) => __async(
|
|
2990
|
-
if (
|
|
2991
|
-
const existingConfig = JSON.parse(
|
|
2965
|
+
action: (currentConfig) => __async(null, null, function* () {
|
|
2966
|
+
if (fs5.existsSync(configPath)) {
|
|
2967
|
+
const existingConfig = JSON.parse(fs5.readFileSync(configPath, "utf8"));
|
|
2992
2968
|
const { success, error, data } = configSchema.omit({ resolvedPaths: true }).safeParse(__spreadProps(__spreadValues(__spreadValues({}, defaultConfig), existingConfig), {
|
|
2993
2969
|
aliases: __spreadValues(__spreadValues({}, defaultConfig.aliases), existingConfig.aliases)
|
|
2994
2970
|
}));
|
|
@@ -3007,7 +2983,7 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
3007
2983
|
},
|
|
3008
2984
|
{
|
|
3009
2985
|
name: "Setup Aliases",
|
|
3010
|
-
action: (currentConfig) => __async(
|
|
2986
|
+
action: (currentConfig) => __async(null, null, function* () {
|
|
3011
2987
|
if (currentConfig.aliases) {
|
|
3012
2988
|
return currentConfig;
|
|
3013
2989
|
}
|
|
@@ -3018,12 +2994,12 @@ var init2 = new import_commander2.Command().name("Init").description("Initialize
|
|
|
3018
2994
|
},
|
|
3019
2995
|
{
|
|
3020
2996
|
name: `Create api.json configuration file`,
|
|
3021
|
-
action: (currentConfig) => __async(
|
|
2997
|
+
action: (currentConfig) => __async(null, null, function* () {
|
|
3022
2998
|
const finalConfig = __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), currentConfig), {
|
|
3023
2999
|
aliases: __spreadValues(__spreadValues({}, defaultConfig.aliases), currentConfig.aliases)
|
|
3024
3000
|
});
|
|
3025
3001
|
configSchema.omit({ resolvedPaths: true }).parse(finalConfig);
|
|
3026
|
-
yield
|
|
3002
|
+
yield fs5.writeFile(configPath, JSON.stringify(finalConfig, null, 2));
|
|
3027
3003
|
})
|
|
3028
3004
|
}
|
|
3029
3005
|
];
|
|
@@ -3056,7 +3032,7 @@ var commands = {
|
|
|
3056
3032
|
Object.values(commands).forEach((command) => {
|
|
3057
3033
|
program.addCommand(command);
|
|
3058
3034
|
});
|
|
3059
|
-
var main = () => __async(
|
|
3035
|
+
var main = () => __async(null, null, function* () {
|
|
3060
3036
|
try {
|
|
3061
3037
|
let chosenCommand;
|
|
3062
3038
|
if (process.argv[2] && Object.keys(commands).includes(process.argv[2])) {
|
|
@@ -3084,4 +3060,4 @@ var main = () => __async(exports, null, function* () {
|
|
|
3084
3060
|
}
|
|
3085
3061
|
});
|
|
3086
3062
|
main();
|
|
3087
|
-
//# sourceMappingURL=
|
|
3063
|
+
//# sourceMappingURL=index.js.map
|