@xy-planning-network/trees 0.6.1 → 0.6.2-rc-2
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 +120 -74
- package/dist/trees.umd.js +6 -6
- package/package.json +4 -2
- package/src/lib-components/lists/Table.vue +7 -3
- package/types/api/base.d.ts +3 -22
- package/types/api/client.d.ts +163 -0
- package/types/api/url.d.ts +1 -0
- package/types/composables/useBaseAPI.d.ts +12 -14
- package/types/composables/usePopper.d.ts +19 -0
- package/types/entry.d.ts +2 -2
- package/types/types/lists.d.ts +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xy-planning-network/trees",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2-rc-2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:xy-planning-network/trees",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"lint": "eslint --ext .js,.ts,.vue src",
|
|
29
29
|
"lint:fix": "eslint --fix --ext .js,.ts,.vue src dev && prettier -w -u src dev",
|
|
30
30
|
"preview": "vite preview --config vite.docs.config.ts",
|
|
31
|
-
"typecheck": "
|
|
31
|
+
"typecheck": "npm run typecheck:src && npm run typecheck:docs",
|
|
32
|
+
"typecheck:src": "vue-tsc -p src --noEmit",
|
|
33
|
+
"typecheck:docs": "vue-tsc -p dev --noEmit"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"@tailwindcss/forms": "^0.5.3",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { AxiosResponse } from "axios"
|
|
3
2
|
import {
|
|
4
3
|
ComponentPublicInstance,
|
|
5
4
|
computed,
|
|
@@ -12,6 +11,7 @@ import Paginator from "../navigation/Paginator.vue"
|
|
|
12
11
|
import BaseAPI from "../../api/base"
|
|
13
12
|
import * as TableTypes from "@/composables/table"
|
|
14
13
|
import { useAppFlasher } from "@/composables/useFlashes"
|
|
14
|
+
import { TrailsResponsePaged } from "@/api/client"
|
|
15
15
|
|
|
16
16
|
const props = withDefaults(
|
|
17
17
|
defineProps<{
|
|
@@ -96,8 +96,12 @@ const loadAndRender = (): void => {
|
|
|
96
96
|
q: query.value,
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
BaseAPI.get(
|
|
100
|
-
|
|
99
|
+
BaseAPI.get<TrailsResponsePaged<unknown>>(
|
|
100
|
+
props.tableData.url,
|
|
101
|
+
{ skipLoader: !props.loader },
|
|
102
|
+
params
|
|
103
|
+
).then(
|
|
104
|
+
(success) => {
|
|
101
105
|
pagination.value = {
|
|
102
106
|
page: success.data.page,
|
|
103
107
|
perPage: success.data.perPage,
|
package/types/api/base.d.ts
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from "axios";
|
|
2
|
-
|
|
3
|
-
export
|
|
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
|
-
*/
|
|
11
|
-
skipLoader?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* artificially delay's the request by the time specified when set
|
|
14
|
-
*/
|
|
15
|
-
withDelay?: number;
|
|
16
|
-
}
|
|
17
|
-
declare const BaseAPI: {
|
|
18
|
-
makeRequest<T = any>(config: AxiosRequestConfig, 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> | FormData, opts: RequestOptions): Promise<T_3>;
|
|
22
|
-
put<T_4 = any>(path: string, data: Record<string, unknown> | FormData, opts: RequestOptions): Promise<T_4>;
|
|
23
|
-
};
|
|
2
|
+
import { HttpClient, HttpPromise, RequestOptions } from "./client";
|
|
3
|
+
export declare const httpRequest: <T = any>(config: AxiosRequestConfig, opts: RequestOptions) => HttpPromise<T>;
|
|
4
|
+
declare const BaseAPI: HttpClient;
|
|
24
5
|
export default BaseAPI;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestMethod
|
|
3
|
+
* The HTTP request methods that our http client supports.
|
|
4
|
+
*/
|
|
5
|
+
export declare type RequestMethod = "GET" | "get" | "PATCH" | "patch" | "PUT" | "put" | "POST" | "post" | "DELETE" | "delete";
|
|
6
|
+
/**
|
|
7
|
+
* RequestOptions
|
|
8
|
+
* The set of options available for any http client request.
|
|
9
|
+
*/
|
|
10
|
+
export interface RequestOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Disable the full screen loading interface during the request when true.
|
|
13
|
+
*/
|
|
14
|
+
skipLoader?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Artificially delay a request by the time specified when set.
|
|
17
|
+
*/
|
|
18
|
+
withDelay?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const HTTP_ERROR = "HttpError";
|
|
21
|
+
export declare const HTTP_CANCELLED_ERROR = "HttpCanceledError";
|
|
22
|
+
/**
|
|
23
|
+
* HttpError
|
|
24
|
+
* An http client error when the request is rejected.
|
|
25
|
+
*/
|
|
26
|
+
export declare class HttpError<T = unknown> extends Error {
|
|
27
|
+
/**
|
|
28
|
+
* The http response status code.
|
|
29
|
+
*/
|
|
30
|
+
status: number;
|
|
31
|
+
/**
|
|
32
|
+
* The http response body.
|
|
33
|
+
*/
|
|
34
|
+
response?: T;
|
|
35
|
+
constructor(message?: string, status?: number, response?: T, name?: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* HttpPromise
|
|
39
|
+
* The successfully resolved interface of an http client request.
|
|
40
|
+
*/
|
|
41
|
+
export interface HttpPromise<T = any> extends Promise<T> {
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* TrailsResponse
|
|
45
|
+
* A convenience interface to represent the shape of a Trails delivered API response.
|
|
46
|
+
*
|
|
47
|
+
* Example Usage:
|
|
48
|
+
* interface User {
|
|
49
|
+
* id: number
|
|
50
|
+
* email: string
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* BaseAPI.get<TrailsResponse<User>>(`/user/${id}`)
|
|
54
|
+
* .then(result => {
|
|
55
|
+
* const id = result.data.id
|
|
56
|
+
* const email = result.data.email
|
|
57
|
+
* const user = { ...result.data }
|
|
58
|
+
* })
|
|
59
|
+
*/
|
|
60
|
+
export interface TrailsResponse<T = any> {
|
|
61
|
+
data: T;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* TrailsResponsePaged
|
|
65
|
+
* A convenience interface to represent the shape of a paginated Trails delivered API response.
|
|
66
|
+
*
|
|
67
|
+
* Example Usage:
|
|
68
|
+
* interface User {
|
|
69
|
+
* id: number
|
|
70
|
+
* email: string
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* BaseAPI.get<TrailsResponsePaged<User>>(`/users`)
|
|
74
|
+
* .then(result => {
|
|
75
|
+
* const currentPage = result.data.page
|
|
76
|
+
* const users = { ...result.data.items }
|
|
77
|
+
*
|
|
78
|
+
* result.data.items.forEach(u => {
|
|
79
|
+
* console.log(u.id)
|
|
80
|
+
* })
|
|
81
|
+
* })
|
|
82
|
+
*/
|
|
83
|
+
export interface TrailsResponsePaged<T = any> {
|
|
84
|
+
data: {
|
|
85
|
+
items: T[];
|
|
86
|
+
page: number;
|
|
87
|
+
perPage: number;
|
|
88
|
+
totalItems: number;
|
|
89
|
+
totalPages: number;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* QueryParams
|
|
94
|
+
* Http GET request query params.
|
|
95
|
+
*/
|
|
96
|
+
export declare type QueryParams = Record<string, any>;
|
|
97
|
+
/**
|
|
98
|
+
* RequestPayload
|
|
99
|
+
* Http POST and PUT payloads.
|
|
100
|
+
*/
|
|
101
|
+
export declare type RequestPayload = Record<string, any> | FormData;
|
|
102
|
+
/**
|
|
103
|
+
* HttpClient
|
|
104
|
+
* The http client interface the BaseAPI implements.
|
|
105
|
+
*/
|
|
106
|
+
export interface HttpClient {
|
|
107
|
+
/**
|
|
108
|
+
* The method to make an http GET request.
|
|
109
|
+
* @param path string
|
|
110
|
+
* @param opts RequestOptions
|
|
111
|
+
* @param params QueryParams
|
|
112
|
+
* @returns HttpPromise<T>
|
|
113
|
+
*/
|
|
114
|
+
get<T>(path: string, opts?: RequestOptions, params?: QueryParams): HttpPromise<T>;
|
|
115
|
+
/**
|
|
116
|
+
* The method to make an http DELETE request.
|
|
117
|
+
* @param path string
|
|
118
|
+
* @param opts RequestOptions
|
|
119
|
+
* @returns HttpPromise<T>
|
|
120
|
+
*/
|
|
121
|
+
delete<T>(path: string, opts?: RequestOptions): HttpPromise<T>;
|
|
122
|
+
/**
|
|
123
|
+
* A convenience method for checking if a variable in a failed request has an http status code.
|
|
124
|
+
* This is most useful for checking for specific http status codes in error callbacks.
|
|
125
|
+
* @param err unknown
|
|
126
|
+
* @param codes number | number[]
|
|
127
|
+
* @returns boolean
|
|
128
|
+
*/
|
|
129
|
+
hasErrStatus(err: unknown, codes: number | number[]): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* A type guard for checking if a variable is in the shape of a HttpError
|
|
132
|
+
* @param err unknown
|
|
133
|
+
* @returns payload is HttpError
|
|
134
|
+
*/
|
|
135
|
+
isHttpError(err: unknown): err is HttpError;
|
|
136
|
+
/**
|
|
137
|
+
* A convenience method for checking if a variable is a cancelled http request error.
|
|
138
|
+
* @param err unknown
|
|
139
|
+
* @returns boolean
|
|
140
|
+
*/
|
|
141
|
+
isHttpCancel(err: unknown): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* The method to make an http PATCH request.
|
|
144
|
+
* @param path string
|
|
145
|
+
* @param data RequestPayload
|
|
146
|
+
* @param opts RequestOptions
|
|
147
|
+
*/
|
|
148
|
+
patch<T>(path: string, data?: RequestPayload, opts?: RequestOptions): HttpPromise<T>;
|
|
149
|
+
/**
|
|
150
|
+
* The method to make an http POST request.
|
|
151
|
+
* @param path string
|
|
152
|
+
* @param data RequestPayload
|
|
153
|
+
* @param opts RequestOptions
|
|
154
|
+
*/
|
|
155
|
+
post<T>(path: string, data?: RequestPayload, opts?: RequestOptions): HttpPromise<T>;
|
|
156
|
+
/**
|
|
157
|
+
* The method to make an http PUT request.
|
|
158
|
+
* @param path string
|
|
159
|
+
* @param data RequestPayload
|
|
160
|
+
* @param opts RequestOptions
|
|
161
|
+
*/
|
|
162
|
+
put<T>(path: string, data?: RequestPayload, opts?: RequestOptions): HttpPromise<T>;
|
|
163
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getBaseUrl(): string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { AxiosError } from "axios";
|
|
2
1
|
import { Ref, ShallowRef } from "vue";
|
|
3
|
-
import type { RequestMethod, RequestOptions } from "../api/
|
|
2
|
+
import type { HttpPromise, HttpError, RequestMethod, RequestOptions, RequestPayload } from "../api/client";
|
|
4
3
|
/**
|
|
5
4
|
* UseBaseAPIOptions extends Trees/RequestOptions
|
|
6
5
|
* these options are used only in the instantiation
|
|
@@ -25,7 +24,7 @@ export interface UseBaseAPI<T> {
|
|
|
25
24
|
/**
|
|
26
25
|
* Any errors that may have occurred
|
|
27
26
|
*/
|
|
28
|
-
error: ShallowRef<Error |
|
|
27
|
+
error: ShallowRef<Error | HttpError<T> | undefined>;
|
|
29
28
|
/**
|
|
30
29
|
* Indicates if the request has finished
|
|
31
30
|
*/
|
|
@@ -51,7 +50,7 @@ export interface UseBaseAPI<T> {
|
|
|
51
50
|
* Manually call the axios request
|
|
52
51
|
* can be used multiple times
|
|
53
52
|
*/
|
|
54
|
-
execute: (data?:
|
|
53
|
+
execute: (data?: RequestPayload, opts?: RequestOptions) => HttpPromise<T>;
|
|
55
54
|
}
|
|
56
55
|
/**
|
|
57
56
|
* useBaseAPI is a composable wrapper of BaseAPI
|
|
@@ -61,16 +60,7 @@ export interface UseBaseAPI<T> {
|
|
|
61
60
|
* @param initConfig {AxiosRequestConfig}
|
|
62
61
|
* @returns {UseBaseAPI<T>}
|
|
63
62
|
*/
|
|
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> | FormData, opts?: RequestOptions) => Promise<T>;
|
|
73
|
-
};
|
|
63
|
+
export default function useBaseAPI<T = any>(path: string, method?: RequestMethod, initOpts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
|
74
64
|
/**
|
|
75
65
|
* useBaseAPIGet is a convenience function for useBaseAPI
|
|
76
66
|
* @param path {string} the api path or full url for the
|
|
@@ -87,6 +77,14 @@ export declare function useBaseAPIGet<T = any>(url: string, opts?: UseBaseAPIOpt
|
|
|
87
77
|
* @returns {UseBaseAPI<T>}
|
|
88
78
|
*/
|
|
89
79
|
export declare function useBaseAPIDelete<T = any>(url: string, opts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
|
80
|
+
/**
|
|
81
|
+
* useBaseAPIPatch is a convenience function for useBaseAPI
|
|
82
|
+
* @param path {string} the api path or full url for the
|
|
83
|
+
* @param initOpts {UseBaseAPIOptions}
|
|
84
|
+
* @param initConfig {AxiosRequestConfig}
|
|
85
|
+
* @returns {UseBaseAPI<T>}
|
|
86
|
+
*/
|
|
87
|
+
export declare function useBaseAPIPatch<T = any>(url: string, opts?: UseBaseAPIOptions): UseBaseAPI<T>;
|
|
90
88
|
/**
|
|
91
89
|
* useBaseAPIPost is a convenience function for useBaseAPI
|
|
92
90
|
* @param path {string} the api path or full url for the
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VNode } from "vue";
|
|
2
|
+
import { Options, Placement } from "@popperjs/core";
|
|
3
|
+
export declare type PopperPosition = Placement;
|
|
4
|
+
export declare const offsetModifier: (skidding: number, distance: number) => {
|
|
5
|
+
options: {
|
|
6
|
+
offset: () => number[];
|
|
7
|
+
};
|
|
8
|
+
name: "offset";
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
phase: import("@popperjs/core").ModifierPhases;
|
|
11
|
+
requires?: string[] | undefined;
|
|
12
|
+
requiresIfExists?: string[] | undefined;
|
|
13
|
+
fn: (arg0: import("@popperjs/core").ModifierArguments<import("@popperjs/core/lib/modifiers/offset").Options>) => void | import("@popperjs/core").State;
|
|
14
|
+
effect?: ((arg0: import("@popperjs/core").ModifierArguments<import("@popperjs/core/lib/modifiers/offset").Options>) => void | (() => void)) | undefined;
|
|
15
|
+
data?: import("@popperjs/core").Obj | undefined;
|
|
16
|
+
};
|
|
17
|
+
export declare function usePopper(opts: Partial<Options>): import("vue").Ref<VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}> | HTMLElement | undefined>[];
|
package/types/entry.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "vue";
|
|
2
2
|
import BaseAPI from "./api/base";
|
|
3
|
-
import type { RequestOptions } from "./api/
|
|
3
|
+
import type { HttpPromise, HttpError, RequestOptions, TrailsResponse, TrailsResponsePaged } from "./api/client";
|
|
4
4
|
declare const install: Exclude<Plugin["install"], undefined>;
|
|
5
5
|
export default install;
|
|
6
6
|
export * from "./composables/index";
|
|
7
7
|
export * from "./lib-components/index";
|
|
8
8
|
export { BaseAPI };
|
|
9
|
-
export type { RequestOptions };
|
|
9
|
+
export type { HttpPromise, HttpError, RequestOptions, TrailsResponse, TrailsResponsePaged, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Pagination {
|
|
2
|
+
page: number;
|
|
3
|
+
perPage: number;
|
|
4
|
+
totalItems: number;
|
|
5
|
+
totalPages: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PaginationItems<T = any> {
|
|
8
|
+
items: T[];
|
|
9
|
+
}
|
|
10
|
+
export interface PaginationData<T = any> {
|
|
11
|
+
data: Pagination & PaginationItems<T>;
|
|
12
|
+
}
|