@devbie/apits 0.0.0-stage → 1.0.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 +89 -2
- package/bin/apits +4 -0
- package/dist/cjs/core/cli.d.ts +29 -0
- package/dist/cjs/core/cli.js +396 -0
- package/dist/cjs/core/generator.d.ts +44 -0
- package/dist/cjs/core/generator.js +301 -0
- package/dist/cjs/core/writeRequestClient.d.ts +2 -0
- package/dist/cjs/core/writeRequestClient.js +93 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/types.d.ts +330 -0
- package/dist/cjs/types.js +90 -0
- package/dist/cjs/utils/console.d.ts +16 -0
- package/dist/cjs/utils/console.js +79 -0
- package/dist/cjs/utils/getOutputPath.d.ts +5 -0
- package/dist/cjs/utils/getOutputPath.js +43 -0
- package/dist/cjs/utils/helpers.d.ts +65 -0
- package/dist/cjs/utils/helpers.js +166 -0
- package/dist/cjs/utils/openApiToInterfaces.d.ts +14 -0
- package/dist/cjs/utils/openApiToInterfaces.js +229 -0
- package/dist/cjs/utils/spinner.d.ts +15 -0
- package/dist/cjs/utils/spinner.js +69 -0
- package/dist/cjs/utils/utils.d.ts +56 -0
- package/dist/cjs/utils/utils.js +355 -0
- package/dist/cjs/utils/vtilsLite.d.ts +55 -0
- package/dist/cjs/utils/vtilsLite.js +123 -0
- package/dist/esm/core/cli.d.mts +29 -0
- package/dist/esm/core/cli.mjs +713 -0
- package/dist/esm/core/generator.d.mts +44 -0
- package/dist/esm/core/generator.mjs +463 -0
- package/dist/esm/core/writeRequestClient.d.mts +2 -0
- package/dist/esm/core/writeRequestClient.mjs +54 -0
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/types.d.mts +330 -0
- package/dist/esm/types.mjs +94 -0
- package/dist/esm/utils/console.d.mts +16 -0
- package/dist/esm/utils/console.mjs +65 -0
- package/dist/esm/utils/getOutputPath.d.mts +5 -0
- package/dist/esm/utils/getOutputPath.mjs +12 -0
- package/dist/esm/utils/helpers.d.mts +65 -0
- package/dist/esm/utils/helpers.mjs +226 -0
- package/dist/esm/utils/openApiToInterfaces.d.mts +14 -0
- package/dist/esm/utils/openApiToInterfaces.mjs +326 -0
- package/dist/esm/utils/spinner.d.mts +15 -0
- package/dist/esm/utils/spinner.mjs +58 -0
- package/dist/esm/utils/utils.d.mts +56 -0
- package/dist/esm/utils/utils.mjs +545 -0
- package/dist/esm/utils/vtilsLite.d.mts +55 -0
- package/dist/esm/utils/vtilsLite.mjs +142 -0
- package/package.json +68 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local replacements for the small subset of `vtils` helpers used by this
|
|
3
|
+
* project. `vtils` pulls in several deprecated dependencies (cuid, uuid,
|
|
4
|
+
* tough-cookie@0.12.1 with a ReDoS advisory) and is otherwise unmaintained,
|
|
5
|
+
* so these minimal local implementations keep the dependency tree clean.
|
|
6
|
+
*
|
|
7
|
+
* Behavior matches the upstream vtils functions for the call sites in this
|
|
8
|
+
* repository only; no attempt is made to be a drop-in replacement for the
|
|
9
|
+
* full vtils API.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Remove `undefined` from a type. Equivalent to vtils's `Defined<T>`.
|
|
13
|
+
*/
|
|
14
|
+
export type Defined<T> = Exclude<T, undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Wrap a value in an array unless it is already an array.
|
|
17
|
+
*/
|
|
18
|
+
export declare function castArray<T>(value: T | T[]): T[];
|
|
19
|
+
/**
|
|
20
|
+
* `Array.isArray` alias, kept for import symmetry with the other helpers.
|
|
21
|
+
*/
|
|
22
|
+
export declare const isArray: (arg: any) => arg is any[];
|
|
23
|
+
/**
|
|
24
|
+
* Check whether a value is a plain object (not null, not an array, not a
|
|
25
|
+
* function, not a primitive). Matches vtils `isObject` for the JSON-Schema
|
|
26
|
+
* values used in this project.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isObject(value: any): value is Record<string, any>;
|
|
29
|
+
/**
|
|
30
|
+
* Check whether a value is "empty": null/undefined, empty string, empty
|
|
31
|
+
* array, or an object with no own enumerable string-keyed properties.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isEmpty(value: any): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Iterate over the own enumerable string-keyed properties of an object,
|
|
36
|
+
* invoking `callback(value, key)` for each.
|
|
37
|
+
*/
|
|
38
|
+
export declare function forOwn<T extends object>(obj: T, callback: (value: T[keyof T], key: keyof T) => void): void;
|
|
39
|
+
/**
|
|
40
|
+
* Iterate over a collection (array or object), invoking `callback(value, key)`
|
|
41
|
+
* for each item. For arrays `key` is the numeric index. Types are intentionally
|
|
42
|
+
* loose (matching vtils) because call sites pass heterogeneous OpenAPI data.
|
|
43
|
+
*/
|
|
44
|
+
export declare function each(collection: any, callback: (value: any, key: any) => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* Return the first item in a collection for which `predicate` returns a
|
|
47
|
+
* truthy value, or `undefined` if none matches.
|
|
48
|
+
*/
|
|
49
|
+
export declare function find(collection: any, predicate: (value: any, key: any) => boolean): any;
|
|
50
|
+
/**
|
|
51
|
+
* Tagged-template helper that strips the common leading whitespace from every
|
|
52
|
+
* line. Multi-line interpolations keep the indentation of the line they are
|
|
53
|
+
* embedded on (mirrors vtils `dedent`, which first runs `indent`).
|
|
54
|
+
*/
|
|
55
|
+
export declare function dedent(literals: TemplateStringsArray, ...interpolations: any[]): string;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
/**
|
|
3
|
+
* Local replacements for the small subset of `vtils` helpers used by this
|
|
4
|
+
* project. `vtils` pulls in several deprecated dependencies (cuid, uuid,
|
|
5
|
+
* tough-cookie@0.12.1 with a ReDoS advisory) and is otherwise unmaintained,
|
|
6
|
+
* so these minimal local implementations keep the dependency tree clean.
|
|
7
|
+
*
|
|
8
|
+
* Behavior matches the upstream vtils functions for the call sites in this
|
|
9
|
+
* repository only; no attempt is made to be a drop-in replacement for the
|
|
10
|
+
* full vtils API.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Remove `undefined` from a type. Equivalent to vtils's `Defined<T>`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a value in an array unless it is already an array.
|
|
19
|
+
*/
|
|
20
|
+
export function castArray(value) {
|
|
21
|
+
return Array.isArray(value) ? value : [value];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `Array.isArray` alias, kept for import symmetry with the other helpers.
|
|
26
|
+
*/
|
|
27
|
+
export var isArray = Array.isArray;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check whether a value is a plain object (not null, not an array, not a
|
|
31
|
+
* function, not a primitive). Matches vtils `isObject` for the JSON-Schema
|
|
32
|
+
* values used in this project.
|
|
33
|
+
*/
|
|
34
|
+
export function isObject(value) {
|
|
35
|
+
return value != null && _typeof(value) === "object" && !Array.isArray(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Check whether a value is "empty": null/undefined, empty string, empty
|
|
40
|
+
* array, or an object with no own enumerable string-keyed properties.
|
|
41
|
+
*/
|
|
42
|
+
export function isEmpty(value) {
|
|
43
|
+
if (value == null) return true;
|
|
44
|
+
if (typeof value === "string" || Array.isArray(value)) return value.length === 0;
|
|
45
|
+
if (_typeof(value) === "object") return Object.keys(value).length === 0;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Iterate over the own enumerable string-keyed properties of an object,
|
|
51
|
+
* invoking `callback(value, key)` for each.
|
|
52
|
+
*/
|
|
53
|
+
export function forOwn(obj, callback) {
|
|
54
|
+
if (obj == null) return;
|
|
55
|
+
Object.keys(obj).forEach(function (key) {
|
|
56
|
+
callback(obj[key], key);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Iterate over a collection (array or object), invoking `callback(value, key)`
|
|
62
|
+
* for each item. For arrays `key` is the numeric index. Types are intentionally
|
|
63
|
+
* loose (matching vtils) because call sites pass heterogeneous OpenAPI data.
|
|
64
|
+
*/
|
|
65
|
+
export function each(collection, callback) {
|
|
66
|
+
if (collection == null) return;
|
|
67
|
+
if (Array.isArray(collection)) {
|
|
68
|
+
collection.forEach(function (value, index) {
|
|
69
|
+
return callback(value, index);
|
|
70
|
+
});
|
|
71
|
+
} else if (_typeof(collection) === "object") {
|
|
72
|
+
Object.keys(collection).forEach(function (key) {
|
|
73
|
+
callback(collection[key], key);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Return the first item in a collection for which `predicate` returns a
|
|
80
|
+
* truthy value, or `undefined` if none matches.
|
|
81
|
+
*/
|
|
82
|
+
export function find(collection, predicate) {
|
|
83
|
+
if (collection == null) return undefined;
|
|
84
|
+
if (Array.isArray(collection)) {
|
|
85
|
+
return collection.find(function (value, index) {
|
|
86
|
+
return predicate(value, index);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (_typeof(collection) === "object") {
|
|
90
|
+
for (var _i = 0, _Object$keys = Object.keys(collection); _i < _Object$keys.length; _i++) {
|
|
91
|
+
var _key = _Object$keys[_i];
|
|
92
|
+
var _value = collection[_key];
|
|
93
|
+
if (predicate(_value, _key)) return _value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Tagged-template helper that strips the common leading whitespace from every
|
|
101
|
+
* line. Multi-line interpolations keep the indentation of the line they are
|
|
102
|
+
* embedded on (mirrors vtils `dedent`, which first runs `indent`).
|
|
103
|
+
*/
|
|
104
|
+
export function dedent(literals) {
|
|
105
|
+
// Step 1: replicate vtils `indent` — when an interpolation spans multiple
|
|
106
|
+
// lines, prefix every continuation line with the whitespace that precedes
|
|
107
|
+
// the interpolation point so relative indentation is preserved.
|
|
108
|
+
var text = "";
|
|
109
|
+
for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
|
110
|
+
var literal = literals[i];
|
|
111
|
+
var interpolation = String(i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]);
|
|
112
|
+
var match = literal.match(/(?:^|[\r\n]+)([^\S\r\n]*)$/);
|
|
113
|
+
if (match && match[1]) {
|
|
114
|
+
text += literal + interpolation.replace(/([\r\n]+)(?=[^\r\n])/g, "$1".concat(match[1]));
|
|
115
|
+
} else {
|
|
116
|
+
text += literal + interpolation;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
text += literals[literals.length - 1];
|
|
120
|
+
|
|
121
|
+
// Step 2: find the common leading whitespace across non-empty lines and
|
|
122
|
+
// strip it. Trim leading/trailing empty lines.
|
|
123
|
+
var lines = text.split(/[\r\n]/g);
|
|
124
|
+
var commonLeadingWhitespace = null;
|
|
125
|
+
var firstLineIndex = null;
|
|
126
|
+
var lastLineIndex = null;
|
|
127
|
+
for (var _i2 = 0; _i2 < lines.length; _i2++) {
|
|
128
|
+
var leadingWhitespace = lines[_i2].match(/^\s*/)[0];
|
|
129
|
+
// Skip blank lines (whitespace-only).
|
|
130
|
+
if (leadingWhitespace.length !== lines[_i2].length) {
|
|
131
|
+
lastLineIndex = _i2;
|
|
132
|
+
if (firstLineIndex == null) firstLineIndex = _i2;
|
|
133
|
+
if (commonLeadingWhitespace == null || leadingWhitespace.length < commonLeadingWhitespace.length) {
|
|
134
|
+
commonLeadingWhitespace = leadingWhitespace;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (commonLeadingWhitespace == null) return text;
|
|
139
|
+
return lines.slice(firstLineIndex, lastLineIndex + 1).map(function (line) {
|
|
140
|
+
return line.slice(commonLeadingWhitespace.length);
|
|
141
|
+
}).join("\n");
|
|
142
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devbie/apits",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "zimv <zimudashiren@163.com>",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.mjs",
|
|
7
|
+
"types": "./dist/cjs/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"apits": "./bin/apits"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "father build",
|
|
17
|
+
"gen": "rm -rf ./api & tsx test/gen.ts --type-check false gen",
|
|
18
|
+
"gen:api-1": "tsx test/gen.ts --type-check false gen -n api-1",
|
|
19
|
+
"init": "tsx test/gen.ts --type-check false init",
|
|
20
|
+
"publishOnly": "npm run build",
|
|
21
|
+
"release": "npm run build && standard-version && git push --follow-tags origin master && npm publish",
|
|
22
|
+
"requestTest": "tsx watch test/requestTest.ts --type-check false",
|
|
23
|
+
"test": "tsx test/index.ts",
|
|
24
|
+
"test2": "tsx watch test/json-schema-to-typescript.ts --type-check false"
|
|
25
|
+
},
|
|
26
|
+
"lint-staged": {
|
|
27
|
+
"src/**/*.ts": [
|
|
28
|
+
"eslint --fix"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"chalk": "^4.1.1",
|
|
33
|
+
"change-case": "^3.1.0",
|
|
34
|
+
"form-data": "^3.0.0",
|
|
35
|
+
"fs-extra": "^7.0.1",
|
|
36
|
+
"got": "^11.5.1",
|
|
37
|
+
"js-yaml": "^3.14.1",
|
|
38
|
+
"json-schema": "^0.3.0",
|
|
39
|
+
"json-schema-to-typescript": "15.0.4",
|
|
40
|
+
"json5": "^2.1.0",
|
|
41
|
+
"openapi-types": "^7.0.1",
|
|
42
|
+
"ora": "5.4.1",
|
|
43
|
+
"prettier": "^3.9.9",
|
|
44
|
+
"prompts": "^2.0.4",
|
|
45
|
+
"tsx": "^4.20.5",
|
|
46
|
+
"typescript": "^5",
|
|
47
|
+
"yargs": "^16.2.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/fs-extra": "^5.0.4",
|
|
51
|
+
"@types/js-yaml": "^3.12.0",
|
|
52
|
+
"@types/json-schema": "^7.0.1",
|
|
53
|
+
"@types/json5": "^0.0.30",
|
|
54
|
+
"@types/node": "^18.7.14",
|
|
55
|
+
"@types/prompts": "^1.2.0",
|
|
56
|
+
"@types/yargs": "^16.0.1",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
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"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public",
|
|
68
|
+
"registry": "https://registry.npmjs.org/"
|
|
69
|
+
}
|
|
70
|
+
}
|