@lark-apaas/miaoda-core 0.0.1-alpha.1 → 0.0.1-alpha.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.
@@ -1,11 +1,38 @@
1
- import apiProxy from '../api-proxy/core';
2
1
  /**
3
2
  * api panel
4
3
  * 获取open-api.json
5
4
  */
6
- declare function getOpenApiJson(): Promise<void>;
5
+ declare function getOpenApiJson(): Promise<{}>;
7
6
  /**
8
7
  * 获取日志json
9
8
  */
10
- declare function getLogJson(): Promise<void>;
11
- export { getOpenApiJson, getLogJson, apiProxy };
9
+ declare function getLogJson(): Promise<{}>;
10
+ /**
11
+ * GET 请求
12
+ */
13
+ declare function api_get(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
14
+ /**
15
+ * POST 请求
16
+ */
17
+ declare function api_post(url: any, data: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
18
+ /**
19
+ * PUT 请求
20
+ */
21
+ declare function api_put(url: any, data: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
22
+ /**
23
+ * DELETE 请求
24
+ */
25
+ declare function api_delete(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
26
+ /**
27
+ * PATCH 请求
28
+ */
29
+ declare function api_patch(url: any, data: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
30
+ /**
31
+ * HEAD 请求
32
+ */
33
+ declare function api_head(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
34
+ /**
35
+ * OPTIONS 请求
36
+ */
37
+ declare function api_options(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
38
+ export { getOpenApiJson, getLogJson, api_get, api_post, api_put, api_delete, api_patch, api_head, api_options, };
@@ -1,21 +1,53 @@
1
1
  import { normalizeBasePath } from "../../../utils/utils.js";
2
2
  import core from "../api-proxy/core.js";
3
3
  async function getOpenApiJson() {
4
+ let apiJson = {};
4
5
  try {
5
6
  const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
6
7
  const res = await fetch(`${basePath}/openapi.json`);
7
- await res.json();
8
+ apiJson = await res.json();
8
9
  } catch (error) {
9
- console.warn('get routes.json error', error);
10
+ console.warn('get openapi.json error', error);
10
11
  }
12
+ return apiJson;
11
13
  }
12
14
  async function getLogJson() {
15
+ let logJson = {};
13
16
  try {
14
17
  const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
15
18
  const res = await fetch(`${basePath}/log.json`);
16
- await res.json();
19
+ logJson = await res.json();
17
20
  } catch (error) {
18
21
  console.warn('get log.json error', error);
19
22
  }
23
+ return logJson;
20
24
  }
21
- export { core as apiProxy, getLogJson, getOpenApiJson };
25
+ async function api_get(url, config) {
26
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
27
+ return core.get(`${basePath}${url}`, config);
28
+ }
29
+ async function api_post(url, data, config) {
30
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
31
+ return core.post(`${basePath}${url}`, data, config);
32
+ }
33
+ async function api_put(url, data, config) {
34
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
35
+ return core.put(`${basePath}${url}`, data, config);
36
+ }
37
+ async function api_delete(url, config) {
38
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
39
+ return core["delete"](`${basePath}${url}`, config);
40
+ }
41
+ async function api_patch(url, data, config) {
42
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
43
+ return core.patch(`${basePath}${url}`, data, config);
44
+ }
45
+ async function api_head(url, config) {
46
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
47
+ return core.head(`${basePath}${url}`, config);
48
+ }
49
+ async function api_options(url, config) {
50
+ const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
51
+ return core.options(`${basePath}${url}`, config);
52
+ }
53
+ export { api_delete, api_get, api_head, api_options, api_patch, api_post, api_put, getLogJson, getOpenApiJson };
@@ -1,5 +1,5 @@
1
1
  import { normalizeBasePath } from "../../../utils/utils.js";
2
- import { apiProxy, getLogJson, getOpenApiJson } from "./api-panel.js";
2
+ import { api_delete, api_get, api_head, api_options, api_patch, api_post, api_put, getLogJson, getOpenApiJson } from "./api-panel.js";
3
3
  async function getRoutes() {
4
4
  let routes = [
5
5
  {
@@ -18,7 +18,13 @@ async function getRoutes() {
18
18
  const childApi = {
19
19
  getRoutes,
20
20
  apiProxy: {
21
- api: apiProxy,
21
+ api_get: api_get,
22
+ api_post: api_post,
23
+ api_put: api_put,
24
+ api_delete: api_delete,
25
+ api_patch: api_patch,
26
+ api_head: api_head,
27
+ api_options: api_options,
22
28
  getOpenApiJson: getOpenApiJson,
23
29
  getLogJson: getLogJson
24
30
  }
@@ -48,7 +48,13 @@ export interface ParentApi {
48
48
  export interface ChildApi {
49
49
  getRoutes: () => Promise<any[]>;
50
50
  apiProxy: {
51
- api: any;
51
+ api_get: (url: string, config?: any) => Promise<any>;
52
+ api_post: (url: string, data?: any, config?: any) => Promise<any>;
53
+ api_put: (url: string, data?: any, config?: any) => Promise<any>;
54
+ api_delete: (url: string, config?: any) => Promise<any>;
55
+ api_patch: (url: string, data?: any, config?: any) => Promise<any>;
56
+ api_head: (url: string, config?: any) => Promise<any>;
57
+ api_options: (url: string, config?: any) => Promise<any>;
52
58
  getOpenApiJson: () => Promise<any>;
53
59
  getLogJson: () => Promise<any>;
54
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-core",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.3",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [