@vc-shell/framework 1.0.41 → 1.0.43

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.
@@ -6,3 +6,6 @@ export { default as useNotifications } from "./useNotifications";
6
6
  export { default as useSettings } from "./useSettings";
7
7
  export { default as usePermissions } from "./usePermissions";
8
8
  export { default as useAutosave } from "./useAutosave";
9
+ export * from "./useAsync";
10
+ export * from "./useApiClient";
11
+ export * from "./useLoading";
@@ -0,0 +1,22 @@
1
+ import { AuthApiBase } from "@/core/api";
2
+ import useUser from "../useUser";
3
+
4
+ interface UseApiClient<ApiClient extends AuthApiBase> {
5
+ getApiClient: () => Promise<ApiClient>;
6
+ }
7
+
8
+ export function useApiClient<ApiClient extends AuthApiBase>(
9
+ c: new () => ApiClient
10
+ ): UseApiClient<ApiClient> {
11
+ const { getAccessToken } = useUser();
12
+
13
+ async function getApiClient() {
14
+ const client = new c();
15
+ client.setAuthToken(await getAccessToken());
16
+ return client;
17
+ }
18
+
19
+ return {
20
+ getApiClient,
21
+ };
22
+ }
@@ -0,0 +1,35 @@
1
+ import { readonly, ref } from "vue";
2
+ import { HasLoading } from "../useLoading";
3
+ import useLogger from "../useLogger";
4
+
5
+ export type AsyncAction<Payload = void, Result = void> = (
6
+ payload?: Payload
7
+ ) => Promise<Result>;
8
+
9
+ export interface UseAsync<Payload = void, Result = void> extends HasLoading {
10
+ action: AsyncAction<Payload, Result>;
11
+ }
12
+
13
+ export function useAsync<Payload = void, Result = void>(
14
+ innerAction: AsyncAction<Payload, Result>
15
+ ): UseAsync<Payload, Result> {
16
+ const logger = useLogger();
17
+ const loading = ref(false);
18
+
19
+ async function action(payload?: Payload): Promise<Result> {
20
+ loading.value = true;
21
+ try {
22
+ return await innerAction(payload);
23
+ } catch (e) {
24
+ logger.error(e);
25
+ throw e;
26
+ } finally {
27
+ loading.value = false;
28
+ }
29
+ }
30
+
31
+ return {
32
+ loading: readonly(loading),
33
+ action,
34
+ };
35
+ }
@@ -0,0 +1,11 @@
1
+ import { computed, ComputedRef, Ref } from "vue";
2
+
3
+ export interface HasLoading {
4
+ loading: Readonly<Ref<boolean>>;
5
+ }
6
+
7
+ export function useLoading(
8
+ ...args: Readonly<Ref<boolean>>[]
9
+ ): ComputedRef<boolean> {
10
+ return computed(() => args.some((item) => item.value));
11
+ }
@@ -6,4 +6,7 @@ export { default as useNotifications } from "./useNotifications";
6
6
  export { default as useSettings } from "./useSettings";
7
7
  export { default as usePermissions } from "./usePermissions";
8
8
  export { default as useAutosave } from "./useAutosave";
9
+ export * from "./useAsync";
10
+ export * from "./useApiClient";
11
+ export * from "./useLoading";
9
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/composables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/composables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { AuthApiBase } from "@/core/api";
2
+ interface UseApiClient<ApiClient extends AuthApiBase> {
3
+ getApiClient: () => Promise<ApiClient>;
4
+ }
5
+ export declare function useApiClient<ApiClient extends AuthApiBase>(c: new () => ApiClient): UseApiClient<ApiClient>;
6
+ export {};
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/composables/useApiClient/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,UAAU,YAAY,CAAC,SAAS,SAAS,WAAW;IAClD,YAAY,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;CACxC;AAED,wBAAgB,YAAY,CAAC,SAAS,SAAS,WAAW,EACxD,CAAC,EAAE,UAAU,SAAS,GACrB,YAAY,CAAC,SAAS,CAAC,CAYzB"}
@@ -0,0 +1,7 @@
1
+ import { HasLoading } from "../useLoading";
2
+ export type AsyncAction<Payload = void, Result = void> = (payload?: Payload) => Promise<Result>;
3
+ export interface UseAsync<Payload = void, Result = void> extends HasLoading {
4
+ action: AsyncAction<Payload, Result>;
5
+ }
6
+ export declare function useAsync<Payload = void, Result = void>(innerAction: AsyncAction<Payload, Result>): UseAsync<Payload, Result>;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/composables/useAsync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,MAAM,WAAW,CAAC,OAAO,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,CACvD,OAAO,CAAC,EAAE,OAAO,KACd,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,WAAW,QAAQ,CAAC,OAAO,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAE,SAAQ,UAAU;IACzE,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CACtC;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,EACpD,WAAW,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,GACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAoB3B"}
@@ -0,0 +1,6 @@
1
+ import { ComputedRef, Ref } from "vue";
2
+ export interface HasLoading {
3
+ loading: Readonly<Ref<boolean>>;
4
+ }
5
+ export declare function useLoading(...args: Readonly<Ref<boolean>>[]): ComputedRef<boolean>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/composables/useLoading/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAEjD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;CACjC;AAED,wBAAgB,UAAU,CACxB,GAAG,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,GAChC,WAAW,CAAC,OAAO,CAAC,CAEtB"}