@vesperjs/vue 0.4.0 → 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 +4 -17
- package/dist/index.mjs +30 -20
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,7 @@ import { BackendErrorInfo, BackendErrorResource, ErrorMessages, ErrorsResource,
|
|
|
2
2
|
import { Ref, WritableComputedRef } from "@vue/reactivity";
|
|
3
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: () => {
|
|
@@ -70,18 +68,7 @@ interface MutationAPIOptions {
|
|
|
70
68
|
response: FetchResponse<any>;
|
|
71
69
|
}) => void;
|
|
72
70
|
}
|
|
73
|
-
declare const useMutationApi: <T = unknown, E = any>(url: string, {
|
|
74
|
-
method,
|
|
75
|
-
body,
|
|
76
|
-
token,
|
|
77
|
-
baseURL,
|
|
78
|
-
retry,
|
|
79
|
-
retryDelay,
|
|
80
|
-
retryStatusCodes,
|
|
81
|
-
timeout,
|
|
82
|
-
onRequestError,
|
|
83
|
-
onResponseError
|
|
84
|
-
}: MutationAPIOptions) => Promise<{
|
|
71
|
+
declare const useMutationApi: <T = unknown, E = any>(url: string, options: MutationAPIOptions) => Promise<{
|
|
85
72
|
token: string | null | undefined;
|
|
86
73
|
data: T | undefined;
|
|
87
74
|
error: FetchError<E> | undefined;
|
|
@@ -129,13 +116,13 @@ declare const useElement: <EL extends Element, P extends string>(el: EL | undefi
|
|
|
129
116
|
//#endregion
|
|
130
117
|
//#region src/composables/use-locale.d.ts
|
|
131
118
|
declare const useLocale: () => {
|
|
132
|
-
locale:
|
|
119
|
+
locale: WritableComputedRef<"en" | "ja", "en" | "ja">;
|
|
133
120
|
autodetect: () => void;
|
|
134
121
|
};
|
|
135
122
|
//#endregion
|
|
136
123
|
//#region src/composables/use-nano-route.d.ts
|
|
137
124
|
declare const useNanoRoute: <T extends RouterConfig>(router: Router<T>) => {
|
|
138
|
-
params:
|
|
125
|
+
params: ParamsFromConfig<T>[string] | undefined;
|
|
139
126
|
query: Record<string, string> | undefined;
|
|
140
127
|
path: string | undefined;
|
|
141
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,14 +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?.retry)
|
|
105
|
-
if (options?.retryDelay)
|
|
106
|
-
if (options?.retryStatusCodes)
|
|
107
|
-
if (options?.timeout)
|
|
108
|
-
if (options?.signal)
|
|
109
|
-
if (options?.onRequestError)
|
|
110
|
-
if (options?.onResponseError)
|
|
111
|
-
const { data, error, pending } = await useOFetch(url,
|
|
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);
|
|
112
112
|
return {
|
|
113
113
|
token: tokenRef.value,
|
|
114
114
|
data,
|
|
@@ -118,28 +118,38 @@ const useQueryApi = async function(url, options) {
|
|
|
118
118
|
};
|
|
119
119
|
//#endregion
|
|
120
120
|
//#region src/composables/backend/api/use-mutation-api.ts
|
|
121
|
-
const useMutationApi = async function(url,
|
|
121
|
+
const useMutationApi = async function(url, options) {
|
|
122
122
|
const { commonHeaders } = useHttpHeaders();
|
|
123
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;
|
|
124
134
|
const headers = commonHeaders.value;
|
|
125
135
|
const tokenRef = ref();
|
|
126
136
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
127
|
-
const
|
|
137
|
+
const mutOptions = {
|
|
128
138
|
baseURL: baseURL ?? baseUrl.value,
|
|
129
139
|
headers,
|
|
130
140
|
method
|
|
131
141
|
};
|
|
132
|
-
if (retry)
|
|
133
|
-
if (retryDelay)
|
|
134
|
-
if (retryStatusCodes)
|
|
135
|
-
if (timeout)
|
|
136
|
-
if (onRequestError)
|
|
137
|
-
if (onResponseError)
|
|
138
|
-
if (method == "post" || method == "put")
|
|
139
|
-
|
|
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 }) => {
|
|
140
150
|
tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? token;
|
|
141
151
|
};
|
|
142
|
-
const { data, error, pending } = await useOFetch(url,
|
|
152
|
+
const { data, error, pending } = await useOFetch(url, mutOptions);
|
|
143
153
|
return {
|
|
144
154
|
token: tokenRef.value,
|
|
145
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,18 +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.
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
34
|
+
"@typescript-eslint/parser": "^8.59.2",
|
|
35
35
|
"@vue/eslint-config-typescript": "^14.7.0",
|
|
36
|
-
"eslint": "^10.
|
|
36
|
+
"eslint": "^10.3.0",
|
|
37
37
|
"eslint-plugin-vue": "^10.9.0",
|
|
38
38
|
"oxfmt": "^0.47.0",
|
|
39
39
|
"tsdown": "^0.21.10",
|