@orpc/vue-query 0.0.0-next.ee0aeaf → 0.0.0-next.f56d2b3
Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js
CHANGED
@@ -47,22 +47,25 @@ function createProcedureUtils(client, path) {
|
|
47
47
|
const input = options?.input;
|
48
48
|
return {
|
49
49
|
queryKey: computed(() => buildKey(path, { type: "query", input: deepUnref(input) })),
|
50
|
-
queryFn: ({ signal }) => client(deepUnref(input), { signal }),
|
50
|
+
queryFn: ({ signal }) => client(deepUnref(input), { signal, context: deepUnref(options?.context) }),
|
51
51
|
...options
|
52
52
|
};
|
53
53
|
},
|
54
54
|
infiniteOptions(options) {
|
55
55
|
const input = options.input;
|
56
56
|
return {
|
57
|
+
initialPageParam: void 0,
|
57
58
|
queryKey: computed(() => buildKey(path, { type: "infinite", input: deepUnref(input) })),
|
58
|
-
queryFn: ({ pageParam, signal }) =>
|
59
|
+
queryFn: ({ pageParam, signal }) => {
|
60
|
+
return client({ ...deepUnref(input), cursor: pageParam }, { signal, context: deepUnref(options.context) });
|
61
|
+
},
|
59
62
|
...options
|
60
63
|
};
|
61
64
|
},
|
62
|
-
mutationOptions(options) {
|
65
|
+
mutationOptions(...[options]) {
|
63
66
|
return {
|
64
67
|
mutationKey: buildKey(path, { type: "mutation" }),
|
65
|
-
mutationFn: (input) => client(input),
|
68
|
+
mutationFn: (input) => client(input, { context: deepUnref(options?.context) }),
|
66
69
|
...options
|
67
70
|
};
|
68
71
|
}
|
package/dist/src/types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { AnyFunction, SetOptional } from '@orpc/shared';
|
2
|
-
import type {
|
3
|
-
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
2
|
+
import type { MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
|
3
|
+
import type { ComputedRef, MaybeRef, MaybeRefOrGetter } from 'vue';
|
4
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>;
|
@@ -8,24 +8,52 @@ export type NonUndefinedGuard<T> = T extends undefined ? never : T;
|
|
8
8
|
export type InferCursor<T> = T extends {
|
9
9
|
cursor?: any;
|
10
10
|
} ? T['cursor'] : never;
|
11
|
-
export type
|
11
|
+
export type QueryOptionsExtra<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
|
12
12
|
input?: MaybeDeepRef<TInput>;
|
13
13
|
} : {
|
14
14
|
input: MaybeDeepRef<TInput>;
|
15
|
+
}) & (undefined extends TClientContext ? {
|
16
|
+
context?: MaybeDeepRef<TClientContext>;
|
17
|
+
} : {
|
18
|
+
context: MaybeDeepRef<TClientContext>;
|
15
19
|
}) & SetOptional<{
|
16
|
-
[P in keyof QueryObserverOptions<TOutput,
|
20
|
+
[P in keyof QueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey>]: P extends 'enabled' ? MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey>[P]> : MaybeDeepRef<QueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey>[P]>;
|
17
21
|
}, 'queryKey'> & {
|
18
22
|
shallow?: MaybeRef<boolean>;
|
19
23
|
initialData?: NonUndefinedGuard<TOutput> | (() => NonUndefinedGuard<TOutput>) | undefined;
|
20
24
|
};
|
21
|
-
export
|
25
|
+
export interface QueryOptionsBase<TOutput, TError extends Error> {
|
26
|
+
queryKey: ComputedRef<QueryKey>;
|
27
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
28
|
+
retry?(failureCount: number, error: TError): boolean;
|
29
|
+
}
|
30
|
+
export type InfiniteOptionsExtra<TClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
|
22
31
|
input?: MaybeDeepRef<Omit<TInput, 'cursor'>>;
|
23
32
|
} : {
|
24
33
|
input: MaybeDeepRef<Omit<TInput, 'cursor'>>;
|
25
|
-
}) &
|
26
|
-
|
27
|
-
|
34
|
+
}) & (undefined extends TClientContext ? {
|
35
|
+
context?: MaybeDeepRef<TClientContext>;
|
36
|
+
} : {
|
37
|
+
context: MaybeDeepRef<TClientContext>;
|
38
|
+
}) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>;
|
39
|
+
export interface InfiniteOptionsBase<TInput, TOutput, TError extends Error> {
|
40
|
+
queryKey: ComputedRef<QueryKey>;
|
41
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>): Promise<TOutput>;
|
42
|
+
initialPageParam: undefined;
|
43
|
+
retry?(failureCount: number, error: TError): boolean;
|
44
|
+
}
|
45
|
+
export type MutationOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
|
46
|
+
context?: MaybeDeepRef<TClientContext>;
|
47
|
+
} : {
|
48
|
+
context: MaybeDeepRef<TClientContext>;
|
49
|
+
}) & {
|
50
|
+
[P in keyof MutationObserverOptions<TOutput, TError, TInput, unknown>]: MaybeDeepRef<MutationObserverOptions<TOutput, TError, TInput, unknown>[P]>;
|
28
51
|
} & {
|
29
52
|
shallow?: MaybeRef<boolean>;
|
30
53
|
};
|
54
|
+
export interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
|
55
|
+
mutationKey: QueryKey;
|
56
|
+
mutationFn(input: TInput): Promise<TOutput>;
|
57
|
+
retry?(failureCount: number, error: TError): boolean;
|
58
|
+
}
|
31
59
|
//# sourceMappingURL=types.d.ts.map
|
@@ -5,7 +5,7 @@ import type { MaybeDeepRef } from './types';
|
|
5
5
|
* Utils at any level (procedure or router)
|
6
6
|
*/
|
7
7
|
export interface GeneralUtils<TInput> {
|
8
|
-
key
|
8
|
+
key<UType extends KeyType = undefined>(options?: MaybeDeepRef<BuildKeyOptions<UType, TInput>>): QueryKey;
|
9
9
|
}
|
10
10
|
export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
11
11
|
//# sourceMappingURL=utils-general.d.ts.map
|
@@ -1,31 +1,13 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Client } from '@orpc/contract';
|
2
2
|
import type { IsEqual } from '@orpc/shared';
|
3
|
-
import type {
|
4
|
-
import type { ComputedRef } from 'vue';
|
5
|
-
import type { InfiniteOptions, MutationOptions, QueryOptions } from './types';
|
3
|
+
import type { InfiniteOptionsBase, InfiniteOptionsExtra, MutationOptionsBase, MutationOptionsExtra, QueryOptionsBase, QueryOptionsExtra } from './types';
|
6
4
|
/**
|
7
5
|
* Utils at procedure level
|
8
6
|
*/
|
9
|
-
export interface ProcedureUtils<TInput, TOutput> {
|
10
|
-
queryOptions
|
11
|
-
|
12
|
-
|
13
|
-
} : Omit<{
|
14
|
-
queryKey: ComputedRef<QueryKey>;
|
15
|
-
queryFn: () => Promise<TOutput>;
|
16
|
-
}, keyof U> & U;
|
17
|
-
infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, any>>(options: U) => Omit<{
|
18
|
-
queryKey: ComputedRef<QueryKey>;
|
19
|
-
queryFn: () => Promise<TOutput>;
|
20
|
-
initialPageParam: undefined;
|
21
|
-
}, keyof U> & U;
|
22
|
-
mutationOptions: <U extends MutationOptions<TInput, TOutput>>(options?: U) => IsEqual<U, MutationOptions<TInput, TOutput>> extends true ? {
|
23
|
-
mutationKey: QueryKey;
|
24
|
-
mutationFn: (input: TInput) => Promise<TOutput>;
|
25
|
-
} : Omit<{
|
26
|
-
mutationKey: QueryKey;
|
27
|
-
mutationFn: (input: TInput) => Promise<TOutput>;
|
28
|
-
}, keyof U> & U;
|
7
|
+
export interface ProcedureUtils<TClientContext, TInput, TOutput, TError extends Error> {
|
8
|
+
queryOptions<U extends QueryOptionsExtra<TClientContext, TInput, TOutput, TError, any>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)): IsEqual<U, QueryOptionsExtra<TClientContext, TInput, TOutput, TError, any>> extends true ? QueryOptionsBase<TOutput, TError> : Omit<QueryOptionsBase<TOutput, TError>, keyof U> & U;
|
9
|
+
infiniteOptions<U extends InfiniteOptionsExtra<TClientContext, TInput, TOutput, TError, any>>(options: U): Omit<InfiniteOptionsBase<TInput, TOutput, TError>, keyof U> & U;
|
10
|
+
mutationOptions<U extends MutationOptionsExtra<TClientContext, TInput, TOutput, TError>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)): IsEqual<U, MutationOptionsExtra<TClientContext, TInput, TOutput, TError>> extends true ? MutationOptionsBase<TInput, TOutput, TError> : Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U> & U;
|
29
11
|
}
|
30
|
-
export declare function createProcedureUtils<TInput, TOutput>(client:
|
12
|
+
export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
31
13
|
//# sourceMappingURL=utils-procedure.d.ts.map
|
@@ -1,14 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
3
|
-
import type { Lazy, Procedure, Router } from '@orpc/server';
|
1
|
+
import type { Client, NestedClient } from '@orpc/contract';
|
4
2
|
import { type GeneralUtils } from './utils-general';
|
5
3
|
import { type ProcedureUtils } from './utils-procedure';
|
6
|
-
export type RouterUtils<T extends
|
7
|
-
[K in keyof T]: T[K] extends
|
4
|
+
export type RouterUtils<T extends NestedClient<any>> = T extends Client<infer TClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<TClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
5
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
8
6
|
} & GeneralUtils<unknown>;
|
9
7
|
/**
|
10
8
|
* @param client - The client create form `@orpc/client`
|
11
9
|
* @param path - The base path for query key
|
12
10
|
*/
|
13
|
-
export declare function createRouterUtils<T extends
|
11
|
+
export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
|
14
12
|
//# 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.0.0-next.
|
4
|
+
"version": "0.0.0-next.f56d2b3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -34,9 +34,8 @@
|
|
34
34
|
"peerDependencies": {
|
35
35
|
"@tanstack/vue-query": ">=5.50.0",
|
36
36
|
"vue": ">=3.3.0",
|
37
|
-
"@orpc/client": "0.0.0-next.
|
38
|
-
"@orpc/
|
39
|
-
"@orpc/contract": "0.0.0-next.ee0aeaf"
|
37
|
+
"@orpc/client": "0.0.0-next.f56d2b3",
|
38
|
+
"@orpc/contract": "0.0.0-next.f56d2b3"
|
40
39
|
},
|
41
40
|
"scripts": {
|
42
41
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|