@orpc/vue-query 0.0.0-next.fd13879 → 0.0.0-next.fd6982a
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 +21 -14
- package/dist/index.d.ts +21 -14
- package/dist/index.mjs +26 -12
- package/package.json +7 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { OperationType, BuildKeyOptions } from '@orpc/tanstack-query';
|
|
3
|
+
export { BuildKeyOptions, OperationType as KeyType, buildKey } from '@orpc/tanstack-query';
|
|
4
|
+
import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
|
5
|
+
import { AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
|
|
4
6
|
import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
|
5
7
|
|
|
6
|
-
type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
|
|
7
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
8
|
-
type?: TType;
|
|
9
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
10
|
-
}
|
|
11
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
12
|
-
|
|
13
8
|
interface GeneralUtils<TInput> {
|
|
14
9
|
/**
|
|
15
10
|
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
|
16
11
|
*
|
|
17
12
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
18
13
|
*/
|
|
19
|
-
key<UType extends
|
|
14
|
+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
20
15
|
}
|
|
21
16
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
22
17
|
|
|
@@ -45,9 +40,14 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
45
40
|
interface QueryOptionsBase<TOutput, TError> {
|
|
46
41
|
queryKey: ComputedRef<QueryKey>;
|
|
47
42
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
48
|
-
|
|
43
|
+
throwOnError?(error: TError): boolean;
|
|
49
44
|
enabled: ComputedRef<boolean>;
|
|
50
45
|
}
|
|
46
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
47
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
48
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
|
|
49
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
50
|
+
}
|
|
51
51
|
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
|
52
52
|
context?: MaybeRefDeep<TClientContext>;
|
|
53
53
|
} : {
|
|
@@ -63,7 +63,7 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
63
63
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
64
64
|
queryKey: ComputedRef<QueryKey>;
|
|
65
65
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
66
|
-
|
|
66
|
+
throwOnError?(error: TError): boolean;
|
|
67
67
|
enabled: ComputedRef<boolean>;
|
|
68
68
|
}
|
|
69
69
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
@@ -90,6 +90,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
90
90
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
91
91
|
*/
|
|
92
92
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
|
95
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
|
98
|
+
*/
|
|
99
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
|
93
100
|
/**
|
|
94
101
|
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
|
95
102
|
*
|
|
@@ -127,5 +134,5 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
|
|
|
127
134
|
} : T;
|
|
128
135
|
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
|
129
136
|
|
|
130
|
-
export {
|
|
131
|
-
export type {
|
|
137
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
|
138
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { OperationType, BuildKeyOptions } from '@orpc/tanstack-query';
|
|
3
|
+
export { BuildKeyOptions, OperationType as KeyType, buildKey } from '@orpc/tanstack-query';
|
|
4
|
+
import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
|
|
5
|
+
import { AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
|
|
4
6
|
import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
|
5
7
|
|
|
6
|
-
type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
|
|
7
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
8
|
-
type?: TType;
|
|
9
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
10
|
-
}
|
|
11
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
12
|
-
|
|
13
8
|
interface GeneralUtils<TInput> {
|
|
14
9
|
/**
|
|
15
10
|
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
|
16
11
|
*
|
|
17
12
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
18
13
|
*/
|
|
19
|
-
key<UType extends
|
|
14
|
+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
20
15
|
}
|
|
21
16
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
22
17
|
|
|
@@ -45,9 +40,14 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
45
40
|
interface QueryOptionsBase<TOutput, TError> {
|
|
46
41
|
queryKey: ComputedRef<QueryKey>;
|
|
47
42
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
48
|
-
|
|
43
|
+
throwOnError?(error: TError): boolean;
|
|
49
44
|
enabled: ComputedRef<boolean>;
|
|
50
45
|
}
|
|
46
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
47
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
48
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
|
|
49
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
50
|
+
}
|
|
51
51
|
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
|
|
52
52
|
context?: MaybeRefDeep<TClientContext>;
|
|
53
53
|
} : {
|
|
@@ -63,7 +63,7 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
63
63
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
64
64
|
queryKey: ComputedRef<QueryKey>;
|
|
65
65
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
66
|
-
|
|
66
|
+
throwOnError?(error: TError): boolean;
|
|
67
67
|
enabled: ComputedRef<boolean>;
|
|
68
68
|
}
|
|
69
69
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
@@ -90,6 +90,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
90
90
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
91
91
|
*/
|
|
92
92
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
|
95
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
|
98
|
+
*/
|
|
99
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
|
93
100
|
/**
|
|
94
101
|
* Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
|
|
95
102
|
*
|
|
@@ -127,5 +134,5 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
|
|
|
127
134
|
} : T;
|
|
128
135
|
declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
|
129
136
|
|
|
130
|
-
export {
|
|
131
|
-
export type {
|
|
137
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
|
138
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildKey } from '@orpc/tanstack-query';
|
|
2
|
+
export { buildKey } from '@orpc/tanstack-query';
|
|
3
|
+
import { isObject, isAsyncIteratorObject } from '@orpc/shared';
|
|
4
|
+
import { skipToken, experimental_streamedQuery } from '@tanstack/vue-query';
|
|
2
5
|
import { isRef, computed } from 'vue';
|
|
3
|
-
import { isObject } from '@orpc/shared';
|
|
4
|
-
|
|
5
|
-
function buildKey(path, options) {
|
|
6
|
-
const withInput = options?.input !== void 0 ? { input: options?.input } : {};
|
|
7
|
-
const withType = options?.type !== void 0 ? { type: options?.type } : {};
|
|
8
|
-
return [path, {
|
|
9
|
-
...withInput,
|
|
10
|
-
...withType
|
|
11
|
-
}];
|
|
12
|
-
}
|
|
13
6
|
|
|
14
7
|
function createGeneralUtils(path) {
|
|
15
8
|
return {
|
|
@@ -52,6 +45,27 @@ function createProcedureUtils(client, options) {
|
|
|
52
45
|
...optionsIn
|
|
53
46
|
};
|
|
54
47
|
},
|
|
48
|
+
experimental_streamedOptions(...[optionsIn = {}]) {
|
|
49
|
+
return {
|
|
50
|
+
enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
|
|
51
|
+
queryKey: computed(() => buildKey(options.path, { type: "streamed", input: unrefDeep(optionsIn.input) })),
|
|
52
|
+
queryFn: experimental_streamedQuery({
|
|
53
|
+
...optionsIn,
|
|
54
|
+
queryFn: async ({ signal }) => {
|
|
55
|
+
const input = unrefDeep(optionsIn.input);
|
|
56
|
+
if (input === skipToken) {
|
|
57
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
58
|
+
}
|
|
59
|
+
const output = await client(input, { signal, context: unrefDeep(optionsIn.context) });
|
|
60
|
+
if (!isAsyncIteratorObject(output)) {
|
|
61
|
+
throw new Error("streamedQuery requires an event iterator output");
|
|
62
|
+
}
|
|
63
|
+
return output;
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
...optionsIn
|
|
67
|
+
};
|
|
68
|
+
},
|
|
55
69
|
infiniteOptions(optionsIn) {
|
|
56
70
|
return {
|
|
57
71
|
queryKey: computed(() => {
|
|
@@ -109,4 +123,4 @@ function createRouterUtils(client, options = {}) {
|
|
|
109
123
|
return recursive;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
export {
|
|
126
|
+
export { createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
|
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.fd6982a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,11 +29,14 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@tanstack/vue-query": ">=5.55.0",
|
|
31
31
|
"vue": ">=3.3.0",
|
|
32
|
-
"@orpc/client": "0.0.0-next.
|
|
32
|
+
"@orpc/client": "0.0.0-next.fd6982a"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@orpc/
|
|
35
|
+
"@orpc/shared": "0.0.0-next.fd6982a",
|
|
36
|
+
"@orpc/tanstack-query": "0.0.0-next.fd6982a"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tanstack/vue-query": "^5.77.2"
|
|
37
40
|
},
|
|
38
41
|
"scripts": {
|
|
39
42
|
"build": "unbuild",
|