@orpc/vue-query 1.1.1 → 1.3.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/README.md CHANGED
@@ -49,6 +49,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
49
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
50
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
51
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
52
53
  - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
53
54
  - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
54
55
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, QueryObserverOptions, QueryFunctionContext, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
2
+ import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
3
  import { PartialDeep, AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
4
4
  import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
5
 
6
- type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
6
+ type KeyType = 'query' | 'streamed' | 'infinite' | 'mutation' | undefined;
7
7
  interface BuildKeyOptions<TType extends KeyType, TInput> {
8
8
  type?: TType;
9
9
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
@@ -28,9 +28,9 @@ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
28
28
  [Property in keyof T]: MaybeRefDeep<T[Property]>;
29
29
  } : T>;
30
30
  type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
31
- input?: MaybeRefDeep<TInput>;
31
+ input?: MaybeRefDeep<TInput | SkipToken>;
32
32
  } : {
33
- input: MaybeRefDeep<TInput>;
33
+ input: MaybeRefDeep<TInput | SkipToken>;
34
34
  }) & (Record<never, never> extends TClientContext ? {
35
35
  context?: MaybeRefDeep<TClientContext>;
36
36
  } : {
@@ -45,17 +45,22 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
45
45
  interface QueryOptionsBase<TOutput, TError> {
46
46
  queryKey: ComputedRef<QueryKey>;
47
47
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
48
- retry?(failureCount: number, error: TError): boolean;
48
+ throwOnError?(error: TError): boolean;
49
+ enabled: ComputedRef<boolean>;
49
50
  }
50
- type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
51
- input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
52
- } & (Record<never, never> extends TClientContext ? {
51
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
52
+ type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
53
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
54
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
55
+ }
56
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
53
57
  context?: MaybeRefDeep<TClientContext>;
54
58
  } : {
55
59
  context: MaybeRefDeep<TClientContext>;
56
60
  }) & {
57
61
  [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>[Property]>;
58
62
  } & {
63
+ input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
59
64
  enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['enabled']>;
60
65
  queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['queryKey']>;
61
66
  shallow?: boolean;
@@ -63,7 +68,8 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
63
68
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
69
  queryKey: ComputedRef<QueryKey>;
65
70
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
66
- retry?(failureCount: number, error: TError): boolean;
71
+ throwOnError?(error: TError): boolean;
72
+ enabled: ComputedRef<boolean>;
67
73
  }
68
74
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
69
75
  context?: TClientContext;
@@ -89,6 +95,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
89
95
  * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
90
96
  */
91
97
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
98
+ /**
99
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
100
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
101
+ *
102
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
103
+ */
104
+ 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>>;
92
105
  /**
93
106
  * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
94
107
  *
@@ -127,4 +140,4 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
127
140
  declare function unrefDeep<T>(value: T): UnrefDeep<T>;
128
141
 
129
142
  export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
130
- export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
143
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, QueryObserverOptions, QueryFunctionContext, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
2
+ import { QueryKey, SkipToken, QueryObserverOptions, QueryFunctionContext, experimental_streamedQuery, InfiniteQueryObserverOptions, MutationObserverOptions, InfiniteData } from '@tanstack/vue-query';
3
3
  import { PartialDeep, AnyFunction, MaybeOptionalOptions } from '@orpc/shared';
4
4
  import { MaybeRef, MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
5
5
 
6
- type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
6
+ type KeyType = 'query' | 'streamed' | 'infinite' | 'mutation' | undefined;
7
7
  interface BuildKeyOptions<TType extends KeyType, TInput> {
8
8
  type?: TType;
9
9
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
@@ -28,9 +28,9 @@ type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
28
28
  [Property in keyof T]: MaybeRefDeep<T[Property]>;
29
29
  } : T>;
30
30
  type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
31
- input?: MaybeRefDeep<TInput>;
31
+ input?: MaybeRefDeep<TInput | SkipToken>;
32
32
  } : {
33
- input: MaybeRefDeep<TInput>;
33
+ input: MaybeRefDeep<TInput | SkipToken>;
34
34
  }) & (Record<never, never> extends TClientContext ? {
35
35
  context?: MaybeRefDeep<TClientContext>;
36
36
  } : {
@@ -45,17 +45,22 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
45
45
  interface QueryOptionsBase<TOutput, TError> {
46
46
  queryKey: ComputedRef<QueryKey>;
47
47
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
48
- retry?(failureCount: number, error: TError): boolean;
48
+ throwOnError?(error: TError): boolean;
49
+ enabled: ComputedRef<boolean>;
49
50
  }
50
- type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
51
- input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
52
- } & (Record<never, never> extends TClientContext ? {
51
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
52
+ type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
53
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
54
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
55
+ }
56
+ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = (Record<never, never> extends TClientContext ? {
53
57
  context?: MaybeRefDeep<TClientContext>;
54
58
  } : {
55
59
  context: MaybeRefDeep<TClientContext>;
56
60
  }) & {
57
61
  [Property in keyof Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey' | 'enabled'>]: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>[Property]>;
58
62
  } & {
63
+ input: MaybeRef<((pageParam: TPageParam) => MaybeRefDeep<TInput>) | SkipToken>;
59
64
  enabled?: MaybeRefOrGetter<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['enabled']>;
60
65
  queryKey?: MaybeRefDeep<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>['queryKey']>;
61
66
  shallow?: boolean;
@@ -63,7 +68,8 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
63
68
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
64
69
  queryKey: ComputedRef<QueryKey>;
65
70
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
66
- retry?(failureCount: number, error: TError): boolean;
71
+ throwOnError?(error: TError): boolean;
72
+ enabled: ComputedRef<boolean>;
67
73
  }
68
74
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
69
75
  context?: TClientContext;
@@ -89,6 +95,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
89
95
  * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
90
96
  */
91
97
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
98
+ /**
99
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
100
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
101
+ *
102
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
103
+ */
104
+ 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>>;
92
105
  /**
93
106
  * Generate options used for useInfiniteQuery/prefetchInfiniteQuery/...
94
107
  *
@@ -127,4 +140,4 @@ type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunctio
127
140
  declare function unrefDeep<T>(value: T): UnrefDeep<T>;
128
141
 
129
142
  export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueQueryUtils, createProcedureUtils, createRouterUtils, unrefDeep };
130
- export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep };
143
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MaybeRefDeep, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, UnrefDeep, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ import { isObject, isAsyncIteratorObject } from '@orpc/shared';
2
+ import { skipToken, experimental_streamedQuery } from '@tanstack/vue-query';
1
3
  import { isRef, computed } from 'vue';
2
- import { isObject } from '@orpc/shared';
3
4
 
4
5
  function buildKey(path, options) {
5
6
  const withInput = options?.input !== void 0 ? { input: options?.input } : {};
@@ -40,18 +41,55 @@ function createProcedureUtils(client, options) {
40
41
  queryOptions(...[optionsIn = {}]) {
41
42
  return {
42
43
  queryKey: computed(() => buildKey(options.path, { type: "query", input: unrefDeep(optionsIn.input) })),
43
- queryFn: ({ signal }) => client(unrefDeep(optionsIn.input), { signal, context: unrefDeep(optionsIn.context) }),
44
+ queryFn: ({ signal }) => {
45
+ const input = unrefDeep(optionsIn.input);
46
+ if (input === skipToken) {
47
+ throw new Error("queryFn should not be called with skipToken used as input");
48
+ }
49
+ return client(input, { signal, context: unrefDeep(optionsIn.context) });
50
+ },
51
+ enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
52
+ ...optionsIn
53
+ };
54
+ },
55
+ experimental_streamedOptions(...[optionsIn = {}]) {
56
+ return {
57
+ enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
58
+ queryKey: computed(() => buildKey(options.path, { type: "streamed", input: unrefDeep(optionsIn.input) })),
59
+ queryFn: experimental_streamedQuery({
60
+ ...optionsIn,
61
+ queryFn: async ({ signal }) => {
62
+ const input = unrefDeep(optionsIn.input);
63
+ if (input === skipToken) {
64
+ throw new Error("queryFn should not be called with skipToken used as input");
65
+ }
66
+ const output = await client(input, { signal, context: unrefDeep(optionsIn.context) });
67
+ if (!isAsyncIteratorObject(output)) {
68
+ throw new Error("streamedQuery requires an event iterator output");
69
+ }
70
+ return output;
71
+ }
72
+ }),
44
73
  ...optionsIn
45
74
  };
46
75
  },
47
76
  infiniteOptions(optionsIn) {
48
77
  return {
49
78
  queryKey: computed(() => {
50
- return buildKey(options.path, { type: "infinite", input: unrefDeep(optionsIn.input(unrefDeep(optionsIn.initialPageParam))) });
79
+ const input = unrefDeep(optionsIn.input);
80
+ return buildKey(options.path, {
81
+ type: "infinite",
82
+ input: input === skipToken ? skipToken : unrefDeep(input(unrefDeep(optionsIn.initialPageParam)))
83
+ });
51
84
  }),
52
85
  queryFn: ({ pageParam, signal }) => {
53
- return client(unrefDeep(optionsIn.input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
86
+ const input = unrefDeep(optionsIn.input);
87
+ if (input === skipToken) {
88
+ throw new Error("queryFn should not be called with skipToken used as input");
89
+ }
90
+ return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(optionsIn.context) });
54
91
  },
92
+ enabled: computed(() => unrefDeep(optionsIn.input) !== skipToken),
55
93
  ...optionsIn
56
94
  };
57
95
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-query",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.3.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,11 +29,13 @@
29
29
  "peerDependencies": {
30
30
  "@tanstack/vue-query": ">=5.55.0",
31
31
  "vue": ">=3.3.0",
32
- "@orpc/client": "1.1.1"
32
+ "@orpc/client": "1.3.0"
33
33
  },
34
34
  "dependencies": {
35
- "@tanstack/vue-query": "^5.72.2",
36
- "@orpc/shared": "1.1.1"
35
+ "@orpc/shared": "1.3.0"
36
+ },
37
+ "devDependencies": {
38
+ "@tanstack/vue-query": "^5.72.3"
37
39
  },
38
40
  "scripts": {
39
41
  "build": "unbuild",