@1szx1/vite-plugin-swagger2ts 1.0.6 → 1.0.7
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/adapters/index.d.ts +13 -0
- package/dist/adapters/index.js +51 -0
- package/dist/adapters/index.mjs +26 -0
- package/dist/chunk-TTFRSOOU.mjs +38 -0
- package/dist/index.js +1255 -1267
- package/dist/index.mjs +180 -222
- package/package.json +4 -3
- package/src/adapters/axios.ts +41 -0
- package/src/adapters/index.ts +1 -0
- package/src/adapters/utils.ts +5 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
|
|
3
|
+
type Get<T, K> = T[K & keyof T];
|
|
4
|
+
|
|
5
|
+
declare function useRequest<T>(httpInstance: AxiosInstance): {
|
|
6
|
+
request: <U extends string & keyof T, M extends string & keyof T[U]>(url: U, method: M, param?: Get<T[U][M]["param" & keyof T[U][M]], M extends "get" ? "query" : "body"> | undefined, config?: (AxiosRequestConfig<any> & {
|
|
7
|
+
data?: Get<T[U][M]["param" & keyof T[U][M]], "body"> | undefined;
|
|
8
|
+
params?: Get<T[U][M]["param" & keyof T[U][M]], "query"> | undefined;
|
|
9
|
+
path?: Get<T[U][M]["param" & keyof T[U][M]], "path"> | undefined;
|
|
10
|
+
}) | undefined) => Promise<T[U][M]["response" & keyof T[U][M]]>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { useRequest };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/adapters/index.ts
|
|
21
|
+
var adapters_exports = {};
|
|
22
|
+
__export(adapters_exports, {
|
|
23
|
+
useRequest: () => useRequest
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(adapters_exports);
|
|
26
|
+
|
|
27
|
+
// src/adapters/utils.ts
|
|
28
|
+
function mergeUrlParam(url, paths) {
|
|
29
|
+
return url.replace(/{(.*?)}/g, (_, key) => paths[key]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/adapters/axios.ts
|
|
33
|
+
function useRequest(httpInstance) {
|
|
34
|
+
async function request(url, method, param, config) {
|
|
35
|
+
if (config?.path)
|
|
36
|
+
url = mergeUrlParam(url, config.path);
|
|
37
|
+
const response = await httpInstance.request({
|
|
38
|
+
url,
|
|
39
|
+
method,
|
|
40
|
+
params: method === "get" ? param : config?.params,
|
|
41
|
+
data: method !== "get" ? param : config?.data,
|
|
42
|
+
...config
|
|
43
|
+
});
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
46
|
+
return { request };
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
useRequest
|
|
51
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "../chunk-TTFRSOOU.mjs";
|
|
2
|
+
|
|
3
|
+
// src/adapters/utils.ts
|
|
4
|
+
function mergeUrlParam(url, paths) {
|
|
5
|
+
return url.replace(/{(.*?)}/g, (_, key) => paths[key]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/adapters/axios.ts
|
|
9
|
+
function useRequest(httpInstance) {
|
|
10
|
+
async function request(url, method, param, config) {
|
|
11
|
+
if (config?.path)
|
|
12
|
+
url = mergeUrlParam(url, config.path);
|
|
13
|
+
const response = await httpInstance.request({
|
|
14
|
+
url,
|
|
15
|
+
method,
|
|
16
|
+
params: method === "get" ? param : config?.params,
|
|
17
|
+
data: method !== "get" ? param : config?.data,
|
|
18
|
+
...config
|
|
19
|
+
});
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
return { request };
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
useRequest
|
|
26
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined")
|
|
11
|
+
return require.apply(this, arguments);
|
|
12
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
__require,
|
|
36
|
+
__commonJS,
|
|
37
|
+
__toESM
|
|
38
|
+
};
|