@kimesh/query 0.2.35 → 0.2.36

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 CHANGED
@@ -741,6 +741,7 @@ declare function defer(queryClient: QueryClient$1, ...queries: DeferrableQueryOp
741
741
  declare function deferWithPromises(queryClient: QueryClient$1, ...queries: DeferrableQueryOptions[]): Promise<void>[];
742
742
  //#endregion
743
743
  //#region src/suspense.d.ts
744
+ type MaybeRefOrGetter$1<T> = T | Ref<T> | ComputedRef<T> | (() => T);
744
745
  /**
745
746
  * Infer TData from QueryOptionsOutput
746
747
  */
@@ -763,31 +764,37 @@ interface UseSuspenseQueryResult<TData> {
763
764
  * Returns a Promise that resolves to the query result when data is ready.
764
765
  * Use with top-level await in <script setup> to trigger Suspense.
765
766
  *
767
+ * Supports both static options and reactive options (getter function or ComputedRef).
768
+ * When using reactive options, the query will automatically refetch when dependencies change.
769
+ *
766
770
  * @example
767
771
  * ```vue
768
772
  * <script setup>
769
773
  * import { useSuspenseQuery } from '@kimesh/query'
770
774
  * import { postsQuery } from './posts.data'
771
775
  *
772
- * // Awaiting triggers Suspense - component suspends until data ready
773
- * // data is typed as Ref<Post[]> (not Ref<Post[] | undefined>)
776
+ * // Static options - fetches once
774
777
  * const { data: posts } = await useSuspenseQuery(postsQuery)
775
- * </script>
776
778
  *
777
- * <template>
778
- * <div v-for="post in posts" :key="post.id">{{ post.title }}</div>
779
- * </template>
779
+ * // Reactive options - refetches when filters change
780
+ * const filters = ref({ page: 1, status: 'active' })
781
+ * const { data: banners } = await useSuspenseQuery(
782
+ * () => bannerListQuery(filters.value)
783
+ * )
784
+ * </script>
780
785
  * ```
781
786
  */
782
- declare function useSuspenseQuery<T extends QueryOptionsOutput<unknown, QueryKey$1>>(options: T): Promise<UseSuspenseQueryResult<InferQueryData<T>>>;
787
+ declare function useSuspenseQuery<T extends QueryOptionsOutput<unknown, QueryKey$1>>(optionsOrGetter: MaybeRefOrGetter$1<T>): Promise<UseSuspenseQueryResult<InferQueryData<T>>>;
783
788
  /**
784
789
  * Suspense-compatible infinite query hook for Vue.
785
790
  *
791
+ * Supports both static options and reactive options (getter function or ComputedRef).
792
+ *
786
793
  * Note: This is a basic implementation. For full infinite query support,
787
794
  * you may need to extend the options interface to include initialPageParam
788
795
  * and getNextPageParam configuration.
789
796
  */
790
- declare function useSuspenseInfiniteQuery<T extends QueryOptionsOutput<unknown, QueryKey$1>>(options: T): Promise<UseInfiniteQueryReturnType<InferQueryData<T>, Error>>;
797
+ declare function useSuspenseInfiniteQuery<T extends QueryOptionsOutput<unknown, QueryKey$1>>(optionsOrGetter: MaybeRefOrGetter$1<T>): Promise<UseInfiniteQueryReturnType<InferQueryData<T>, Error>>;
791
798
  type UseSuspenseQueryReturnType<TData = unknown> = UseSuspenseQueryResult<TData>;
792
799
  //#endregion
793
800
  export { $fetch, type DeferrableQueryOptions, type FetchContext, type FetchError, type FetchPluginOptions, type FetchResponse, type FetchRuntimeConfig, KimeshQueryPlugin, type KimeshQueryPluginOptions, type KmAsyncDataContext, type KmAsyncDataResult, type KmFetchConfig, type KmFetchCreateOptions, type KmFetchInstance, type KmFetchRequestOptions, type LayerFetchPluginOptions, type LoadableComponent, type LoaderDefinition, QueryClient, type QueryKey, type QueryKeyFactory, type QueryPrefetchOptions, type UseKmAsyncDataOptions, type UseKmFetchOptions, type UseQueryReturnType, type UseSuspenseQueryReturnType, VueQueryPlugin, createKimeshQueryClient, createKmFetch, createNamedFetchPlugin, createPrefetcher, createQueryKeyFactory, defer, deferWithPromises, defineMutation, defineQuery, defineQueryOptions, executeLoader, extractLoaders, fetchPlugin, getCurrentLayer, getLayerFetch, hasLoader, initGlobalFetch, initLayerFetch, isLayerFetchInitialized, layerFetchPlugin, queryOptions, setCurrentLayer, setupQueryPrefetching, useGlobalFetch, useInfiniteQuery, useKmAsyncData, useKmData, useKmFetch, useLazyKmAsyncData, useLazyKmFetch, useMutation, useQuery, useQueryClient, useSuspenseInfiniteQuery, useSuspenseQuery };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { QueryClient, QueryClient as QueryClient$1, VueQueryPlugin, VueQueryPlugin as VueQueryPlugin$1, queryOptions, useInfiniteQuery, useInfiniteQuery as useInfiniteQuery$1, useMutation, useMutation as useMutation$1, useQuery, useQuery as useQuery$1, useQueryClient, useQueryClient as useQueryClient$1 } from "@tanstack/vue-query";
2
2
  import { ofetch } from "ofetch";
3
- import { computed, ref, toValue, watch } from "vue";
3
+ import { computed, isRef, ref, toValue, watch } from "vue";
4
4
  import { hash } from "ohash";
5
5
 
6
6
  //#region src/plugin.ts
@@ -947,55 +947,77 @@ function deferWithPromises(queryClient, ...queries) {
947
947
  * ```
948
948
  */
949
949
  /**
950
+ * Check if a value is a getter function (not a QueryOptionsOutput)
951
+ */
952
+ function isGetter(value) {
953
+ return typeof value === "function" && !("queryKey" in value);
954
+ }
955
+ /**
956
+ * Resolve a MaybeRefOrGetter to a computed ref
957
+ */
958
+ function resolveOptions(optionsOrGetter) {
959
+ if (isGetter(optionsOrGetter)) return computed(optionsOrGetter);
960
+ if (isRef(optionsOrGetter)) return optionsOrGetter;
961
+ return computed(() => optionsOrGetter);
962
+ }
963
+ /**
950
964
  * Suspense-compatible query hook for Vue.
951
965
  *
952
966
  * Returns a Promise that resolves to the query result when data is ready.
953
967
  * Use with top-level await in <script setup> to trigger Suspense.
954
968
  *
969
+ * Supports both static options and reactive options (getter function or ComputedRef).
970
+ * When using reactive options, the query will automatically refetch when dependencies change.
971
+ *
955
972
  * @example
956
973
  * ```vue
957
974
  * <script setup>
958
975
  * import { useSuspenseQuery } from '@kimesh/query'
959
976
  * import { postsQuery } from './posts.data'
960
977
  *
961
- * // Awaiting triggers Suspense - component suspends until data ready
962
- * // data is typed as Ref<Post[]> (not Ref<Post[] | undefined>)
978
+ * // Static options - fetches once
963
979
  * const { data: posts } = await useSuspenseQuery(postsQuery)
964
- * <\/script>
965
980
  *
966
- * <template>
967
- * <div v-for="post in posts" :key="post.id">{{ post.title }}</div>
968
- * </template>
981
+ * // Reactive options - refetches when filters change
982
+ * const filters = ref({ page: 1, status: 'active' })
983
+ * const { data: banners } = await useSuspenseQuery(
984
+ * () => bannerListQuery(filters.value)
985
+ * )
986
+ * <\/script>
969
987
  * ```
970
988
  */
971
- async function useSuspenseQuery(options) {
972
- const result = useQuery$1({
973
- queryKey: options.queryKey,
974
- queryFn: options.queryFn,
975
- staleTime: options.staleTime,
976
- gcTime: options.gcTime,
977
- enabled: options.enabled
978
- });
989
+ async function useSuspenseQuery(optionsOrGetter) {
990
+ const resolvedOptions = resolveOptions(optionsOrGetter);
991
+ const result = useQuery$1(computed(() => ({
992
+ queryKey: resolvedOptions.value.queryKey,
993
+ queryFn: resolvedOptions.value.queryFn,
994
+ staleTime: resolvedOptions.value.staleTime,
995
+ gcTime: resolvedOptions.value.gcTime,
996
+ enabled: resolvedOptions.value.enabled
997
+ })));
979
998
  await result.suspense();
980
999
  return result;
981
1000
  }
982
1001
  /**
983
1002
  * Suspense-compatible infinite query hook for Vue.
984
1003
  *
1004
+ * Supports both static options and reactive options (getter function or ComputedRef).
1005
+ *
985
1006
  * Note: This is a basic implementation. For full infinite query support,
986
1007
  * you may need to extend the options interface to include initialPageParam
987
1008
  * and getNextPageParam configuration.
988
1009
  */
989
- async function useSuspenseInfiniteQuery(options) {
990
- const result = useInfiniteQuery$1({
991
- queryKey: options.queryKey,
992
- queryFn: options.queryFn,
993
- staleTime: options.staleTime,
994
- gcTime: options.gcTime,
995
- enabled: options.enabled,
1010
+ async function useSuspenseInfiniteQuery(optionsOrGetter) {
1011
+ const resolvedOptions = resolveOptions(optionsOrGetter);
1012
+ const result = useInfiniteQuery$1(computed(() => ({
1013
+ queryKey: resolvedOptions.value.queryKey,
1014
+ queryFn: resolvedOptions.value.queryFn,
1015
+ staleTime: resolvedOptions.value.staleTime,
1016
+ gcTime: resolvedOptions.value.gcTime,
1017
+ enabled: resolvedOptions.value.enabled,
996
1018
  initialPageParam: 0,
997
1019
  getNextPageParam: () => void 0
998
- });
1020
+ })));
999
1021
  await result.suspense();
1000
1022
  return result;
1001
1023
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimesh/query",
3
- "version": "0.2.35",
3
+ "version": "0.2.36",
4
4
  "description": "Query utilities for Kimesh framework",
5
5
  "repository": {
6
6
  "type": "git",