@xy-planning-network/trees 0.4.7 → 0.4.8
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/trees.es.js +619 -405
- package/dist/trees.umd.js +7 -7
- package/package.json +2 -2
- package/types/api/base.d.ts +19 -7
- package/types/composables/index.d.ts +4 -0
- package/types/composables/useBaseAPI.d.ts +105 -0
- package/types/entry.d.ts +3 -0
- package/types/helpers/Debounce.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xy-planning-network/trees",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:xy-planning-network/trees",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@headlessui/vue": "^1.4.2",
|
|
60
60
|
"@heroicons/vue": "^1.0.5",
|
|
61
|
-
"axios": "^0.
|
|
61
|
+
"axios": "^0.27.2",
|
|
62
62
|
"flatpickr": "^4.6.9"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
package/types/api/base.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
2
|
+
export declare type RequestMethod = "GET" | "get" | "PUT" | "put" | "POST" | "post" | "DELETE" | "delete";
|
|
3
|
+
export interface RequestOptions extends AxiosRequestConfig {
|
|
4
|
+
/**
|
|
5
|
+
* returns the nested data key inside the AxiosResponse data when true
|
|
6
|
+
*/
|
|
7
|
+
dataIntercept?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* disables the full screen loading interface during the request when true
|
|
10
|
+
*/
|
|
3
11
|
skipLoader?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* artificially delay's the request by the time specified when set
|
|
14
|
+
*/
|
|
15
|
+
withDelay?: number;
|
|
4
16
|
}
|
|
5
17
|
declare const BaseAPI: {
|
|
6
|
-
makeRequest
|
|
7
|
-
get(path: string, opts: RequestOptions, params?: Record<string, unknown> | undefined):
|
|
8
|
-
delete(path: string, opts: RequestOptions):
|
|
9
|
-
post(path: string, data: Record<string, unknown>, opts: RequestOptions):
|
|
10
|
-
put(path: string, data: Record<string, unknown>, opts: RequestOptions):
|
|
18
|
+
makeRequest<T = any>(opts: RequestOptions): Promise<T>;
|
|
19
|
+
get<T_1 = any>(path: string, opts: RequestOptions, params?: Record<string, unknown> | undefined): Promise<T_1>;
|
|
20
|
+
delete<T_2 = any>(path: string, opts: RequestOptions): Promise<T_2>;
|
|
21
|
+
post<T_3 = any>(path: string, data: Record<string, unknown>, opts: RequestOptions): Promise<T_3>;
|
|
22
|
+
put<T_4 = any>(path: string, data: Record<string, unknown>, opts: RequestOptions): Promise<T_4>;
|
|
11
23
|
};
|
|
12
24
|
export default BaseAPI;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as useBaseAPI, useBaseAPIGet, useBaseAPIPut, useBaseAPIPost, useBaseAPIDelete } from "./useBaseAPI";
|
|
2
|
+
import type { UseBaseAPIOptions, UseBaseAPI } from "./useBaseAPI";
|
|
3
|
+
export type { UseBaseAPIOptions, UseBaseAPI };
|
|
4
|
+
export { useBaseAPI, useBaseAPIGet, useBaseAPIPut, useBaseAPIPost, useBaseAPIDelete, };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AxiosError } from "axios";
|
|
2
|
+
import { Ref, ShallowRef } from "vue";
|
|
3
|
+
import type { RequestMethod, RequestOptions } from "../api/base";
|
|
4
|
+
/**
|
|
5
|
+
* UseBaseAPIOptions extends Trees/RequestOptions
|
|
6
|
+
* these options are used only in the instantiation
|
|
7
|
+
* of a new UseBaseAPI composable
|
|
8
|
+
*/
|
|
9
|
+
export interface UseBaseAPIOptions extends RequestOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether to immediately fire the execute function during instantiation
|
|
12
|
+
*/
|
|
13
|
+
immediate?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* UseBaseAPI is a composable the wraps up the
|
|
17
|
+
* usage of Trees/BaseAPI and returns reactive
|
|
18
|
+
* state variables along with reusaable execute and abort functions
|
|
19
|
+
*/
|
|
20
|
+
export interface UseBaseAPI<T> {
|
|
21
|
+
/**
|
|
22
|
+
* Axios response data
|
|
23
|
+
*/
|
|
24
|
+
result: Ref<T | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Any errors that may have occurred
|
|
27
|
+
*/
|
|
28
|
+
error: ShallowRef<Error | AxiosError<T> | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Indicates if the request has finished
|
|
31
|
+
*/
|
|
32
|
+
isFinished: Ref<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Indicates if the request is currently loading
|
|
35
|
+
*/
|
|
36
|
+
isLoading: Ref<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Indicates if the request was canceled
|
|
39
|
+
*/
|
|
40
|
+
isAborted: Ref<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Indicates if a first request has completed
|
|
43
|
+
*/
|
|
44
|
+
hasFetched: Ref<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Aborts the current request
|
|
47
|
+
* can be used multiple times
|
|
48
|
+
*/
|
|
49
|
+
abort: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Manually call the axios request
|
|
52
|
+
* can be used multiple times
|
|
53
|
+
*/
|
|
54
|
+
execute: (data?: Record<string, unknown>, opts?: RequestOptions) => Promise<T>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* useBaseAPI is a composable wrapper of BaseAPI
|
|
58
|
+
* @param path {string} the api path or full url for the
|
|
59
|
+
* @param method {RequestMethod} the initial request type
|
|
60
|
+
* @param initOpts {UseBaseAPIOptions}
|
|
61
|
+
* @param initConfig {AxiosRequestConfig}
|
|
62
|
+
* @returns {UseBaseAPI<T>}
|
|
63
|
+
*/
|
|
64
|
+
export default function useBaseAPI<T = any>(path: string, method?: RequestMethod, initOpts?: UseBaseAPIOptions): {
|
|
65
|
+
result: Ref<T | undefined>;
|
|
66
|
+
error: ShallowRef<Error | AxiosError<T, any> | undefined>;
|
|
67
|
+
isFinished: Ref<boolean>;
|
|
68
|
+
isLoading: Ref<boolean>;
|
|
69
|
+
isAborted: Ref<boolean>;
|
|
70
|
+
hasFetched: Ref<boolean>;
|
|
71
|
+
abort: () => void;
|
|
72
|
+
execute: (data?: Record<string, unknown>, opts?: RequestOptions) => Promise<T>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* useBaseAPIGet is a convenience function for useBaseAPI
|
|
76
|
+
* @param path {string} the api path or full url for the
|
|
77
|
+
* @param initOpts {UseBaseAPIOptions}
|
|
78
|
+
* @param initConfig {AxiosRequestConfig}
|
|
79
|
+
* @returns {UseBaseAPI<T>}
|
|
80
|
+
*/
|
|
81
|
+
export declare function useBaseAPIGet<T = any>(url: string, opts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
|
82
|
+
/**
|
|
83
|
+
* useBaseAPIDelete is a convenience function for useBaseAPI
|
|
84
|
+
* @param path {string} the api path or full url for the
|
|
85
|
+
* @param initOpts {UseBaseAPIOptions}
|
|
86
|
+
* @param initConfig {AxiosRequestConfig}
|
|
87
|
+
* @returns {UseBaseAPI<T>}
|
|
88
|
+
*/
|
|
89
|
+
export declare function useBaseAPIDelete<T = any>(url: string, opts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
|
90
|
+
/**
|
|
91
|
+
* useBaseAPIPost is a convenience function for useBaseAPI
|
|
92
|
+
* @param path {string} the api path or full url for the
|
|
93
|
+
* @param initOpts {UseBaseAPIOptions}
|
|
94
|
+
* @param initConfig {AxiosRequestConfig}
|
|
95
|
+
* @returns {UseBaseAPI<T>}
|
|
96
|
+
*/
|
|
97
|
+
export declare function useBaseAPIPost<T = any>(url: string, opts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
|
98
|
+
/**
|
|
99
|
+
* useBaseAPIPut is a convenience function for useBaseAPI
|
|
100
|
+
* @param path {string} the api path or full url for the
|
|
101
|
+
* @param initOpts {UseBaseAPIOptions}
|
|
102
|
+
* @param initConfig {AxiosRequestConfig}
|
|
103
|
+
* @returns {UseBaseAPI<T>}
|
|
104
|
+
*/
|
|
105
|
+
export declare function useBaseAPIPut<T = any>(url: string, opts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
package/types/entry.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "vue";
|
|
2
2
|
import BaseAPI from "./api/base";
|
|
3
|
+
import type { RequestOptions } from "./api/base";
|
|
3
4
|
declare const install: Exclude<Plugin["install"], undefined>;
|
|
4
5
|
export default install;
|
|
6
|
+
export * from "./composables/index";
|
|
5
7
|
export * from "./lib-components/index";
|
|
6
8
|
export { BaseAPI };
|
|
9
|
+
export type { RequestOptions };
|