@mix-space-lts/api-client 2.4.2 → 2.4.3

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.
@@ -0,0 +1,25 @@
1
+ //#region interfaces/instance.d.ts
2
+ interface RequestOptions {
3
+ method?: string;
4
+ data?: Record<string, any>;
5
+ params?: Record<string, any> | URLSearchParams;
6
+ headers?: Record<string, string>;
7
+ [key: string]: any;
8
+ }
9
+ //#endregion
10
+ //#region interfaces/adapter.d.ts
11
+ type IAdaptorRequestResponseType<P> = Promise<Record<string, any> & {
12
+ data: P;
13
+ }>;
14
+ type IRequestAdapter<T = any, Response = undefined> = Readonly<(Response extends undefined ? {} : {
15
+ responseWrapper: Response;
16
+ }) & {
17
+ default: T;
18
+ get: <P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>) => IAdaptorRequestResponseType<P>;
19
+ post: <P = unknown>(url: string, options: Partial<RequestOptions>) => IAdaptorRequestResponseType<P>;
20
+ patch: <P = unknown>(url: string, options: Partial<RequestOptions>) => IAdaptorRequestResponseType<P>;
21
+ delete: <P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>) => IAdaptorRequestResponseType<P>;
22
+ put: <P = unknown>(url: string, options: Partial<RequestOptions>) => IAdaptorRequestResponseType<P>;
23
+ }>;
24
+ //#endregion
25
+ export { IRequestAdapter as n, RequestOptions as r, IAdaptorRequestResponseType as t };
@@ -0,0 +1,25 @@
1
+ //#region interfaces/instance.d.ts
2
+ interface RequestOptions {
3
+ method?: string;
4
+ data?: Record<string, any>;
5
+ params?: Record<string, any> | URLSearchParams;
6
+ headers?: Record<string, string>;
7
+ [key: string]: any;
8
+ }
9
+ //#endregion
10
+ //#region interfaces/adapter.d.ts
11
+ type IAdaptorRequestResponseType<P> = Promise<Record<string, any> & {
12
+ data: P;
13
+ }>;
14
+ type IRequestAdapter<T = any, Response = undefined> = Readonly<(Response extends undefined ? {} : {
15
+ responseWrapper: Response;
16
+ }) & {
17
+ default: T;
18
+ get: <P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>) => IAdaptorRequestResponseType<P>;
19
+ post: <P = unknown>(url: string, options: Partial<RequestOptions>) => IAdaptorRequestResponseType<P>;
20
+ patch: <P = unknown>(url: string, options: Partial<RequestOptions>) => IAdaptorRequestResponseType<P>;
21
+ delete: <P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>) => IAdaptorRequestResponseType<P>;
22
+ put: <P = unknown>(url: string, options: Partial<RequestOptions>) => IAdaptorRequestResponseType<P>;
23
+ }>;
24
+ //#endregion
25
+ export { IRequestAdapter as n, RequestOptions as r, IAdaptorRequestResponseType as t };
@@ -0,0 +1,63 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
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;
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));
27
+
28
+ //#endregion
29
+ let axios = require("axios");
30
+ axios = __toESM(axios);
31
+
32
+ //#region adaptors/axios.ts
33
+ const $http = /* @__PURE__ */ axios.default.create({});
34
+ const axiosAdaptor = Object.preventExtensions({
35
+ get default() {
36
+ return $http;
37
+ },
38
+ responseWrapper: {},
39
+ get(url, options) {
40
+ return $http.get(url, options);
41
+ },
42
+ post(url, options) {
43
+ const { data, ...config } = options || {};
44
+ return $http.post(url, data, config);
45
+ },
46
+ put(url, options) {
47
+ const { data, ...config } = options || {};
48
+ return $http.put(url, data, config);
49
+ },
50
+ delete(url, options) {
51
+ const { ...config } = options || {};
52
+ return $http.delete(url, config);
53
+ },
54
+ patch(url, options) {
55
+ const { data, ...config } = options || {};
56
+ return $http.patch(url, data, config);
57
+ }
58
+ });
59
+
60
+ //#endregion
61
+ exports.__toESM = __toESM;
62
+ exports.axiosAdaptor = axiosAdaptor;
63
+ exports.default = axiosAdaptor;
@@ -0,0 +1,7 @@
1
+ import { n as IRequestAdapter } from "../adapter-DLzJOGbI.cjs";
2
+ import { AxiosInstance, AxiosResponse } from "axios";
3
+
4
+ //#region adaptors/axios.d.ts
5
+ declare const axiosAdaptor: IRequestAdapter<AxiosInstance, AxiosResponse<unknown>>;
6
+ //#endregion
7
+ export { axiosAdaptor, axiosAdaptor as default };
@@ -0,0 +1,7 @@
1
+ import { n as IRequestAdapter } from "../adapter-D1g1obyM.mjs";
2
+ import { AxiosInstance, AxiosResponse } from "axios";
3
+
4
+ //#region adaptors/axios.d.ts
5
+ declare const axiosAdaptor: IRequestAdapter<AxiosInstance, AxiosResponse<unknown>>;
6
+ //#endregion
7
+ export { axiosAdaptor, axiosAdaptor as default };
@@ -0,0 +1,32 @@
1
+ import axios from "axios";
2
+
3
+ //#region adaptors/axios.ts
4
+ const $http = /* @__PURE__ */ axios.create({});
5
+ const axiosAdaptor = Object.preventExtensions({
6
+ get default() {
7
+ return $http;
8
+ },
9
+ responseWrapper: {},
10
+ get(url, options) {
11
+ return $http.get(url, options);
12
+ },
13
+ post(url, options) {
14
+ const { data, ...config } = options || {};
15
+ return $http.post(url, data, config);
16
+ },
17
+ put(url, options) {
18
+ const { data, ...config } = options || {};
19
+ return $http.put(url, data, config);
20
+ },
21
+ delete(url, options) {
22
+ const { ...config } = options || {};
23
+ return $http.delete(url, config);
24
+ },
25
+ patch(url, options) {
26
+ const { data, ...config } = options || {};
27
+ return $http.patch(url, data, config);
28
+ }
29
+ });
30
+
31
+ //#endregion
32
+ export { axiosAdaptor, axiosAdaptor as default };
@@ -0,0 +1,77 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region adaptors/fetch.ts
4
+ const jsonDataAttachResponse = async (response) => {
5
+ const cloned = response.clone();
6
+ let data = {};
7
+ switch (cloned.headers.get("Content-Type")?.split(";")[0].trim() || "") {
8
+ case "application/json":
9
+ data = await cloned.json();
10
+ break;
11
+ default:
12
+ data = await cloned.text();
13
+ break;
14
+ }
15
+ const nextResponse = Object.assign({}, response, { data });
16
+ if (response.ok) return nextResponse;
17
+ else return Promise.reject(nextResponse);
18
+ };
19
+ /**
20
+ * transform options to fetch options
21
+ * @param options
22
+ * @returns
23
+ */
24
+ const parseOptions = (options) => {
25
+ const { headers = {}, data, ...rest } = options;
26
+ if (typeof data === "object" && !(data instanceof FormData)) {
27
+ const key = "Content-Type";
28
+ const value = "application/json";
29
+ if (Array.isArray(headers)) headers.push([key, value]);
30
+ else if (Object.prototype.toString.call(headers) === "[object Object]") headers[key] = value;
31
+ else if (headers instanceof Headers) headers.append(key, value);
32
+ }
33
+ return {
34
+ headers,
35
+ body: typeof data === "object" ? JSON.stringify(data) : data,
36
+ ...rest
37
+ };
38
+ };
39
+ const fetchAdaptor = Object.preventExtensions({
40
+ get default() {
41
+ return fetch;
42
+ },
43
+ async delete(url, options) {
44
+ return jsonDataAttachResponse(await fetch(url, {
45
+ ...options,
46
+ method: "DELETE"
47
+ }));
48
+ },
49
+ async get(url, options) {
50
+ return jsonDataAttachResponse(await fetch(url, {
51
+ ...options,
52
+ method: "GET"
53
+ }));
54
+ },
55
+ async patch(url, options) {
56
+ return jsonDataAttachResponse(await fetch(url, {
57
+ ...parseOptions(options),
58
+ method: "PATCH"
59
+ }));
60
+ },
61
+ async post(url, options) {
62
+ return jsonDataAttachResponse(await fetch(url, {
63
+ ...parseOptions(options),
64
+ method: "POST"
65
+ }));
66
+ },
67
+ async put(url, options) {
68
+ return jsonDataAttachResponse(await fetch(url, {
69
+ ...parseOptions(options),
70
+ method: "PUT"
71
+ }));
72
+ },
73
+ responseWrapper: {}
74
+ });
75
+
76
+ //#endregion
77
+ exports.fetchAdaptor = fetchAdaptor;
@@ -0,0 +1,6 @@
1
+ import { n as IRequestAdapter } from "../adapter-DLzJOGbI.cjs";
2
+
3
+ //#region adaptors/fetch.d.ts
4
+ declare const fetchAdaptor: IRequestAdapter<typeof fetch>;
5
+ //#endregion
6
+ export { fetchAdaptor };
@@ -0,0 +1,6 @@
1
+ import { n as IRequestAdapter } from "../adapter-D1g1obyM.mjs";
2
+
3
+ //#region adaptors/fetch.d.ts
4
+ declare const fetchAdaptor: IRequestAdapter<typeof fetch>;
5
+ //#endregion
6
+ export { fetchAdaptor };
@@ -0,0 +1,75 @@
1
+ //#region adaptors/fetch.ts
2
+ const jsonDataAttachResponse = async (response) => {
3
+ const cloned = response.clone();
4
+ let data = {};
5
+ switch (cloned.headers.get("Content-Type")?.split(";")[0].trim() || "") {
6
+ case "application/json":
7
+ data = await cloned.json();
8
+ break;
9
+ default:
10
+ data = await cloned.text();
11
+ break;
12
+ }
13
+ const nextResponse = Object.assign({}, response, { data });
14
+ if (response.ok) return nextResponse;
15
+ else return Promise.reject(nextResponse);
16
+ };
17
+ /**
18
+ * transform options to fetch options
19
+ * @param options
20
+ * @returns
21
+ */
22
+ const parseOptions = (options) => {
23
+ const { headers = {}, data, ...rest } = options;
24
+ if (typeof data === "object" && !(data instanceof FormData)) {
25
+ const key = "Content-Type";
26
+ const value = "application/json";
27
+ if (Array.isArray(headers)) headers.push([key, value]);
28
+ else if (Object.prototype.toString.call(headers) === "[object Object]") headers[key] = value;
29
+ else if (headers instanceof Headers) headers.append(key, value);
30
+ }
31
+ return {
32
+ headers,
33
+ body: typeof data === "object" ? JSON.stringify(data) : data,
34
+ ...rest
35
+ };
36
+ };
37
+ const fetchAdaptor = Object.preventExtensions({
38
+ get default() {
39
+ return fetch;
40
+ },
41
+ async delete(url, options) {
42
+ return jsonDataAttachResponse(await fetch(url, {
43
+ ...options,
44
+ method: "DELETE"
45
+ }));
46
+ },
47
+ async get(url, options) {
48
+ return jsonDataAttachResponse(await fetch(url, {
49
+ ...options,
50
+ method: "GET"
51
+ }));
52
+ },
53
+ async patch(url, options) {
54
+ return jsonDataAttachResponse(await fetch(url, {
55
+ ...parseOptions(options),
56
+ method: "PATCH"
57
+ }));
58
+ },
59
+ async post(url, options) {
60
+ return jsonDataAttachResponse(await fetch(url, {
61
+ ...parseOptions(options),
62
+ method: "POST"
63
+ }));
64
+ },
65
+ async put(url, options) {
66
+ return jsonDataAttachResponse(await fetch(url, {
67
+ ...parseOptions(options),
68
+ method: "PUT"
69
+ }));
70
+ },
71
+ responseWrapper: {}
72
+ });
73
+
74
+ //#endregion
75
+ export { fetchAdaptor };
@@ -0,0 +1,35 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_adaptors_axios = require('./axios.cjs');
3
+ let umi_request = require("umi-request");
4
+
5
+ //#region adaptors/umi-request.ts
6
+ const $http = /* @__PURE__ */ (0, umi_request.extend)({
7
+ getResponse: true,
8
+ requestType: "json",
9
+ responseType: "json"
10
+ });
11
+ const umiAdaptor = Object.preventExtensions({
12
+ get default() {
13
+ return $http;
14
+ },
15
+ responseWrapper: {},
16
+ get(url, options) {
17
+ return $http.get(url, options);
18
+ },
19
+ post(url, options) {
20
+ return $http.post(url, options);
21
+ },
22
+ put(url, options) {
23
+ return $http.put(url, options);
24
+ },
25
+ delete(url, options) {
26
+ return $http.delete(url, options);
27
+ },
28
+ patch(url, options) {
29
+ return $http.patch(url, options);
30
+ }
31
+ });
32
+
33
+ //#endregion
34
+ exports.default = umiAdaptor;
35
+ exports.umiAdaptor = umiAdaptor;
@@ -0,0 +1,7 @@
1
+ import { n as IRequestAdapter } from "../adapter-DLzJOGbI.cjs";
2
+ import { RequestMethod, RequestResponse } from "umi-request";
3
+
4
+ //#region adaptors/umi-request.d.ts
5
+ declare const umiAdaptor: IRequestAdapter<RequestMethod<true>, RequestResponse>;
6
+ //#endregion
7
+ export { umiAdaptor as default, umiAdaptor };
@@ -0,0 +1,7 @@
1
+ import { n as IRequestAdapter } from "../adapter-D1g1obyM.mjs";
2
+ import { RequestMethod, RequestResponse } from "umi-request";
3
+
4
+ //#region adaptors/umi-request.d.ts
5
+ declare const umiAdaptor: IRequestAdapter<RequestMethod<true>, RequestResponse>;
6
+ //#endregion
7
+ export { umiAdaptor as default, umiAdaptor };
@@ -0,0 +1,32 @@
1
+ import { extend } from "umi-request";
2
+
3
+ //#region adaptors/umi-request.ts
4
+ const $http = /* @__PURE__ */ extend({
5
+ getResponse: true,
6
+ requestType: "json",
7
+ responseType: "json"
8
+ });
9
+ const umiAdaptor = Object.preventExtensions({
10
+ get default() {
11
+ return $http;
12
+ },
13
+ responseWrapper: {},
14
+ get(url, options) {
15
+ return $http.get(url, options);
16
+ },
17
+ post(url, options) {
18
+ return $http.post(url, options);
19
+ },
20
+ put(url, options) {
21
+ return $http.put(url, options);
22
+ },
23
+ delete(url, options) {
24
+ return $http.delete(url, options);
25
+ },
26
+ patch(url, options) {
27
+ return $http.patch(url, options);
28
+ }
29
+ });
30
+
31
+ //#endregion
32
+ export { umiAdaptor as default, umiAdaptor };