@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/cli",
3
- "version": "7.2.4",
3
+ "version": "7.2.6",
4
4
  "description": "Hyper Fetch cli for code generation and utilities",
5
5
  "author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
6
6
  "homepage": "https://hyperfetch.bettertyped.com/",
@@ -10,8 +10,8 @@
10
10
  "types": "dist/index.d.ts",
11
11
  "source": "src/index.ts",
12
12
  "cli": "src/cli/index.ts",
13
- "climain": "dist/cli.cjs.js",
14
- "bin": "dist/cli.cjs.js",
13
+ "climain": "dist/index.js",
14
+ "bin": "dist/index.js",
15
15
  "scripts": {
16
16
  "clean": "npx rimraf dist",
17
17
  "test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest --watchAll --maxWorkers=3 --forceExit",
@@ -40,7 +40,7 @@
40
40
  "url": "https://github.com/BetterTyped/hyper-fetch/issues"
41
41
  },
42
42
  "dependencies": {
43
- "@anttiviljami/dtsgenerator": "^3.12.2",
43
+ "@anttiviljami/dtsgenerator": "^3.20.0",
44
44
  "@apidevtools/json-schema-ref-parser": "^11.9.3",
45
45
  "@hyper-fetch/core": "*",
46
46
  "@inquirer/prompts": "^7.6.0",
@@ -1,10 +1,10 @@
1
1
  import DtsGenerator, { ExportedType } from "@anttiviljami/dtsgenerator/dist/core/dtsGenerator";
2
2
  import RefParser from "@apidevtools/json-schema-ref-parser";
3
3
  import { parseSchema } from "@anttiviljami/dtsgenerator/dist/core/type";
4
- import { find, chain, isEmpty } from "lodash";
4
+ import * as lodash from "lodash";
5
5
  import * as prettier from "prettier";
6
6
  import * as fs from "fs-extra";
7
- import * as path from "path";
7
+ import * as path from "node:path";
8
8
  import { createClient } from "@hyper-fetch/core";
9
9
 
10
10
  import { Document, Operation, GeneratedTypes } from "./openapi.types";
@@ -46,7 +46,7 @@ export class OpenapiRequestGenerator {
46
46
  const defaultFileName = "openapi.client";
47
47
  const { schemaTypes, generatedTypes, sdkSchema, createSdkFn } = await this.generateRequestsFromSchema();
48
48
  const contents = [
49
- `import { createSdk as coreCreateSdk, ClientInstance, RequestInstance } from "@hyper-fetch/core";`,
49
+ `import { createSdk as coreCreateSdk, ClientInstance, Request } from "@hyper-fetch/core";`,
50
50
  "\n\n",
51
51
  schemaTypes,
52
52
  "\n\n",
@@ -138,7 +138,7 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
138
138
  };
139
139
 
140
140
  static generateRequestInstanceType(
141
- { id, path: relPath }: { id: string; path: string },
141
+ { id, path: endpoint }: { id: string; path: string },
142
142
  types: Record<string, string>,
143
143
  ) {
144
144
  const Response = types[`${createTypeBaseName(id)}ResponseType`]
@@ -150,25 +150,7 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
150
150
  ? `${createTypeBaseName(id)}QueryParams`
151
151
  : undefined;
152
152
 
153
- const genericTypes: string[] = [];
154
-
155
- genericTypes.push(`client: Client`);
156
- genericTypes.push(`endpoint: "${relPath}"`);
157
-
158
- if (Response) {
159
- genericTypes.push(`response: ${Response}`);
160
- }
161
- if (Payload) {
162
- genericTypes.push(`payload: ${Payload}`);
163
- }
164
- if (LocalError) {
165
- genericTypes.push(`error: ${LocalError}`);
166
- }
167
- if (QueryParams) {
168
- genericTypes.push(`queryParams: ${QueryParams}`);
169
- }
170
-
171
- return `RequestInstance<{ ${genericTypes.join(", ")} }>`;
153
+ return `Request<${Response}, ${Payload}, ${QueryParams}, ${LocalError}, "${endpoint}", Client>`;
172
154
  }
173
155
 
174
156
  static generateHyperFetchRequest(
@@ -257,18 +239,22 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
257
239
  ) {
258
240
  const { operationId, method, path: relPath } = operation;
259
241
  const normalizedOperationId = normalizeOperationId(operationId);
260
- const pathParametersType = find(exportTypes, {
242
+ const pathParametersType = lodash.find(exportTypes, {
261
243
  schemaRef: `#/paths/${normalizedOperationId}/pathParameters`,
262
244
  })?.path;
263
- const queryParametersType = find(exportTypes, {
245
+ const queryParametersType = lodash.find(exportTypes, {
264
246
  schemaRef: `#/paths/${normalizedOperationId}/queryParameters`,
265
247
  })?.path;
266
- const requestBodyType = find(exportTypes, { schemaRef: `#/paths/${normalizedOperationId}/requestBody` })?.path;
267
- const responseTypePaths = chain(exportTypes)
248
+ const requestBodyType = lodash.find(exportTypes, {
249
+ schemaRef: `#/paths/${normalizedOperationId}/requestBody`,
250
+ })?.path;
251
+ const responseTypePaths = lodash
252
+ .chain(exportTypes)
268
253
  .filter(({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/2`))
269
254
  .map(({ path: responsePath }) => responsePath)
270
255
  .value();
271
- const errorTypePaths = chain(exportTypes)
256
+ const errorTypePaths = lodash
257
+ .chain(exportTypes)
272
258
  .filter(
273
259
  ({ schemaRef }) =>
274
260
  schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/4`) ||
@@ -277,8 +263,8 @@ export const createSdk = <Client extends ClientInstance>(client: Client) => {
277
263
  .map(({ path: errorPath }) => errorPath)
278
264
  .value();
279
265
 
280
- const responseType = !isEmpty(responseTypePaths) ? responseTypePaths.join(" | ") : "any";
281
- const errorType = !isEmpty(errorTypePaths) ? errorTypePaths.join(" | ") : "undefined";
266
+ const responseType = !lodash.isEmpty(responseTypePaths) ? responseTypePaths.join(" | ") : "any";
267
+ const errorType = !lodash.isEmpty(errorTypePaths) ? errorTypePaths.join(" | ") : "undefined";
282
268
 
283
269
  return {
284
270
  id: normalizedOperationId,
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
  import { Command } from "commander";
3
3
  import { z } from "zod";
4
- import path from "path";
5
- import fs from "fs-extra";
4
+ import * as path from "node:path";
5
+ import * as fs from "fs-extra";
6
6
  import { input, select, confirm } from "@inquirer/prompts";
7
7
 
8
8
  import { handleError } from "utils/handle-error";
@@ -1,8 +1,8 @@
1
1
  import { Command } from "commander";
2
2
  import { input, select } from "@inquirer/prompts";
3
3
  import { z } from "zod";
4
- import path from "path";
5
- import { existsSync, mkdir, readFileSync, writeFile } from "fs-extra";
4
+ import * as path from "node:path";
5
+ import * as fs from "fs-extra";
6
6
 
7
7
  import { handleError } from "../utils/handle-error";
8
8
  import { spinner } from "../utils/spinner";
@@ -103,16 +103,16 @@ export const init = new Command()
103
103
  {
104
104
  name: `Initialize API directory at ${relativePath}`,
105
105
  action: async () => {
106
- if (!existsSync(fullPath)) {
107
- await mkdir(fullPath, { recursive: true });
106
+ if (!fs.existsSync(fullPath)) {
107
+ await fs.mkdir(fullPath, { recursive: true });
108
108
  }
109
109
  },
110
110
  },
111
111
  {
112
112
  name: "Setup configuration",
113
113
  action: async (currentConfig) => {
114
- if (existsSync(configPath)) {
115
- const existingConfig = JSON.parse(readFileSync(configPath, "utf8"));
114
+ if (fs.existsSync(configPath)) {
115
+ const existingConfig = JSON.parse(fs.readFileSync(configPath, "utf8"));
116
116
  const { success, error, data } = configSchema.omit({ resolvedPaths: true }).safeParse({
117
117
  ...defaultConfig,
118
118
  ...existingConfig,
@@ -163,7 +163,7 @@ export const init = new Command()
163
163
 
164
164
  configSchema.omit({ resolvedPaths: true }).parse(finalConfig);
165
165
 
166
- await writeFile(configPath, JSON.stringify(finalConfig, null, 2));
166
+ await fs.writeFile(configPath, JSON.stringify(finalConfig, null, 2));
167
167
  },
168
168
  },
169
169
  ];
@@ -1,5 +1,5 @@
1
- import path from "path";
2
- import fs from "fs-extra";
1
+ import * as path from "node:path";
2
+ import * as fs from "fs-extra";
3
3
  import { loadConfig } from "tsconfig-paths";
4
4
 
5
5
  import { highlighter } from "utils/highlighter";
@@ -1,5 +1,5 @@
1
- import path from "path";
2
- import fs from "fs-extra";
1
+ import * as path from "node:path";
2
+ import * as fs from "fs-extra";
3
3
  import { z } from "zod";
4
4
 
5
5
  import { addOptionsSchema } from "commands/add";
@@ -1,5 +1,5 @@
1
- import path from "path";
2
- import fs from "fs-extra";
1
+ import * as path from "node:path";
2
+ import * as fs from "fs-extra";
3
3
  import { z } from "zod";
4
4
 
5
5
  import { generateOptionsSchema } from "commands/generate";