@gopowerteam/request 0.1.20 → 0.2.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.
@@ -1,135 +1,107 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
9
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => {
31
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
- return value;
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
33
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
34
27
 
35
- // src/adapters/index.ts
36
- var adapters_exports = {};
37
- __export(adapters_exports, {
38
- AxiosAdapter: () => AxiosAdapter
39
- });
40
- module.exports = __toCommonJS(adapters_exports);
28
+ //#endregion
29
+ let axios = require("axios");
30
+ axios = __toESM(axios);
31
+ let qs = require("qs");
32
+ qs = __toESM(qs);
41
33
 
42
- // src/adapters/axios.adapter.ts
43
- var import_axios = __toESM(require("axios"), 1);
44
- var qs = __toESM(require("qs"), 1);
45
- var _AxiosAdapter = class {
46
- config;
47
- injectConfig(config) {
48
- this.config = config;
49
- }
50
- /**
51
- * 获取Axios实例
52
- */
53
- getAxiosInstance() {
54
- if (!_AxiosAdapter.axiosInstance) {
55
- _AxiosAdapter.axiosInstance = import_axios.default.create({
56
- timeout: this.config?.timeout,
57
- headers: {
58
- "Content-Type": "application/json"
59
- },
60
- paramsSerializer: {
61
- serialize: (params) => qs.stringify(
62
- params,
63
- this.config?.qs || {
64
- arrayFormat: "repeat",
65
- skipNulls: true,
66
- allowDots: true,
67
- encodeValuesOnly: true,
68
- encode: true,
69
- sort: (a, b) => a.localeCompare(b),
70
- filter: (_, value) => ["", void 0, null].some((v) => v === value) ? void 0 : value
71
- }
72
- )
73
- }
74
- });
75
- }
76
- return _AxiosAdapter.axiosInstance;
77
- }
78
- /**
79
- * 发送请求
80
- * @param options 请求参数
81
- * @returns AxiosResponse
82
- */
83
- request({
84
- baseURL,
85
- pathURL,
86
- headers,
87
- method,
88
- paramsQuery,
89
- paramsBody,
90
- extraParams = {}
91
- }) {
92
- const axiosInstance = this.getAxiosInstance();
93
- return axiosInstance.request({
94
- method,
95
- baseURL,
96
- headers,
97
- params: paramsQuery,
98
- data: paramsBody,
99
- url: pathURL,
100
- ...extraParams
101
- });
102
- }
103
- /**
104
- * 转换Response
105
- * @param response
106
- * @returns
107
- */
108
- transformResponse(response) {
109
- return {
110
- data: response.data,
111
- statusText: response.statusText,
112
- status: response.status,
113
- headers: response.headers
114
- };
115
- }
116
- /**
117
- * 转换Response
118
- * @param response
119
- * @returns
120
- */
121
- transformException(exception) {
122
- return {
123
- data: exception.response?.data || {},
124
- statusText: exception.response?.statusText || "",
125
- status: exception.response?.status || 400,
126
- headers: exception.response?.headers || {}
127
- };
128
- }
34
+ //#region src/adapters/axios.adapter.ts
35
+ var AxiosAdapter = class AxiosAdapter {
36
+ static axiosInstance;
37
+ config;
38
+ injectConfig(config) {
39
+ this.config = config;
40
+ }
41
+ /**
42
+ * 获取Axios实例
43
+ */
44
+ getAxiosInstance() {
45
+ if (!AxiosAdapter.axiosInstance) AxiosAdapter.axiosInstance = axios.default.create({
46
+ timeout: this.config?.timeout,
47
+ headers: { "Content-Type": "application/json" },
48
+ paramsSerializer: { serialize: (params) => qs.stringify(params, this.config?.qs || {
49
+ arrayFormat: "repeat",
50
+ skipNulls: true,
51
+ allowDots: true,
52
+ encodeValuesOnly: true,
53
+ encode: true,
54
+ sort: (a, b) => a.localeCompare(b),
55
+ filter: (_, value) => [
56
+ "",
57
+ void 0,
58
+ null
59
+ ].includes(value) ? void 0 : value
60
+ }) }
61
+ });
62
+ return AxiosAdapter.axiosInstance;
63
+ }
64
+ /**
65
+ * 发送请求
66
+ * @returns AxiosResponse
67
+ */
68
+ request({ baseURL, pathURL, headers, method, paramsQuery, paramsBody, extraParams = {} }) {
69
+ return this.getAxiosInstance().request({
70
+ method,
71
+ baseURL,
72
+ headers,
73
+ params: paramsQuery,
74
+ data: paramsBody,
75
+ url: pathURL,
76
+ ...extraParams
77
+ });
78
+ }
79
+ /**
80
+ * 转换Response
81
+ * @param response
82
+ * @returns AdapterResponse
83
+ */
84
+ transformResponse(response) {
85
+ return {
86
+ data: response.data,
87
+ statusText: response.statusText,
88
+ status: response.status,
89
+ headers: response.headers
90
+ };
91
+ }
92
+ /**
93
+ * 转换Response
94
+ * @returns AdapterResponse
95
+ */
96
+ transformException(exception) {
97
+ return {
98
+ data: exception.response?.data || {},
99
+ statusText: exception.response?.statusText || "",
100
+ status: exception.response?.status || 400,
101
+ headers: exception.response?.headers || {}
102
+ };
103
+ }
129
104
  };
130
- var AxiosAdapter = _AxiosAdapter;
131
- __publicField(AxiosAdapter, "axiosInstance");
132
- // Annotate the CommonJS export names for ESM import in node:
133
- 0 && (module.exports = {
134
- AxiosAdapter
135
- });
105
+
106
+ //#endregion
107
+ exports.AxiosAdapter = AxiosAdapter;
@@ -0,0 +1,39 @@
1
+ import { a as RequestSetupConfig, i as RequestAdapterOptions, r as RequestAdapter, t as AdapterResponse } from "../request-adapter.interface-Cr5s4kIp.cjs";
2
+ import { AxiosError, AxiosResponse } from "axios";
3
+
4
+ //#region src/adapters/axios.adapter.d.ts
5
+ declare class AxiosAdapter implements RequestAdapter {
6
+ private static axiosInstance;
7
+ private config;
8
+ injectConfig(config: RequestSetupConfig): void;
9
+ /**
10
+ * 获取Axios实例
11
+ */
12
+ private getAxiosInstance;
13
+ /**
14
+ * 发送请求
15
+ * @returns AxiosResponse
16
+ */
17
+ request({
18
+ baseURL,
19
+ pathURL,
20
+ headers,
21
+ method,
22
+ paramsQuery,
23
+ paramsBody,
24
+ extraParams
25
+ }: RequestAdapterOptions): Promise<AxiosResponse<any, any, {}>>;
26
+ /**
27
+ * 转换Response
28
+ * @param response
29
+ * @returns AdapterResponse
30
+ */
31
+ transformResponse(response: AxiosResponse): AdapterResponse;
32
+ /**
33
+ * 转换Response
34
+ * @returns AdapterResponse
35
+ */
36
+ transformException(exception: AxiosError): AdapterResponse;
37
+ }
38
+ //#endregion
39
+ export { AxiosAdapter };
@@ -0,0 +1,39 @@
1
+ import { a as RequestAdapter, o as RequestAdapterOptions, r as AdapterResponse, s as RequestSetupConfig } from "../index-hNav9Ikc.mjs";
2
+ import { AxiosError, AxiosResponse } from "axios";
3
+
4
+ //#region src/adapters/axios.adapter.d.ts
5
+ declare class AxiosAdapter implements RequestAdapter {
6
+ private static axiosInstance;
7
+ private config;
8
+ injectConfig(config: RequestSetupConfig): void;
9
+ /**
10
+ * 获取Axios实例
11
+ */
12
+ private getAxiosInstance;
13
+ /**
14
+ * 发送请求
15
+ * @returns AxiosResponse
16
+ */
17
+ request({
18
+ baseURL,
19
+ pathURL,
20
+ headers,
21
+ method,
22
+ paramsQuery,
23
+ paramsBody,
24
+ extraParams
25
+ }: RequestAdapterOptions): Promise<AxiosResponse<any, any, {}>>;
26
+ /**
27
+ * 转换Response
28
+ * @param response
29
+ * @returns AdapterResponse
30
+ */
31
+ transformResponse(response: AxiosResponse): AdapterResponse;
32
+ /**
33
+ * 转换Response
34
+ * @returns AdapterResponse
35
+ */
36
+ transformException(exception: AxiosError): AdapterResponse;
37
+ }
38
+ //#endregion
39
+ export { AxiosAdapter };
@@ -0,0 +1,77 @@
1
+ import axios from "axios";
2
+ import * as qs from "qs";
3
+
4
+ //#region src/adapters/axios.adapter.ts
5
+ var AxiosAdapter = class AxiosAdapter {
6
+ static axiosInstance;
7
+ config;
8
+ injectConfig(config) {
9
+ this.config = config;
10
+ }
11
+ /**
12
+ * 获取Axios实例
13
+ */
14
+ getAxiosInstance() {
15
+ if (!AxiosAdapter.axiosInstance) AxiosAdapter.axiosInstance = axios.create({
16
+ timeout: this.config?.timeout,
17
+ headers: { "Content-Type": "application/json" },
18
+ paramsSerializer: { serialize: (params) => qs.stringify(params, this.config?.qs || {
19
+ arrayFormat: "repeat",
20
+ skipNulls: true,
21
+ allowDots: true,
22
+ encodeValuesOnly: true,
23
+ encode: true,
24
+ sort: (a, b) => a.localeCompare(b),
25
+ filter: (_, value) => [
26
+ "",
27
+ void 0,
28
+ null
29
+ ].includes(value) ? void 0 : value
30
+ }) }
31
+ });
32
+ return AxiosAdapter.axiosInstance;
33
+ }
34
+ /**
35
+ * 发送请求
36
+ * @returns AxiosResponse
37
+ */
38
+ request({ baseURL, pathURL, headers, method, paramsQuery, paramsBody, extraParams = {} }) {
39
+ return this.getAxiosInstance().request({
40
+ method,
41
+ baseURL,
42
+ headers,
43
+ params: paramsQuery,
44
+ data: paramsBody,
45
+ url: pathURL,
46
+ ...extraParams
47
+ });
48
+ }
49
+ /**
50
+ * 转换Response
51
+ * @param response
52
+ * @returns AdapterResponse
53
+ */
54
+ transformResponse(response) {
55
+ return {
56
+ data: response.data,
57
+ statusText: response.statusText,
58
+ status: response.status,
59
+ headers: response.headers
60
+ };
61
+ }
62
+ /**
63
+ * 转换Response
64
+ * @returns AdapterResponse
65
+ */
66
+ transformException(exception) {
67
+ return {
68
+ data: exception.response?.data || {},
69
+ statusText: exception.response?.statusText || "",
70
+ status: exception.response?.status || 400,
71
+ headers: exception.response?.headers || {}
72
+ };
73
+ }
74
+ };
75
+
76
+ //#endregion
77
+ export { AxiosAdapter };
@@ -0,0 +1,112 @@
1
+ import { IStringifyOptions } from "qs";
2
+
3
+ //#region src/interfaces/request-send.interface.d.ts
4
+ /**
5
+ * 请求方法类型
6
+ */
7
+ declare enum RequestMethod {
8
+ Get = "GET",
9
+ Post = "POST",
10
+ Put = "PUT",
11
+ Delete = "DELETE",
12
+ Options = "OPTIONS",
13
+ Head = "HEAD",
14
+ Patch = "PATCH"
15
+ }
16
+ interface RequestSendOptions {
17
+ service?: string;
18
+ path: string;
19
+ method: RequestMethod | string;
20
+ headers?: Record<string, string>;
21
+ paramsPath?: Record<string, string | number>;
22
+ paramsQuery?: Record<string, any>;
23
+ paramsBody?: any;
24
+ }
25
+ //#endregion
26
+ //#region src/interfaces/request-plugin.interface.d.ts
27
+ /**
28
+ * 请求插件
29
+ */
30
+ interface RequestPlugin {
31
+ before?: (options: RequestSendOptions, appendParams: (params: Record<string, any>) => void) => void | Promise<void>;
32
+ after?: (response: AdapterResponse, options: RequestSendOptions) => void;
33
+ catch?: (response: AdapterResponse, options: RequestSendOptions) => void;
34
+ }
35
+ declare enum PluginLifecycle {
36
+ before = "before",
37
+ after = "after",
38
+ catch = "catch"
39
+ }
40
+ type RequestLifecycle = PluginLifecycle.before;
41
+ type ResponseLifecycle = PluginLifecycle.after | PluginLifecycle.catch;
42
+ //#endregion
43
+ //#region src/interfaces/response-interceptor.interface.d.ts
44
+ interface ResponseInterceptor {
45
+ exec: (response: AdapterResponse) => any;
46
+ }
47
+ //#endregion
48
+ //#region src/interfaces/request-setup.interface.d.ts
49
+ interface RequestSetupConfig {
50
+ gateway: string;
51
+ timeout?: number;
52
+ qs?: IStringifyOptions;
53
+ adapter?: RequestAdapter;
54
+ interceptors: {
55
+ status: ResponseInterceptor;
56
+ success: ResponseInterceptor;
57
+ error: ResponseInterceptor;
58
+ exception: ResponseInterceptor;
59
+ };
60
+ plugins: RequestPlugin[];
61
+ }
62
+ //#endregion
63
+ //#region src/interfaces/request-adapter.interface.d.ts
64
+ interface RequestAdapter {
65
+ /**
66
+ * 注入全局配置文件
67
+ * @param config
68
+ * @returns
69
+ */
70
+ injectConfig?: (config: RequestSetupConfig) => void;
71
+ /**
72
+ * 发送请求
73
+ */
74
+ request: (options: RequestAdapterOptions) => Promise<any>;
75
+ /**
76
+ * 转换Response
77
+ * @param response
78
+ */
79
+ transformResponse: (response: any) => AdapterResponse;
80
+ /**
81
+ * 转换Exception
82
+ * @param response
83
+ */
84
+ transformException: (response: any) => AdapterResponse;
85
+ }
86
+ interface RequestAdapterOptions {
87
+ baseURL: string;
88
+ pathURL: string;
89
+ headers: Record<string, string>;
90
+ method: RequestMethod | string;
91
+ paramsQuery?: Record<string, any>;
92
+ paramsBody?: any;
93
+ extraParams?: any;
94
+ }
95
+ interface AdapterResponse {
96
+ data: Record<string, any>;
97
+ status: number;
98
+ statusText: string;
99
+ headers: AdapterResponseHeaders;
100
+ }
101
+ type AdapterResponseHeaders = Record<string, string | string[] | number | boolean | undefined>;
102
+ //#endregion
103
+ //#region src/interfaces/request-generate.interface.d.ts
104
+ declare enum RequestGenerateType {
105
+ Request = "TO_REQUEST",
106
+ URL = "TO_URL"
107
+ }
108
+ interface RequestGenerateOptions {
109
+ type?: RequestGenerateType;
110
+ }
111
+ //#endregion
112
+ export { RequestAdapter as a, ResponseInterceptor as c, RequestPlugin as d, ResponseLifecycle as f, AdapterResponseHeaders as i, PluginLifecycle as l, RequestSendOptions as m, RequestGenerateType as n, RequestAdapterOptions as o, RequestMethod as p, AdapterResponse as r, RequestSetupConfig as s, RequestGenerateOptions as t, RequestLifecycle as u };