@vesperjs/vue 0.3.3 → 0.5.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.
- package/dist/index.d.mts +13 -14
- package/dist/index.mjs +31 -16
- package/package.json +6 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { BackendErrorInfo, BackendErrorResource, ErrorMessages, ErrorsResource, Flash, UseFlashType, useDate, useEntity, useExternalErrors, useFlash } from "@vesperjs/shared";
|
|
2
2
|
import { Ref, WritableComputedRef } from "@vue/reactivity";
|
|
3
|
-
import { FetchError, FetchOptions, FetchResponse } from "ofetch";
|
|
3
|
+
import { FetchContext, FetchError, FetchOptions, FetchResponse } from "ofetch";
|
|
4
4
|
import * as _$vue_i18n0 from "vue-i18n";
|
|
5
|
-
import
|
|
6
|
-
import * as _$_nanostores_router0 from "@nanostores/router";
|
|
7
|
-
import { Router, RouterConfig } from "@nanostores/router";
|
|
5
|
+
import { ParamsFromConfig, Router, RouterConfig } from "@nanostores/router";
|
|
8
6
|
|
|
9
7
|
//#region src/composables/backend/api/use-api-constants.d.ts
|
|
10
8
|
declare const useApiConstants: () => {
|
|
@@ -25,6 +23,10 @@ interface QueryAPIOptions {
|
|
|
25
23
|
token?: string | null | undefined;
|
|
26
24
|
baseURL?: string | null | undefined;
|
|
27
25
|
signal?: AbortSignal;
|
|
26
|
+
retry?: number | false;
|
|
27
|
+
retryDelay?: number | ((context: FetchContext<any, 'json'>) => number);
|
|
28
|
+
retryStatusCodes?: number[];
|
|
29
|
+
timeout?: number;
|
|
28
30
|
onRequestError?: ({
|
|
29
31
|
error
|
|
30
32
|
}: {
|
|
@@ -51,6 +53,10 @@ interface MutationAPIOptions {
|
|
|
51
53
|
body?: Record<string, any> | FormData;
|
|
52
54
|
token?: string | null;
|
|
53
55
|
baseURL?: string | null;
|
|
56
|
+
retry?: number | false;
|
|
57
|
+
retryDelay?: number | ((context: FetchContext<any, 'json'>) => number);
|
|
58
|
+
retryStatusCodes?: number[];
|
|
59
|
+
timeout?: number;
|
|
54
60
|
onRequestError?: ({
|
|
55
61
|
error
|
|
56
62
|
}: {
|
|
@@ -62,14 +68,7 @@ interface MutationAPIOptions {
|
|
|
62
68
|
response: FetchResponse<any>;
|
|
63
69
|
}) => void;
|
|
64
70
|
}
|
|
65
|
-
declare const useMutationApi: <T = unknown, E = any>(url: string, {
|
|
66
|
-
method,
|
|
67
|
-
body,
|
|
68
|
-
token,
|
|
69
|
-
baseURL,
|
|
70
|
-
onRequestError,
|
|
71
|
-
onResponseError
|
|
72
|
-
}: MutationAPIOptions) => Promise<{
|
|
71
|
+
declare const useMutationApi: <T = unknown, E = any>(url: string, options: MutationAPIOptions) => Promise<{
|
|
73
72
|
token: string | null | undefined;
|
|
74
73
|
data: T | undefined;
|
|
75
74
|
error: FetchError<E> | undefined;
|
|
@@ -117,13 +116,13 @@ declare const useElement: <EL extends Element, P extends string>(el: EL | undefi
|
|
|
117
116
|
//#endregion
|
|
118
117
|
//#region src/composables/use-locale.d.ts
|
|
119
118
|
declare const useLocale: () => {
|
|
120
|
-
locale:
|
|
119
|
+
locale: WritableComputedRef<"en" | "ja", "en" | "ja">;
|
|
121
120
|
autodetect: () => void;
|
|
122
121
|
};
|
|
123
122
|
//#endregion
|
|
124
123
|
//#region src/composables/use-nano-route.d.ts
|
|
125
124
|
declare const useNanoRoute: <T extends RouterConfig>(router: Router<T>) => {
|
|
126
|
-
params:
|
|
125
|
+
params: ParamsFromConfig<T>[string] | undefined;
|
|
127
126
|
query: Record<string, string> | undefined;
|
|
128
127
|
path: string | undefined;
|
|
129
128
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -92,7 +92,7 @@ const useQueryApi = async function(url, options) {
|
|
|
92
92
|
const tokenRef = ref();
|
|
93
93
|
const headers = commonHeaders.value;
|
|
94
94
|
if (options?.token) headers.Authorization = `Bearer ${options.token}`;
|
|
95
|
-
const
|
|
95
|
+
const queryOptions = {
|
|
96
96
|
baseURL: options?.baseURL ?? baseUrl.value,
|
|
97
97
|
method: "get",
|
|
98
98
|
query: options?.query ?? {},
|
|
@@ -101,10 +101,14 @@ const useQueryApi = async function(url, options) {
|
|
|
101
101
|
tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? options?.token;
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
-
if (options?.
|
|
105
|
-
if (options?.
|
|
106
|
-
if (options?.
|
|
107
|
-
|
|
104
|
+
if (options?.retry) queryOptions.retry = options.retry;
|
|
105
|
+
if (options?.retryDelay) queryOptions.retryDelay = options.retryDelay;
|
|
106
|
+
if (options?.retryStatusCodes) queryOptions.retryStatusCodes = options.retryStatusCodes;
|
|
107
|
+
if (options?.timeout) queryOptions.timeout = options.timeout;
|
|
108
|
+
if (options?.signal) queryOptions.signal = options.signal;
|
|
109
|
+
if (options?.onRequestError) queryOptions.onRequestError = options.onRequestError;
|
|
110
|
+
if (options?.onResponseError) queryOptions.onResponseError = options.onResponseError;
|
|
111
|
+
const { data, error, pending } = await useOFetch(url, queryOptions);
|
|
108
112
|
return {
|
|
109
113
|
token: tokenRef.value,
|
|
110
114
|
data,
|
|
@@ -114,27 +118,38 @@ const useQueryApi = async function(url, options) {
|
|
|
114
118
|
};
|
|
115
119
|
//#endregion
|
|
116
120
|
//#region src/composables/backend/api/use-mutation-api.ts
|
|
117
|
-
const useMutationApi = async function(url,
|
|
121
|
+
const useMutationApi = async function(url, options) {
|
|
118
122
|
const { commonHeaders } = useHttpHeaders();
|
|
119
123
|
const { baseURL: baseUrl } = useApiConstants();
|
|
124
|
+
const method = options.method;
|
|
125
|
+
const body = options.body ?? {};
|
|
126
|
+
const token = options.token ?? null;
|
|
127
|
+
const baseURL = options.baseURL ?? null;
|
|
128
|
+
const retry = options.retry;
|
|
129
|
+
const retryDelay = options.retryDelay;
|
|
130
|
+
const retryStatusCodes = options.retryStatusCodes;
|
|
131
|
+
const timeout = options.timeout;
|
|
132
|
+
const onRequestError = options.onRequestError;
|
|
133
|
+
const onResponseError = options.onResponseError;
|
|
120
134
|
const headers = commonHeaders.value;
|
|
121
135
|
const tokenRef = ref();
|
|
122
|
-
if (token) {
|
|
123
|
-
|
|
124
|
-
tokenRef.value = token;
|
|
125
|
-
}
|
|
126
|
-
const options = {
|
|
136
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
137
|
+
const mutOptions = {
|
|
127
138
|
baseURL: baseURL ?? baseUrl.value,
|
|
128
139
|
headers,
|
|
129
140
|
method
|
|
130
141
|
};
|
|
131
|
-
if (
|
|
132
|
-
if (
|
|
133
|
-
if (
|
|
134
|
-
|
|
142
|
+
if (retry) mutOptions.retry = retry;
|
|
143
|
+
if (retryDelay) mutOptions.retryDelay = retryDelay;
|
|
144
|
+
if (retryStatusCodes) mutOptions.retryStatusCodes = retryStatusCodes;
|
|
145
|
+
if (timeout) mutOptions.timeout = timeout;
|
|
146
|
+
if (onRequestError) mutOptions.onRequestError = onRequestError;
|
|
147
|
+
if (onResponseError) mutOptions.onResponseError = onResponseError;
|
|
148
|
+
if (method == "post" || method == "put") mutOptions.body = body;
|
|
149
|
+
mutOptions.onResponse = ({ response }) => {
|
|
135
150
|
tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? token;
|
|
136
151
|
};
|
|
137
|
-
const { data, error, pending } = await useOFetch(url,
|
|
152
|
+
const { data, error, pending } = await useOFetch(url, mutOptions);
|
|
138
153
|
return {
|
|
139
154
|
token: tokenRef.value,
|
|
140
155
|
data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesperjs/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"vue.js"
|
|
6
6
|
],
|
|
@@ -22,21 +22,18 @@
|
|
|
22
22
|
"@formkit/tempo": "^1.0.0",
|
|
23
23
|
"@nanostores/persistent": "^1.3.4",
|
|
24
24
|
"@nanostores/router": "^1.0.0",
|
|
25
|
-
"@vesperjs/shared": "0.
|
|
25
|
+
"@vesperjs/shared": "0.5.0",
|
|
26
26
|
"nanostores": "^1.3.0",
|
|
27
27
|
"ofetch": "^1.5.1",
|
|
28
|
-
"undici": "^8.
|
|
28
|
+
"undici": "^8.2.0",
|
|
29
29
|
"vue-i18n": "^11.4.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@eslint/js": "^10.0.1",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^8.59.
|
|
34
|
-
"@typescript-eslint/parser": "^8.59.
|
|
35
|
-
"@typescript-eslint/project-service": "^8.59.1",
|
|
36
|
-
"@typescript-eslint/typescript-estree": "^8.59.1",
|
|
37
|
-
"@typescript-eslint/utils": "^8.59.1",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
34
|
+
"@typescript-eslint/parser": "^8.59.2",
|
|
38
35
|
"@vue/eslint-config-typescript": "^14.7.0",
|
|
39
|
-
"eslint": "^10.
|
|
36
|
+
"eslint": "^10.3.0",
|
|
40
37
|
"eslint-plugin-vue": "^10.9.0",
|
|
41
38
|
"oxfmt": "^0.47.0",
|
|
42
39
|
"tsdown": "^0.21.10",
|