@orpc/svelte-query 0.0.0-next.f72e6b9 → 0.0.0-next.fa75202

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,8 +1,8 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, CreateQueryOptions, QueryFunctionContext, CreateInfiniteQueryOptions, CreateMutationOptions, InfiniteData } from '@tanstack/svelte-query';
2
+ import { QueryKey, SkipToken, CreateQueryOptions, QueryFunctionContext, experimental_streamedQuery, CreateInfiniteQueryOptions, CreateMutationOptions, InfiniteData } from '@tanstack/svelte-query';
3
3
  import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
4
 
5
- type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
5
+ type KeyType = 'query' | 'streamed' | 'infinite' | 'mutation' | undefined;
6
6
  interface BuildKeyOptions<TType extends KeyType, TInput> {
7
7
  type?: TType;
8
8
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
@@ -23,9 +23,9 @@ interface GeneralUtils<TInput> {
23
23
  declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
24
24
 
25
25
  type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
26
- input?: TInput;
26
+ input?: TInput | SkipToken;
27
27
  } : {
28
- input: TInput;
28
+ input: TInput | SkipToken;
29
29
  }) & (Record<never, never> extends TClientContext ? {
30
30
  context?: TClientContext;
31
31
  } : {
@@ -34,10 +34,16 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
34
34
  interface QueryOptionsBase<TOutput, TError> {
35
35
  queryKey: QueryKey;
36
36
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
37
- retry?(failureCount: number, error: TError): boolean;
37
+ throwOnError?(error: TError): boolean;
38
+ enabled: boolean;
39
+ }
40
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
41
+ type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
42
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
43
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
38
44
  }
39
45
  type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
40
- input: (pageParam: TPageParam) => TInput;
46
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
41
47
  } & (Record<never, never> extends TClientContext ? {
42
48
  context?: TClientContext;
43
49
  } : {
@@ -46,7 +52,8 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
46
52
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
47
53
  queryKey: QueryKey;
48
54
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
49
- retry?(failureCount: number, error: TError): boolean;
55
+ throwOnError?(error: TError): boolean;
56
+ enabled: boolean;
50
57
  }
51
58
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
52
59
  context?: TClientContext;
@@ -68,6 +75,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
68
75
  * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
69
76
  */
70
77
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
78
+ /**
79
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
80
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
81
+ *
82
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
83
+ */
84
+ 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>>;
71
85
  /**
72
86
  * Generate options used for createInfiniteQuery/prefetchInfiniteQuery/...
73
87
  *
@@ -101,4 +115,4 @@ interface CreateRouterUtilsOptions {
101
115
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
102
116
 
103
117
  export { buildKey, createGeneralUtils, createRouterUtils as createORPCSvelteQueryUtils, createProcedureUtils, createRouterUtils };
104
- export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils };
118
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, CreateQueryOptions, QueryFunctionContext, CreateInfiniteQueryOptions, CreateMutationOptions, InfiniteData } from '@tanstack/svelte-query';
2
+ import { QueryKey, SkipToken, CreateQueryOptions, QueryFunctionContext, experimental_streamedQuery, CreateInfiniteQueryOptions, CreateMutationOptions, InfiniteData } from '@tanstack/svelte-query';
3
3
  import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
4
 
5
- type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
5
+ type KeyType = 'query' | 'streamed' | 'infinite' | 'mutation' | undefined;
6
6
  interface BuildKeyOptions<TType extends KeyType, TInput> {
7
7
  type?: TType;
8
8
  input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
@@ -23,9 +23,9 @@ interface GeneralUtils<TInput> {
23
23
  declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
24
24
 
25
25
  type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
26
- input?: TInput;
26
+ input?: TInput | SkipToken;
27
27
  } : {
28
- input: TInput;
28
+ input: TInput | SkipToken;
29
29
  }) & (Record<never, never> extends TClientContext ? {
30
30
  context?: TClientContext;
31
31
  } : {
@@ -34,10 +34,16 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
34
34
  interface QueryOptionsBase<TOutput, TError> {
35
35
  queryKey: QueryKey;
36
36
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
37
- retry?(failureCount: number, error: TError): boolean;
37
+ throwOnError?(error: TError): boolean;
38
+ enabled: boolean;
39
+ }
40
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
41
+ type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
42
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
43
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
38
44
  }
39
45
  type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
40
- input: (pageParam: TPageParam) => TInput;
46
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
41
47
  } & (Record<never, never> extends TClientContext ? {
42
48
  context?: TClientContext;
43
49
  } : {
@@ -46,7 +52,8 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
46
52
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
47
53
  queryKey: QueryKey;
48
54
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
49
- retry?(failureCount: number, error: TError): boolean;
55
+ throwOnError?(error: TError): boolean;
56
+ enabled: boolean;
50
57
  }
51
58
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
52
59
  context?: TClientContext;
@@ -68,6 +75,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
68
75
  * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
69
76
  */
70
77
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
78
+ /**
79
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
80
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
81
+ *
82
+ * @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
83
+ */
84
+ 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>>;
71
85
  /**
72
86
  * Generate options used for createInfiniteQuery/prefetchInfiniteQuery/...
73
87
  *
@@ -101,4 +115,4 @@ interface CreateRouterUtilsOptions {
101
115
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
102
116
 
103
117
  export { buildKey, createGeneralUtils, createRouterUtils as createORPCSvelteQueryUtils, createProcedureUtils, createRouterUtils };
104
- export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils };
118
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, KeyType, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
package/dist/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ import { isAsyncIteratorObject } from '@orpc/shared';
2
+ import { skipToken, experimental_streamedQuery } from '@tanstack/svelte-query';
3
+
1
4
  function buildKey(path, options) {
2
5
  const withInput = options?.input !== void 0 ? { input: options?.input } : {};
3
6
  const withType = options?.type !== void 0 ? { type: options?.type } : {};
@@ -21,16 +24,49 @@ function createProcedureUtils(client, options) {
21
24
  queryOptions(...[optionsIn = {}]) {
22
25
  return {
23
26
  queryKey: buildKey(options.path, { type: "query", input: optionsIn.input }),
24
- queryFn: ({ signal }) => client(optionsIn.input, { signal, context: optionsIn.context }),
27
+ queryFn: ({ signal }) => {
28
+ if (optionsIn.input === skipToken) {
29
+ throw new Error("queryFn should not be called with skipToken used as input");
30
+ }
31
+ return client(optionsIn.input, { signal, context: optionsIn.context });
32
+ },
33
+ enabled: optionsIn.input !== skipToken,
34
+ ...optionsIn
35
+ };
36
+ },
37
+ experimental_streamedOptions(...[optionsIn = {}]) {
38
+ return {
39
+ enabled: optionsIn.input !== skipToken,
40
+ queryKey: buildKey(options.path, { type: "streamed", input: optionsIn.input }),
41
+ queryFn: experimental_streamedQuery({
42
+ ...optionsIn,
43
+ queryFn: async ({ signal }) => {
44
+ if (optionsIn.input === skipToken) {
45
+ throw new Error("queryFn should not be called with skipToken used as input");
46
+ }
47
+ const output = await client(optionsIn.input, { signal, context: optionsIn.context });
48
+ if (!isAsyncIteratorObject(output)) {
49
+ throw new Error("streamedQuery requires an event iterator output");
50
+ }
51
+ return output;
52
+ }
53
+ }),
25
54
  ...optionsIn
26
55
  };
27
56
  },
28
57
  infiniteOptions(optionsIn) {
29
58
  return {
30
- queryKey: buildKey(options.path, { type: "infinite", input: optionsIn.input(optionsIn.initialPageParam) }),
59
+ queryKey: buildKey(options.path, {
60
+ type: "infinite",
61
+ input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
62
+ }),
31
63
  queryFn: ({ pageParam, signal }) => {
64
+ if (optionsIn.input === skipToken) {
65
+ throw new Error("queryFn should not be called with skipToken used as input");
66
+ }
32
67
  return client(optionsIn.input(pageParam), { signal, context: optionsIn.context });
33
68
  },
69
+ enabled: optionsIn.input !== skipToken,
34
70
  ...optionsIn
35
71
  };
36
72
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/svelte-query",
3
3
  "type": "module",
4
- "version": "0.0.0-next.f72e6b9",
4
+ "version": "0.0.0-next.fa75202",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,14 +29,14 @@
29
29
  "peerDependencies": {
30
30
  "@tanstack/svelte-query": ">=5.55.0",
31
31
  "svelte": ">=4.2.0",
32
- "@orpc/client": "0.0.0-next.f72e6b9"
32
+ "@orpc/client": "0.0.0-next.fa75202"
33
33
  },
34
34
  "dependencies": {
35
- "@orpc/shared": "0.0.0-next.f72e6b9"
35
+ "@orpc/shared": "0.0.0-next.fa75202"
36
36
  },
37
37
  "devDependencies": {
38
- "@tanstack/vue-query": "^5.72.3",
39
- "zod": "^3.24.2"
38
+ "@tanstack/svelte-query": "^5.72.3",
39
+ "zod": "^3.25.11"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "unbuild",