|
|
@@ -5,6 +5,7 @@ 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: (
|
|
|
@@ -16,7 +17,13 @@ interface useEntityFetchReturnType {
|
|
|
model: typeof ApiResource,
|
|
|
parent?: ApiResource | null,
|
|
|
query?: Query | null,
|
|
|
- ) => AsyncData<ComputedRef<Collection> | null, Error | null>
|
|
|
+ ) => {
|
|
|
+ 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>(
|
|
|
model: new () => T,
|
|
|
@@ -41,13 +48,22 @@ export const useEntityFetch = (
|
|
|
model: typeof ApiResource,
|
|
|
parent: ApiResource | null = null,
|
|
|
query: Query | null = null,
|
|
|
- ) =>
|
|
|
- useAsyncData(
|
|
|
+ ) => {
|
|
|
+ const {data, pending, refresh, error, status } = useAsyncData(
|
|
|
model.entity + '_many_' + uuid4(),
|
|
|
() => em.fetchCollection(model, parent, query),
|
|
|
- { lazy, deep: false },
|
|
|
+ {lazy, deep: true},
|
|
|
)
|
|
|
|
|
|
+ return {
|
|
|
+ data: computed(() => data.value !== null ? data.value.value : null),
|
|
|
+ pending,
|
|
|
+ refresh,
|
|
|
+ error,
|
|
|
+ status
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
const getRef = <T extends ApiResource>(
|
|
|
model: new () => T,
|
|
|
id: Ref<number | null>,
|