@orpc/vue-query 0.0.0 → 0.16.0
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.js
CHANGED
@@ -12,15 +12,6 @@ function buildKey(path, options) {
|
|
12
12
|
];
|
13
13
|
}
|
14
14
|
|
15
|
-
// src/utils-general.ts
|
16
|
-
function createGeneralUtils(path) {
|
17
|
-
return {
|
18
|
-
key(options) {
|
19
|
-
return buildKey(path, options);
|
20
|
-
}
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
15
|
// src/utils.ts
|
25
16
|
import { isRef } from "vue";
|
26
17
|
function deepUnref(value) {
|
@@ -39,22 +30,32 @@ function deepUnref(value) {
|
|
39
30
|
return value;
|
40
31
|
}
|
41
32
|
|
33
|
+
// src/utils-general.ts
|
34
|
+
function createGeneralUtils(path) {
|
35
|
+
return {
|
36
|
+
key(options) {
|
37
|
+
return buildKey(path, deepUnref(options));
|
38
|
+
}
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
42
|
// src/utils-procedure.ts
|
43
|
+
import { computed } from "vue";
|
43
44
|
function createProcedureUtils(client, path) {
|
44
45
|
return {
|
45
46
|
queryOptions(...[options]) {
|
46
47
|
const input = options?.input;
|
47
48
|
return {
|
48
|
-
queryKey: buildKey(path, { type: "query", input }),
|
49
|
-
queryFn: () => client(deepUnref(input)),
|
49
|
+
queryKey: computed(() => buildKey(path, { type: "query", input: deepUnref(input) })),
|
50
|
+
queryFn: ({ signal }) => client(deepUnref(input), { signal }),
|
50
51
|
...options
|
51
52
|
};
|
52
53
|
},
|
53
54
|
infiniteOptions(options) {
|
54
55
|
const input = options.input;
|
55
56
|
return {
|
56
|
-
queryKey: buildKey(path, { type: "infinite", input }),
|
57
|
-
queryFn: ({ pageParam }) => client({ ...deepUnref(input), cursor: pageParam }),
|
57
|
+
queryKey: computed(() => buildKey(path, { type: "infinite", input: deepUnref(input) })),
|
58
|
+
queryFn: ({ pageParam, signal }) => client({ ...deepUnref(input), cursor: pageParam }, { signal }),
|
58
59
|
...options
|
59
60
|
};
|
60
61
|
},
|
package/dist/src/types.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import type { SetOptional } from '@orpc/shared';
|
1
|
+
import type { AnyFunction, SetOptional } from '@orpc/shared';
|
2
2
|
import type { DefaultError, MutationObserverOptions, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
|
3
3
|
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
4
|
-
export type MaybeDeepRef<T> = MaybeRef<T extends object ? {
|
4
|
+
export type MaybeDeepRef<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
5
5
|
[K in keyof T]: MaybeDeepRef<T[K]>;
|
6
6
|
} : T>;
|
7
7
|
export type NonUndefinedGuard<T> = T extends undefined ? never : T;
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import type { QueryKey } from '@tanstack/vue-query';
|
2
2
|
import type { BuildKeyOptions, KeyType } from './key';
|
3
|
+
import type { MaybeDeepRef } from './types';
|
3
4
|
/**
|
4
5
|
* Utils at any level (procedure or router)
|
5
6
|
*/
|
6
7
|
export interface GeneralUtils<TInput> {
|
7
|
-
key: <UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput
|
8
|
+
key: <UType extends KeyType = undefined>(options?: MaybeDeepRef<BuildKeyOptions<UType, TInput>>) => QueryKey;
|
8
9
|
}
|
9
10
|
export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
10
11
|
//# sourceMappingURL=utils-general.d.ts.map
|
@@ -1,19 +1,21 @@
|
|
1
|
+
import type { Caller } from '@orpc/server';
|
1
2
|
import type { IsEqual } from '@orpc/shared';
|
2
3
|
import type { QueryKey } from '@tanstack/vue-query';
|
4
|
+
import type { ComputedRef } from 'vue';
|
3
5
|
import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
|
4
6
|
/**
|
5
7
|
* Utils at procedure level
|
6
8
|
*/
|
7
9
|
export interface ProcedureUtils<TInput, TOutput> {
|
8
|
-
queryOptions: <U extends QueryOptions<TInput, TOutput,
|
10
|
+
queryOptions: <U extends QueryOptions<TInput, TOutput, any>>(...options: [U] | (undefined extends TInput ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, any>> extends true ? {
|
9
11
|
queryKey: QueryKey;
|
10
12
|
queryFn: () => Promise<TOutput>;
|
11
13
|
} : Omit<{
|
12
|
-
queryKey: QueryKey
|
14
|
+
queryKey: ComputedRef<QueryKey>;
|
13
15
|
queryFn: () => Promise<TOutput>;
|
14
16
|
}, keyof U> & U;
|
15
17
|
infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, any>>(options: U) => Omit<{
|
16
|
-
queryKey: QueryKey
|
18
|
+
queryKey: ComputedRef<QueryKey>;
|
17
19
|
queryFn: () => Promise<TOutput>;
|
18
20
|
initialPageParam: undefined;
|
19
21
|
}, keyof U> & U;
|
@@ -25,5 +27,5 @@ export interface ProcedureUtils<TInput, TOutput> {
|
|
25
27
|
mutationFn: (input: TInput) => Promise<TOutput>;
|
26
28
|
}, keyof U> & U;
|
27
29
|
}
|
28
|
-
export declare function createProcedureUtils<TInput, TOutput>(client:
|
30
|
+
export declare function createProcedureUtils<TInput, TOutput>(client: Caller<TInput, TOutput>, path: string[]): ProcedureUtils<TInput, TOutput>;
|
29
31
|
//# sourceMappingURL=utils-procedure.d.ts.map
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { RouterClient } from '@orpc/client';
|
1
2
|
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
3
|
import type { Lazy, Procedure, Router } from '@orpc/server';
|
3
4
|
import { type GeneralUtils } from './utils-general';
|
@@ -9,6 +10,5 @@ export type RouterUtils<T extends Router<any> | ContractRouter> = {
|
|
9
10
|
* @param client - The client create form `@orpc/client`
|
10
11
|
* @param path - The base path for query key
|
11
12
|
*/
|
12
|
-
export declare function createRouterUtils<T extends Router<any> | ContractRouter>(client:
|
13
|
-
path?: string[]): RouterUtils<T>;
|
13
|
+
export declare function createRouterUtils<T extends Router<any> | ContractRouter>(client: RouterClient<T>, path?: string[]): RouterUtils<T>;
|
14
14
|
//# sourceMappingURL=utils-router.d.ts.map
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/vue-query",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.16.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -34,9 +34,9 @@
|
|
34
34
|
"peerDependencies": {
|
35
35
|
"@tanstack/vue-query": ">=5.50.0",
|
36
36
|
"vue": ">=3.3.0",
|
37
|
-
"@orpc/contract": "0.
|
38
|
-
"@orpc/client": "0.
|
39
|
-
"@orpc/server": "0.
|
37
|
+
"@orpc/contract": "0.16.0",
|
38
|
+
"@orpc/client": "0.16.0",
|
39
|
+
"@orpc/server": "0.16.0"
|
40
40
|
},
|
41
41
|
"scripts": {
|
42
42
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|