|
|
@@ -1,11 +1,14 @@
|
|
|
import type { AsyncData } from '#app'
|
|
|
import type { ComputedRef, Ref } from 'vue'
|
|
|
import { v4 as uuid4 } from 'uuid'
|
|
|
+import type {
|
|
|
+ AsyncDataExecuteOptions,
|
|
|
+ AsyncDataRequestStatus,
|
|
|
+} from '#app/composables/asyncData'
|
|
|
import { useEntityManager } from '~/composables/data/useEntityManager'
|
|
|
import ApiResource from '~/models/ApiResource'
|
|
|
import type { Collection } from '~/types/data'
|
|
|
import Query from '~/services/data/Query'
|
|
|
-import type {AsyncDataExecuteOptions, AsyncDataRequestStatus} from "#app/composables/asyncData";
|
|
|
|
|
|
interface useEntityFetchReturnType {
|
|
|
fetch: (
|
|
|
@@ -18,11 +21,13 @@ interface useEntityFetchReturnType {
|
|
|
parent?: ApiResource | null,
|
|
|
query?: Query | null,
|
|
|
) => {
|
|
|
- data: ComputedRef<Collection | null>,
|
|
|
- pending: Ref<boolean>,
|
|
|
- refresh: (opts?: AsyncDataExecuteOptions) => Promise<ComputedRef<Collection> | null>,
|
|
|
- error: Ref<Error | null>,
|
|
|
- status: Ref<AsyncDataRequestStatus>,
|
|
|
+ data: ComputedRef<Collection | null>
|
|
|
+ pending: Ref<boolean>
|
|
|
+ refresh: (
|
|
|
+ opts?: AsyncDataExecuteOptions,
|
|
|
+ ) => Promise<ComputedRef<Collection> | null>
|
|
|
+ error: Ref<Error | null>
|
|
|
+ status: Ref<AsyncDataRequestStatus>
|
|
|
}
|
|
|
|
|
|
getRef: <T extends ApiResource>(
|
|
|
@@ -49,18 +54,18 @@ export const useEntityFetch = (
|
|
|
parent: ApiResource | null = null,
|
|
|
query: Query | null = null,
|
|
|
) => {
|
|
|
- const {data, pending, refresh, error, status } = useAsyncData(
|
|
|
+ const { data, pending, refresh, error, status } = useAsyncData(
|
|
|
model.entity + '_many_' + uuid4(),
|
|
|
() => em.fetchCollection(model, parent, query),
|
|
|
- {lazy, deep: true},
|
|
|
+ { lazy, deep: true },
|
|
|
)
|
|
|
|
|
|
return {
|
|
|
- data: computed(() => data.value !== null ? data.value.value : null),
|
|
|
+ data: computed(() => (data.value !== null ? data.value.value : null)),
|
|
|
pending,
|
|
|
refresh,
|
|
|
error,
|
|
|
- status
|
|
|
+ status,
|
|
|
}
|
|
|
}
|
|
|
|