@piveau/sdk-vue 0.0.0-alpha.2 → 0.0.0-alpha.3
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 +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +14 -6
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToRef, Ref, ComputedRef, MaybeRef,
|
|
1
|
+
import { MaybeRefOrGetter, ToRef, Ref, ComputedRef, MaybeRef, InjectionKey, App } from 'vue-demi';
|
|
2
2
|
import { UseQueryReturnType, QueryClient } from '@tanstack/vue-query';
|
|
3
3
|
import { GetResourceResult, SearchParamsBase, SearchResult, SearchResultFacetGroup, SearchParams } from '@piveau/sdk-core';
|
|
4
4
|
import * as z from 'zod';
|
|
@@ -31,6 +31,11 @@ type UseResourceResult<TModelSchema = any, TContext = any, TGetterTree extends G
|
|
|
31
31
|
isLoading: Ref<boolean> | Ref<true> | Ref<false>;
|
|
32
32
|
isFetching: Ref<boolean>;
|
|
33
33
|
};
|
|
34
|
+
interface UseResourceParams {
|
|
35
|
+
additionalParams?: MaybeRefOrGetter<any>;
|
|
36
|
+
headers?: MaybeRefOrGetter<Record<string, string>>;
|
|
37
|
+
}
|
|
38
|
+
type UseResourceFunction = (resourceId: MaybeRefOrGetter<string>, params?: UseResourceParams) => UseResourceResult;
|
|
34
39
|
|
|
35
40
|
type Reffify<T> = {
|
|
36
41
|
[key in keyof T]: MaybeRef<T[key]>;
|
|
@@ -146,7 +151,7 @@ declare function defineResourceSearchOptions<TFacetNames extends string, TIndex
|
|
|
146
151
|
declare function createUseResourceSearch<TFacetNames extends string, TGettersTree extends GettersTree<TModelSchema, ResourceSearchOptions<TFacetNames, TIndex, TModelSchema>>, TIndex extends string = string, TModelSchema = any>({ resourceSearchOptions, options, getters, }: CreateUseResourceSearchParams<TFacetNames, TGettersTree, TIndex, TModelSchema>): {
|
|
147
152
|
useSearch: (params: UseSearchParams<string>) => UseSearchFactoryReturn<string, TModelSchema, TGettersTree>;
|
|
148
153
|
useResources: (params: UseSearchParams<string>) => UseSearchFactoryReturn<string, TModelSchema, TGettersTree>;
|
|
149
|
-
useResource:
|
|
154
|
+
useResource: UseResourceFunction;
|
|
150
155
|
refSyncedWithRouteQuery: <T extends string | number, K = T extends string ? string : T extends number ? number : never>(searchParam: keyof SearchParamsBase, defaultValue?: MaybeRefOrGetter<T> | undefined) => Ref<K>;
|
|
151
156
|
refSyncedWithRouteQueryFacet: <T_1 extends string[]>(searchParam: TFacetNames, defaultValue?: MaybeRefOrGetter<T_1> | undefined) => Ref<string[]>;
|
|
152
157
|
getters: TGettersTree;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToRef, Ref, ComputedRef, MaybeRef,
|
|
1
|
+
import { MaybeRefOrGetter, ToRef, Ref, ComputedRef, MaybeRef, InjectionKey, App } from 'vue-demi';
|
|
2
2
|
import { UseQueryReturnType, QueryClient } from '@tanstack/vue-query';
|
|
3
3
|
import { GetResourceResult, SearchParamsBase, SearchResult, SearchResultFacetGroup, SearchParams } from '@piveau/sdk-core';
|
|
4
4
|
import * as z from 'zod';
|
|
@@ -31,6 +31,11 @@ type UseResourceResult<TModelSchema = any, TContext = any, TGetterTree extends G
|
|
|
31
31
|
isLoading: Ref<boolean> | Ref<true> | Ref<false>;
|
|
32
32
|
isFetching: Ref<boolean>;
|
|
33
33
|
};
|
|
34
|
+
interface UseResourceParams {
|
|
35
|
+
additionalParams?: MaybeRefOrGetter<any>;
|
|
36
|
+
headers?: MaybeRefOrGetter<Record<string, string>>;
|
|
37
|
+
}
|
|
38
|
+
type UseResourceFunction = (resourceId: MaybeRefOrGetter<string>, params?: UseResourceParams) => UseResourceResult;
|
|
34
39
|
|
|
35
40
|
type Reffify<T> = {
|
|
36
41
|
[key in keyof T]: MaybeRef<T[key]>;
|
|
@@ -146,7 +151,7 @@ declare function defineResourceSearchOptions<TFacetNames extends string, TIndex
|
|
|
146
151
|
declare function createUseResourceSearch<TFacetNames extends string, TGettersTree extends GettersTree<TModelSchema, ResourceSearchOptions<TFacetNames, TIndex, TModelSchema>>, TIndex extends string = string, TModelSchema = any>({ resourceSearchOptions, options, getters, }: CreateUseResourceSearchParams<TFacetNames, TGettersTree, TIndex, TModelSchema>): {
|
|
147
152
|
useSearch: (params: UseSearchParams<string>) => UseSearchFactoryReturn<string, TModelSchema, TGettersTree>;
|
|
148
153
|
useResources: (params: UseSearchParams<string>) => UseSearchFactoryReturn<string, TModelSchema, TGettersTree>;
|
|
149
|
-
useResource:
|
|
154
|
+
useResource: UseResourceFunction;
|
|
150
155
|
refSyncedWithRouteQuery: <T extends string | number, K = T extends string ? string : T extends number ? number : never>(searchParam: keyof SearchParamsBase, defaultValue?: MaybeRefOrGetter<T> | undefined) => Ref<K>;
|
|
151
156
|
refSyncedWithRouteQueryFacet: <T_1 extends string[]>(searchParam: TFacetNames, defaultValue?: MaybeRefOrGetter<T_1> | undefined) => Ref<string[]>;
|
|
152
157
|
getters: TGettersTree;
|
package/dist/index.mjs
CHANGED
|
@@ -302,7 +302,7 @@ function useSearchFactory(options) {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
function useResourceFactory(options) {
|
|
305
|
-
|
|
305
|
+
const useResource = (resourceId, params) => {
|
|
306
306
|
const {
|
|
307
307
|
index,
|
|
308
308
|
indexSearch = index,
|
|
@@ -313,6 +313,10 @@ function useResourceFactory(options) {
|
|
|
313
313
|
getters = {},
|
|
314
314
|
fetcherFn
|
|
315
315
|
} = options;
|
|
316
|
+
const {
|
|
317
|
+
additionalParams,
|
|
318
|
+
headers
|
|
319
|
+
} = params ?? {};
|
|
316
320
|
assertQueryClient(qc);
|
|
317
321
|
const resolvedIndex = computed(() => index ?? indexSearch);
|
|
318
322
|
const query = useQuery(
|
|
@@ -320,15 +324,19 @@ function useResourceFactory(options) {
|
|
|
320
324
|
queryKey: computed(() => [
|
|
321
325
|
"pv-resource",
|
|
322
326
|
toValue(resolvedIndex),
|
|
323
|
-
toValue(resourceId)
|
|
327
|
+
toValue(resourceId),
|
|
328
|
+
...toValue(additionalParams) ? [toValue(additionalParams)] : [],
|
|
329
|
+
...toValue(headers) ? [toValue(headers)] : []
|
|
324
330
|
]),
|
|
325
331
|
queryFn: async () => {
|
|
326
|
-
const
|
|
332
|
+
const res = await fetcherFn({
|
|
327
333
|
baseUrl,
|
|
328
334
|
resource: toValue(resolvedIndex),
|
|
329
|
-
id: toValue(resourceId)
|
|
335
|
+
id: toValue(resourceId),
|
|
336
|
+
additionalParams: toValue(additionalParams),
|
|
337
|
+
headers: toValue(headers)
|
|
330
338
|
});
|
|
331
|
-
return
|
|
339
|
+
return res;
|
|
332
340
|
},
|
|
333
341
|
// placeholderData: keepPreviousData,
|
|
334
342
|
initialData() {
|
|
@@ -371,7 +379,7 @@ function useResourceFactory(options) {
|
|
|
371
379
|
getters: { ...computedGetters }
|
|
372
380
|
};
|
|
373
381
|
return obj;
|
|
374
|
-
}
|
|
382
|
+
};
|
|
375
383
|
return useResource;
|
|
376
384
|
}
|
|
377
385
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@piveau/sdk-vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-alpha.
|
|
4
|
+
"version": "0.0.0-alpha.3",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"pinia": "^2.1.7",
|
|
39
39
|
"vue-demi": ">=0.14.7",
|
|
40
40
|
"zod": "^3.22.4",
|
|
41
|
-
"@piveau/sdk-core": "^0.0.0-alpha.
|
|
41
|
+
"@piveau/sdk-core": "^0.0.0-alpha.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"msw": "^2.2.1",
|