@vesperjs/vue 0.4.0 → 0.6.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 +6 -17
- package/dist/index.mjs +41 -22
- package/package.json +12 -12
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: () => {
|
|
@@ -21,7 +19,9 @@ declare const useOFetch: <T = unknown, E = any>(url: string, options?: FetchOpti
|
|
|
21
19
|
//#region src/composables/backend/api/use-query-api.d.ts
|
|
22
20
|
type SearchParams = Record<string, any>;
|
|
23
21
|
interface QueryAPIOptions {
|
|
22
|
+
method?: 'get' | 'query';
|
|
24
23
|
query?: SearchParams;
|
|
24
|
+
body?: Record<string, any> | FormData;
|
|
25
25
|
token?: string | null | undefined;
|
|
26
26
|
baseURL?: string | null | undefined;
|
|
27
27
|
signal?: AbortSignal;
|
|
@@ -70,18 +70,7 @@ interface MutationAPIOptions {
|
|
|
70
70
|
response: FetchResponse<any>;
|
|
71
71
|
}) => void;
|
|
72
72
|
}
|
|
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<{
|
|
73
|
+
declare const useMutationApi: <T = unknown, E = any>(url: string, options: MutationAPIOptions) => Promise<{
|
|
85
74
|
token: string | null | undefined;
|
|
86
75
|
data: T | undefined;
|
|
87
76
|
error: FetchError<E> | undefined;
|
|
@@ -129,13 +118,13 @@ declare const useElement: <EL extends Element, P extends string>(el: EL | undefi
|
|
|
129
118
|
//#endregion
|
|
130
119
|
//#region src/composables/use-locale.d.ts
|
|
131
120
|
declare const useLocale: () => {
|
|
132
|
-
locale:
|
|
121
|
+
locale: WritableComputedRef<"en" | "ja", "en" | "ja">;
|
|
133
122
|
autodetect: () => void;
|
|
134
123
|
};
|
|
135
124
|
//#endregion
|
|
136
125
|
//#region src/composables/use-nano-route.d.ts
|
|
137
126
|
declare const useNanoRoute: <T extends RouterConfig>(router: Router<T>) => {
|
|
138
|
-
params:
|
|
127
|
+
params: ParamsFromConfig<T>[string] | undefined;
|
|
139
128
|
query: Record<string, string> | undefined;
|
|
140
129
|
path: string | undefined;
|
|
141
130
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -92,23 +92,32 @@ 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
|
-
method: "get",
|
|
98
|
-
query: options?.query ?? {},
|
|
99
97
|
headers,
|
|
100
98
|
onResponse({ response }) {
|
|
101
99
|
tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? options?.token;
|
|
102
100
|
}
|
|
103
101
|
};
|
|
104
|
-
if (options?.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (options?.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
if (options?.method) {
|
|
103
|
+
queryOptions.method = options.method;
|
|
104
|
+
if (options.method === "get") queryOptions.query = options.query ?? {};
|
|
105
|
+
if (options.method === "query") queryOptions.body = options.body ?? {};
|
|
106
|
+
} else if (options?.query) {
|
|
107
|
+
queryOptions.method = "get";
|
|
108
|
+
queryOptions.query = options.query;
|
|
109
|
+
} else if (options?.body) {
|
|
110
|
+
queryOptions.method = "query";
|
|
111
|
+
queryOptions.body = options.body;
|
|
112
|
+
}
|
|
113
|
+
if (options?.retry) queryOptions.retry = options.retry;
|
|
114
|
+
if (options?.retryDelay) queryOptions.retryDelay = options.retryDelay;
|
|
115
|
+
if (options?.retryStatusCodes) queryOptions.retryStatusCodes = options.retryStatusCodes;
|
|
116
|
+
if (options?.timeout) queryOptions.timeout = options.timeout;
|
|
117
|
+
if (options?.signal) queryOptions.signal = options.signal;
|
|
118
|
+
if (options?.onRequestError) queryOptions.onRequestError = options.onRequestError;
|
|
119
|
+
if (options?.onResponseError) queryOptions.onResponseError = options.onResponseError;
|
|
120
|
+
const { data, error, pending } = await useOFetch(url, queryOptions);
|
|
112
121
|
return {
|
|
113
122
|
token: tokenRef.value,
|
|
114
123
|
data,
|
|
@@ -118,28 +127,38 @@ const useQueryApi = async function(url, options) {
|
|
|
118
127
|
};
|
|
119
128
|
//#endregion
|
|
120
129
|
//#region src/composables/backend/api/use-mutation-api.ts
|
|
121
|
-
const useMutationApi = async function(url,
|
|
130
|
+
const useMutationApi = async function(url, options) {
|
|
122
131
|
const { commonHeaders } = useHttpHeaders();
|
|
123
132
|
const { baseURL: baseUrl } = useApiConstants();
|
|
133
|
+
const method = options.method;
|
|
134
|
+
const body = options.body ?? {};
|
|
135
|
+
const token = options.token ?? null;
|
|
136
|
+
const baseURL = options.baseURL ?? null;
|
|
137
|
+
const retry = options.retry;
|
|
138
|
+
const retryDelay = options.retryDelay;
|
|
139
|
+
const retryStatusCodes = options.retryStatusCodes;
|
|
140
|
+
const timeout = options.timeout;
|
|
141
|
+
const onRequestError = options.onRequestError;
|
|
142
|
+
const onResponseError = options.onResponseError;
|
|
124
143
|
const headers = commonHeaders.value;
|
|
125
144
|
const tokenRef = ref();
|
|
126
145
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
127
|
-
const
|
|
146
|
+
const mutOptions = {
|
|
128
147
|
baseURL: baseURL ?? baseUrl.value,
|
|
129
148
|
headers,
|
|
130
149
|
method
|
|
131
150
|
};
|
|
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
|
-
|
|
151
|
+
if (retry) mutOptions.retry = retry;
|
|
152
|
+
if (retryDelay) mutOptions.retryDelay = retryDelay;
|
|
153
|
+
if (retryStatusCodes) mutOptions.retryStatusCodes = retryStatusCodes;
|
|
154
|
+
if (timeout) mutOptions.timeout = timeout;
|
|
155
|
+
if (onRequestError) mutOptions.onRequestError = onRequestError;
|
|
156
|
+
if (onResponseError) mutOptions.onResponseError = onResponseError;
|
|
157
|
+
if (method == "post" || method == "put") mutOptions.body = body;
|
|
158
|
+
mutOptions.onResponse = ({ response }) => {
|
|
140
159
|
tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? token;
|
|
141
160
|
};
|
|
142
|
-
const { data, error, pending } = await useOFetch(url,
|
|
161
|
+
const { data, error, pending } = await useOFetch(url, mutOptions);
|
|
143
162
|
return {
|
|
144
163
|
token: tokenRef.value,
|
|
145
164
|
data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesperjs/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"vue.js"
|
|
6
6
|
],
|
|
@@ -22,28 +22,28 @@
|
|
|
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.6.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.
|
|
37
|
-
"eslint-plugin-vue": "^10.9.
|
|
38
|
-
"oxfmt": "^0.
|
|
36
|
+
"eslint": "^10.3.0",
|
|
37
|
+
"eslint-plugin-vue": "^10.9.1",
|
|
38
|
+
"oxfmt": "^0.48.0",
|
|
39
39
|
"tsdown": "^0.21.10",
|
|
40
40
|
"typescript": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@vue/reactivity": "^3.5.
|
|
44
|
-
"@vue/runtime-core": "^3.5.
|
|
45
|
-
"@vue/runtime-dom": "^3.5.
|
|
46
|
-
"vue": "^3.5.
|
|
43
|
+
"@vue/reactivity": "^3.5.34 || ^3.6.0-beta.10",
|
|
44
|
+
"@vue/runtime-core": "^3.5.34 || ^3.6.0-beta.10",
|
|
45
|
+
"@vue/runtime-dom": "^3.5.34 || ^3.6.0-beta.10",
|
|
46
|
+
"vue": "^3.5.34 || ^3.6.0-beta.10"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsdown --dts",
|