@devbie/apits 1.0.3 → 1.0.4
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/cjs/core/generator.js +3 -3
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/utils/helpers.js +1 -1
- package/dist/esm/core/cli.mjs +1 -0
- package/dist/esm/core/generator.mjs +1 -2
- package/dist/esm/core/writeRequestClient.mjs +0 -1
- package/dist/esm/types.d.mts +1 -1
- package/dist/esm/utils/getOutputPath.mjs +0 -1
- package/dist/esm/utils/helpers.mjs +1 -1
- package/dist/esm/utils/utils.mjs +1 -0
- package/package.json +14 -17
|
@@ -45,7 +45,7 @@ var import_types = require("../types.js");
|
|
|
45
45
|
var import_utils = require("../utils/utils.js");
|
|
46
46
|
var import_getOutputPath = require("../utils/getOutputPath.js");
|
|
47
47
|
var import_writeRequestClient = __toESM(require("./writeRequestClient.js"));
|
|
48
|
-
function defaultClientImportTemplate(
|
|
48
|
+
function defaultClientImportTemplate(_config) {
|
|
49
49
|
return `import request from './request'`;
|
|
50
50
|
}
|
|
51
51
|
var getDataKeySetStr = (method) => {
|
|
@@ -174,9 +174,9 @@ var Generator = class {
|
|
|
174
174
|
})
|
|
175
175
|
);
|
|
176
176
|
const allApi = await (0, import_openApiToInterfaces.openApiToInterfaces)(openApiV3Json);
|
|
177
|
-
|
|
177
|
+
const interfaceList = allApi.interfaces;
|
|
178
178
|
const categoryCode = [...componentsCode];
|
|
179
|
-
for (
|
|
179
|
+
for (const interfaceInfo of interfaceList) {
|
|
180
180
|
const code = await this.generateInterfaceCode(
|
|
181
181
|
{
|
|
182
182
|
...this.config,
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -302,7 +302,7 @@ export interface RequestFunctionParams extends RequestConfig {
|
|
|
302
302
|
getFormData: () => FormData;
|
|
303
303
|
}
|
|
304
304
|
/** Additional parameters of the request function */
|
|
305
|
-
export type RequestFunctionRestArgs<T extends
|
|
305
|
+
export type RequestFunctionRestArgs<T extends (...args: any[]) => any> = T extends (payload: any, ...args: infer R) => any ? R : never;
|
|
306
306
|
/** Property definition */
|
|
307
307
|
export interface PropDefinition {
|
|
308
308
|
/** Property name */
|
|
@@ -121,7 +121,7 @@ function prepare(requestConfig, requestData) {
|
|
|
121
121
|
const useNodeFormData = !useNativeFormData && // https://github.com/fjc0k/vtils/blob/master/src/utils/inNodeJS.ts
|
|
122
122
|
typeof global === "object" && typeof global.process === "object" && typeof global.process.versions === "object" && global.process.versions.node != null;
|
|
123
123
|
const UniFormData = useNativeFormData ? FormData : useNodeFormData ? (
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- isomorphic shim: conditional CJS require when native FormData is unavailable
|
|
125
125
|
require("form-data")
|
|
126
126
|
) : void 0;
|
|
127
127
|
if (!UniFormData) {
|
package/dist/esm/core/cli.mjs
CHANGED
|
@@ -169,6 +169,7 @@ function loadConfigFile(discovered) {
|
|
|
169
169
|
if (kind === "ts") {
|
|
170
170
|
var _mod$default;
|
|
171
171
|
// tsx is registered at module load time.
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- user config files are loaded dynamically at runtime
|
|
172
173
|
var mod = require(filePath);
|
|
173
174
|
return normalizeConfig((_mod$default = mod.default) !== null && _mod$default !== void 0 ? _mod$default : mod);
|
|
174
175
|
}
|
|
@@ -33,7 +33,7 @@ import { getRequestDataJsonSchema, getResponseDataJsonSchema, jsonSchemaToTsCode
|
|
|
33
33
|
import { getOutputFilePath } from "../utils/getOutputPath.mjs";
|
|
34
34
|
import writeRequestClient from "./writeRequestClient.mjs";
|
|
35
35
|
// Default client import snippet placed at the top of generated files.
|
|
36
|
-
function defaultClientImportTemplate(
|
|
36
|
+
function defaultClientImportTemplate(_config) {
|
|
37
37
|
return "import request from './request'";
|
|
38
38
|
}
|
|
39
39
|
var getDataKeySetStr = function getDataKeySetStr(method) {
|
|
@@ -47,7 +47,6 @@ var getDataKeySetStr = function getDataKeySetStr(method) {
|
|
|
47
47
|
// request function can substitute path params from the incoming data object.
|
|
48
48
|
function handlePathParam(path) {
|
|
49
49
|
if (path.match(/\{(\w+)\}/)) {
|
|
50
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
51
50
|
return "`".concat(path.replace(/\{(\w+)\}/g, "${data.$1}"), "`");
|
|
52
51
|
}
|
|
53
52
|
return JSON.stringify(path);
|
|
@@ -4,7 +4,6 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
|
|
|
4
4
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
5
5
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
6
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
8
7
|
import fs from "fs-extra";
|
|
9
8
|
import { dedent } from "../utils/vtilsLite.mjs";
|
|
10
9
|
import { getOutputFilePath } from "../utils/getOutputPath.mjs";
|
package/dist/esm/types.d.mts
CHANGED
|
@@ -302,7 +302,7 @@ export interface RequestFunctionParams extends RequestConfig {
|
|
|
302
302
|
getFormData: () => FormData;
|
|
303
303
|
}
|
|
304
304
|
/** Additional parameters of the request function */
|
|
305
|
-
export type RequestFunctionRestArgs<T extends
|
|
305
|
+
export type RequestFunctionRestArgs<T extends (...args: any[]) => any> = T extends (payload: any, ...args: infer R) => any ? R : never;
|
|
306
306
|
/** Property definition */
|
|
307
307
|
export interface PropDefinition {
|
|
308
308
|
/** Property name */
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Resolve the output file path for a generated file.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6
5
|
import path from "path";
|
|
7
6
|
export var getOutputFilePath = function getOutputFilePath(config, file) {
|
|
8
7
|
var _path$parse = path.parse(config.output || ""),
|
|
@@ -161,7 +161,7 @@ export function prepare(requestConfig, requestData) {
|
|
|
161
161
|
// https://github.com/fjc0k/vtils/blob/master/src/utils/inNodeJS.ts
|
|
162
162
|
(typeof global === "undefined" ? "undefined" : _typeof(global)) === "object" && _typeof(global.process) === "object" && _typeof(global.process.versions) === "object" && global.process.versions.node != null;
|
|
163
163
|
var UniFormData = useNativeFormData ? FormData : useNodeFormData ?
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- isomorphic shim: conditional CJS require when native FormData is unavailable
|
|
165
165
|
require("form-data") : undefined;
|
|
166
166
|
if (!UniFormData) {
|
|
167
167
|
throw new Error("FormData is not supported in the current environment");
|
package/dist/esm/utils/utils.mjs
CHANGED
|
@@ -94,6 +94,7 @@ export function processJsonSchema(jsonSchema) {
|
|
|
94
94
|
|
|
95
95
|
// Mock.toJSONSchema produces `properties` as an array, but JSONSchema4 expects an object.
|
|
96
96
|
if (isArray(jsonSchema.properties)) {
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- narrowing the array to the object shape here is intentional and type-safe at runtime
|
|
97
98
|
// @ts-ignore
|
|
98
99
|
jsonSchema.properties = jsonSchema.properties.reduce(function (props, js) {
|
|
99
100
|
props[js.name] = js;
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devbie/apits",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"author": "
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"author": "worldzhy",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/worldzhy/newbie.git",
|
|
9
|
+
"directory": "packages/apits"
|
|
10
|
+
},
|
|
5
11
|
"main": "./dist/cjs/index.js",
|
|
6
12
|
"module": "./dist/esm/index.mjs",
|
|
7
13
|
"types": "./dist/cjs/index.d.ts",
|
|
@@ -14,20 +20,18 @@
|
|
|
14
20
|
],
|
|
15
21
|
"scripts": {
|
|
16
22
|
"build": "father build",
|
|
23
|
+
"format": "prettier --write .",
|
|
24
|
+
"format:check": "prettier --check .",
|
|
17
25
|
"gen": "rm -rf ./api & tsx test/gen.ts --type-check false gen",
|
|
18
26
|
"gen:api-1": "tsx test/gen.ts --type-check false gen -n api-1",
|
|
19
27
|
"init": "tsx test/gen.ts --type-check false init",
|
|
28
|
+
"lint": "eslint",
|
|
29
|
+
"lint:fix": "eslint --fix",
|
|
20
30
|
"publishOnly": "npm run build",
|
|
21
|
-
"release": "npm run build && standard-version && git push --follow-tags origin master && npm publish",
|
|
22
31
|
"requestTest": "tsx watch test/requestTest.ts --type-check false",
|
|
23
32
|
"test": "tsx test/index.ts",
|
|
24
33
|
"test2": "tsx watch test/json-schema-to-typescript.ts --type-check false"
|
|
25
34
|
},
|
|
26
|
-
"lint-staged": {
|
|
27
|
-
"src/**/*.ts": [
|
|
28
|
-
"eslint --fix"
|
|
29
|
-
]
|
|
30
|
-
},
|
|
31
35
|
"dependencies": {
|
|
32
36
|
"chalk": "^4.1.1",
|
|
33
37
|
"change-case": "^3.1.0",
|
|
@@ -52,16 +56,9 @@
|
|
|
52
56
|
"@types/json-schema": "^7.0.1",
|
|
53
57
|
"@types/json5": "^0.0.30",
|
|
54
58
|
"@types/node": "^18.7.14",
|
|
55
|
-
"@types/prompts": "^1.
|
|
59
|
+
"@types/prompts": "^1.0.4",
|
|
56
60
|
"@types/yargs": "^16.0.1",
|
|
57
|
-
"
|
|
58
|
-
"@typescript-eslint/parser": "^6.21.0",
|
|
59
|
-
"eslint": "^7.16.0",
|
|
60
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
61
|
-
"eslint-config-prettier": "^9.1.2",
|
|
62
|
-
"eslint-plugin-prettier": "^5.5.7",
|
|
63
|
-
"father": "^4",
|
|
64
|
-
"standard-version": "^4.4.0"
|
|
61
|
+
"father": "^4"
|
|
65
62
|
},
|
|
66
63
|
"publishConfig": {
|
|
67
64
|
"access": "public",
|