@data-fair/lib-vue 1.3.0 → 1.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/fetch.d.ts +2 -0
- package/fetch.js +13 -4
- package/package.json +1 -1
- package/session.d.ts +3 -0
package/fetch.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import type { QueryObject } from 'ufo';
|
|
|
2
2
|
import type { Ref } from 'vue';
|
|
3
3
|
type UseFetchOptions = {
|
|
4
4
|
query?: QueryObject | Ref<QueryObject>;
|
|
5
|
+
watch?: Boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare function useFetch<T>(url: string | Ref<string>, options?: UseFetchOptions): {
|
|
7
8
|
data: [T | null] extends [Ref<any, any>] ? import("@vue/shared").IfAny<Ref<any, any> & T, Ref<Ref<any, any> & T, Ref<any, any> & T>, Ref<any, any> & T> : Ref<import("vue").UnwrapRef<T> | null, T | import("vue").UnwrapRef<T> | null>;
|
|
8
9
|
loading: Ref<boolean, boolean>;
|
|
9
10
|
refresh: () => Promise<void>;
|
|
11
|
+
initialFetch: () => Promise<void>;
|
|
10
12
|
};
|
|
11
13
|
export default useFetch;
|
package/fetch.js
CHANGED
|
@@ -12,16 +12,25 @@ export function useFetch (url, options = {}) {
|
|
|
12
12
|
})
|
|
13
13
|
const data = ref(null)
|
|
14
14
|
const loading = ref(false)
|
|
15
|
+
let abortController
|
|
15
16
|
const refresh = async () => {
|
|
17
|
+
if (abortController) { abortController.abort() }
|
|
16
18
|
loading.value = true
|
|
19
|
+
abortController = new AbortController()
|
|
17
20
|
try {
|
|
18
|
-
data.value = await ofetch(fullUrl.value)
|
|
21
|
+
data.value = await ofetch(fullUrl.value, { signal: abortController.signal })
|
|
19
22
|
} catch (error) {
|
|
20
|
-
sendUiNotif({ msg: '', error })
|
|
23
|
+
if (error.name !== 'AbortError') { sendUiNotif({ msg: '', error }) }
|
|
21
24
|
}
|
|
22
25
|
loading.value = false
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const initialFetch = async () => {
|
|
28
|
+
if (loading.value || data.value) { return }
|
|
29
|
+
await refresh()
|
|
30
|
+
}
|
|
31
|
+
if (options.watch !== false) {
|
|
32
|
+
watch(fullUrl, refresh, { immediate: true })
|
|
33
|
+
}
|
|
34
|
+
return { data, loading, refresh, initialFetch }
|
|
26
35
|
}
|
|
27
36
|
export default useFetch
|
package/package.json
CHANGED
package/session.d.ts
CHANGED
|
@@ -41,6 +41,9 @@ export interface Session {
|
|
|
41
41
|
}
|
|
42
42
|
export type SessionAuthenticated = Session & {
|
|
43
43
|
state: SessionStateAuthenticated;
|
|
44
|
+
user: ComputedRef<SessionStateAuthenticated['user']>;
|
|
45
|
+
account: ComputedRef<SessionStateAuthenticated['account']>;
|
|
46
|
+
accountRole: ComputedRef<SessionStateAuthenticated['accountRole']>;
|
|
44
47
|
};
|
|
45
48
|
export declare function getSession(initOptions: Partial<SessionOptions>): Promise<Session>;
|
|
46
49
|
export declare const sessionKey: unique symbol;
|