@orpc/solid-query 0.0.0-next.ee46dab → 0.0.0-next.ee89076

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
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
34
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
35
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
36
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
37
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
38
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
39
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
40
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
41
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,20 +49,21 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
53
+ - [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
54
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
56
55
  - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
57
- - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
58
- - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
59
- - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
60
- - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
56
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
57
+ - [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
61
58
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
62
- - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
59
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
63
60
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
64
61
  - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
65
62
  - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
66
63
 
67
64
  ## `@orpc/solid-query`
68
65
 
69
- Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview). Read the [documentation](https://orpc.unnoq.com/docs/tanstack-query/solid) for more information.
66
+ Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview). Read the [documentation](https://orpc.unnoq.com/docs/integrations/tanstack-query-old/solid) for more information.
70
67
 
71
68
  ```ts
72
69
  export function Example() {
package/dist/index.d.mts CHANGED
@@ -1,26 +1,26 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, SolidQueryOptions, QueryFunctionContext, SolidInfiniteQueryOptions, SolidMutationOptions, InfiniteData } from '@tanstack/solid-query';
3
- import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
-
5
- type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
6
- interface BuildKeyOptions<TType extends KeyType, TInput> {
7
- type?: TType;
8
- input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
9
- }
10
- declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
2
+ import { OperationType, OperationKeyOptions } from '@orpc/tanstack-query';
3
+ export { OperationKeyOptions as BuildKeyOptions, OperationType as KeyType, generateOperationKey as buildKey } from '@orpc/tanstack-query';
4
+ import { QueryKey, SkipToken, SolidQueryOptions, QueryFunctionContext, experimental_streamedQuery, SolidInfiniteQueryOptions, SolidMutationOptions, InfiniteData } from '@tanstack/solid-query';
5
+ import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
11
6
 
12
7
  /**
13
8
  * Utils at any level (procedure or router)
14
9
  */
15
10
  interface GeneralUtils<TInput> {
16
- key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
11
+ /**
12
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
13
+ *
14
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
15
+ */
16
+ key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
17
17
  }
18
18
  declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
19
19
 
20
20
  type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
21
- input?: TInput;
21
+ input?: TInput | SkipToken;
22
22
  } : {
23
- input: TInput;
23
+ input: TInput | SkipToken;
24
24
  }) & (Record<never, never> extends TClientContext ? {
25
25
  context?: TClientContext;
26
26
  } : {
@@ -29,19 +29,30 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
29
29
  interface QueryOptionsBase<TOutput, TError> {
30
30
  queryKey: QueryKey;
31
31
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
32
- retry?(failureCount: number, error: TError): boolean;
32
+ throwOnError?(error: TError): boolean;
33
+ retryDelay?: (count: number, error: TError) => number;
34
+ enabled?: boolean;
35
+ }
36
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
37
+ type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
38
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
39
+ queryFnOptions?: experimental_StreamedQueryOptions;
40
+ };
41
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
33
42
  }
34
43
  type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
35
- input: (pageParam: TPageParam) => TInput;
44
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
36
45
  } & (Record<never, never> extends TClientContext ? {
37
46
  context?: TClientContext;
38
47
  } : {
39
48
  context: TClientContext;
40
- }) & SetOptional<SolidInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
49
+ }) & SetOptional<SolidInfiniteQueryOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
41
50
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
42
51
  queryKey: QueryKey;
43
52
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
44
- retry?(failureCount: number, error: TError): boolean;
53
+ throwOnError?(error: TError): boolean;
54
+ retryDelay?: (count: number, error: TError) => number;
55
+ enabled?: boolean;
45
56
  }
46
57
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
47
58
  context?: TClientContext;
@@ -51,9 +62,36 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
51
62
  type MutationOptions<TInput, TOutput, TError, TMutationContext> = SolidMutationOptions<TOutput, TError, TInput, TMutationContext>;
52
63
 
53
64
  interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
65
+ /**
66
+ * Calling corresponding procedure client
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
69
+ */
54
70
  call: Client<TClientContext, TInput, TOutput, TError>;
71
+ /**
72
+ * Generate options used for createQuery/prefetchQuery/...
73
+ *
74
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
75
+ */
55
76
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
77
+ /**
78
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
79
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
80
+ *
81
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
82
+ */
83
+ 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>>;
84
+ /**
85
+ * Generate options used for createInfiniteQuery/prefetchInfiniteQuery/...
86
+ *
87
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
88
+ */
56
89
  infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
90
+ /**
91
+ * Generate options used for createMutation/...
92
+ *
93
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
94
+ */
57
95
  mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
58
96
  }
59
97
  interface CreateProcedureUtilsOptions {
@@ -67,6 +105,13 @@ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientCo
67
105
  interface CreateRouterUtilsOptions {
68
106
  path?: string[];
69
107
  }
108
+ /**
109
+ * Create a router utils from a client.
110
+ *
111
+ * @info Both client-side and server-side clients are supported.
112
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/solid Tanstack Query Solid Docs}
113
+ */
70
114
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
71
115
 
72
- export { type BuildKeyOptions, type CreateProcedureUtilsOptions, type CreateRouterUtilsOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MutationOptions, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, buildKey, createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
116
+ export { createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
117
+ export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
package/dist/index.d.ts CHANGED
@@ -1,26 +1,26 @@
1
1
  import { ClientContext, Client, NestedClient } from '@orpc/client';
2
- import { QueryKey, SolidQueryOptions, QueryFunctionContext, SolidInfiniteQueryOptions, SolidMutationOptions, InfiniteData } from '@tanstack/solid-query';
3
- import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
-
5
- type KeyType = 'query' | 'infinite' | 'mutation' | undefined;
6
- interface BuildKeyOptions<TType extends KeyType, TInput> {
7
- type?: TType;
8
- input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
9
- }
10
- declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
2
+ import { OperationType, OperationKeyOptions } from '@orpc/tanstack-query';
3
+ export { OperationKeyOptions as BuildKeyOptions, OperationType as KeyType, generateOperationKey as buildKey } from '@orpc/tanstack-query';
4
+ import { QueryKey, SkipToken, SolidQueryOptions, QueryFunctionContext, experimental_streamedQuery, SolidInfiniteQueryOptions, SolidMutationOptions, InfiniteData } from '@tanstack/solid-query';
5
+ import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
11
6
 
12
7
  /**
13
8
  * Utils at any level (procedure or router)
14
9
  */
15
10
  interface GeneralUtils<TInput> {
16
- key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
11
+ /**
12
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
13
+ *
14
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
15
+ */
16
+ key<UType extends OperationType>(options?: OperationKeyOptions<UType, TInput>): QueryKey;
17
17
  }
18
18
  declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
19
19
 
20
20
  type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
21
- input?: TInput;
21
+ input?: TInput | SkipToken;
22
22
  } : {
23
- input: TInput;
23
+ input: TInput | SkipToken;
24
24
  }) & (Record<never, never> extends TClientContext ? {
25
25
  context?: TClientContext;
26
26
  } : {
@@ -29,19 +29,30 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
29
29
  interface QueryOptionsBase<TOutput, TError> {
30
30
  queryKey: QueryKey;
31
31
  queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
32
- retry?(failureCount: number, error: TError): boolean;
32
+ throwOnError?(error: TError): boolean;
33
+ retryDelay?: (count: number, error: TError) => number;
34
+ enabled?: boolean;
35
+ }
36
+ type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
37
+ type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
38
+ type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
39
+ queryFnOptions?: experimental_StreamedQueryOptions;
40
+ };
41
+ interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
33
42
  }
34
43
  type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
35
- input: (pageParam: TPageParam) => TInput;
44
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
36
45
  } & (Record<never, never> extends TClientContext ? {
37
46
  context?: TClientContext;
38
47
  } : {
39
48
  context: TClientContext;
40
- }) & SetOptional<SolidInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
49
+ }) & SetOptional<SolidInfiniteQueryOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
41
50
  interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
42
51
  queryKey: QueryKey;
43
52
  queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
44
- retry?(failureCount: number, error: TError): boolean;
53
+ throwOnError?(error: TError): boolean;
54
+ retryDelay?: (count: number, error: TError) => number;
55
+ enabled?: boolean;
45
56
  }
46
57
  type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
47
58
  context?: TClientContext;
@@ -51,9 +62,36 @@ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
51
62
  type MutationOptions<TInput, TOutput, TError, TMutationContext> = SolidMutationOptions<TOutput, TError, TInput, TMutationContext>;
52
63
 
53
64
  interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
65
+ /**
66
+ * Calling corresponding procedure client
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#calling-procedure-clients Tanstack Calling Procedure Client Docs}
69
+ */
54
70
  call: Client<TClientContext, TInput, TOutput, TError>;
71
+ /**
72
+ * Generate options used for createQuery/prefetchQuery/...
73
+ *
74
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#query-options-utility Tanstack Query Options Utility Docs}
75
+ */
55
76
  queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
77
+ /**
78
+ * Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
79
+ * Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
80
+ *
81
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
82
+ */
83
+ 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>>;
84
+ /**
85
+ * Generate options used for createInfiniteQuery/prefetchInfiniteQuery/...
86
+ *
87
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#infinite-query-options-utility Tanstack Infinite Query Options Utility Docs}
88
+ */
56
89
  infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
90
+ /**
91
+ * Generate options used for createMutation/...
92
+ *
93
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/basic#mutation-options Tanstack Mutation Options Docs}
94
+ */
57
95
  mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
58
96
  }
59
97
  interface CreateProcedureUtilsOptions {
@@ -67,6 +105,13 @@ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientCo
67
105
  interface CreateRouterUtilsOptions {
68
106
  path?: string[];
69
107
  }
108
+ /**
109
+ * Create a router utils from a client.
110
+ *
111
+ * @info Both client-side and server-side clients are supported.
112
+ * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query-old/solid Tanstack Query Solid Docs}
113
+ */
70
114
  declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
71
115
 
72
- export { type BuildKeyOptions, type CreateProcedureUtilsOptions, type CreateRouterUtilsOptions, type GeneralUtils, type InfiniteOptionsBase, type InfiniteOptionsIn, type KeyType, type MutationOptions, type MutationOptionsIn, type ProcedureUtils, type QueryOptionsBase, type QueryOptionsIn, type RouterUtils, buildKey, createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
116
+ export { createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
117
+ export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
package/dist/index.mjs CHANGED
@@ -1,16 +1,12 @@
1
- function buildKey(path, options) {
2
- const withInput = options?.input !== void 0 ? { input: options?.input } : {};
3
- const withType = options?.type !== void 0 ? { type: options?.type } : {};
4
- return [path, {
5
- ...withInput,
6
- ...withType
7
- }];
8
- }
1
+ import { generateOperationKey } from '@orpc/tanstack-query';
2
+ export { generateOperationKey as buildKey } from '@orpc/tanstack-query';
3
+ import { isAsyncIteratorObject } from '@orpc/shared';
4
+ import { skipToken, experimental_streamedQuery } from '@tanstack/solid-query';
9
5
 
10
6
  function createGeneralUtils(path) {
11
7
  return {
12
8
  key(options) {
13
- return buildKey(path, options);
9
+ return generateOperationKey(path, options);
14
10
  }
15
11
  };
16
12
  }
@@ -20,23 +16,56 @@ function createProcedureUtils(client, options) {
20
16
  call: client,
21
17
  queryOptions(...[optionsIn = {}]) {
22
18
  return {
23
- queryKey: buildKey(options.path, { type: "query", input: optionsIn.input }),
24
- queryFn: ({ signal }) => client(optionsIn.input, { signal, context: optionsIn.context }),
19
+ queryKey: generateOperationKey(options.path, { type: "query", input: optionsIn.input }),
20
+ queryFn: ({ signal }) => {
21
+ if (optionsIn.input === skipToken) {
22
+ throw new Error("queryFn should not be called with skipToken used as input");
23
+ }
24
+ return client(optionsIn.input, { signal, context: optionsIn.context });
25
+ },
26
+ ...optionsIn.input === skipToken ? { enabled: false } : {},
27
+ ...optionsIn
28
+ };
29
+ },
30
+ experimental_streamedOptions(...[optionsIn = {}]) {
31
+ return {
32
+ queryKey: generateOperationKey(options.path, { type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions }),
33
+ queryFn: experimental_streamedQuery({
34
+ queryFn: async ({ signal }) => {
35
+ if (optionsIn.input === skipToken) {
36
+ throw new Error("queryFn should not be called with skipToken used as input");
37
+ }
38
+ const output = await client(optionsIn.input, { signal, context: optionsIn.context });
39
+ if (!isAsyncIteratorObject(output)) {
40
+ throw new Error("streamedQuery requires an event iterator output");
41
+ }
42
+ return output;
43
+ },
44
+ ...optionsIn.queryFnOptions
45
+ }),
46
+ ...optionsIn.input === skipToken ? { enabled: false } : {},
25
47
  ...optionsIn
26
48
  };
27
49
  },
28
50
  infiniteOptions(optionsIn) {
29
51
  return {
30
- queryKey: buildKey(options.path, { type: "infinite", input: optionsIn.input(optionsIn.initialPageParam) }),
52
+ queryKey: generateOperationKey(options.path, {
53
+ type: "infinite",
54
+ input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
55
+ }),
31
56
  queryFn: ({ pageParam, signal }) => {
57
+ if (optionsIn.input === skipToken) {
58
+ throw new Error("queryFn should not be called with skipToken used as input");
59
+ }
32
60
  return client(optionsIn.input(pageParam), { signal, context: optionsIn.context });
33
61
  },
62
+ ...optionsIn.input === skipToken ? { enabled: false } : {},
34
63
  ...optionsIn
35
64
  };
36
65
  },
37
66
  mutationOptions(...[optionsIn = {}]) {
38
67
  return {
39
- mutationKey: buildKey(options.path, { type: "mutation" }),
68
+ mutationKey: generateOperationKey(options.path, { type: "mutation" }),
40
69
  mutationFn: (input) => client(input, { context: optionsIn.context }),
41
70
  ...optionsIn
42
71
  };
@@ -71,4 +100,4 @@ function createRouterUtils(client, options = {}) {
71
100
  return recursive;
72
101
  }
73
102
 
74
- export { buildKey, createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
103
+ export { createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/solid-query",
3
3
  "type": "module",
4
- "version": "0.0.0-next.ee46dab",
4
+ "version": "0.0.0-next.ee89076",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -27,15 +27,17 @@
27
27
  "dist"
28
28
  ],
29
29
  "peerDependencies": {
30
- "@tanstack/solid-query": ">=5.59.0",
30
+ "@tanstack/solid-query": ">=5.80.2",
31
31
  "solid-js": ">=1.9.0",
32
- "@orpc/client": "0.0.0-next.ee46dab"
32
+ "@orpc/client": "0.0.0-next.ee89076"
33
33
  },
34
34
  "dependencies": {
35
- "@orpc/shared": "0.0.0-next.ee46dab"
35
+ "@orpc/shared": "0.0.0-next.ee89076",
36
+ "@orpc/tanstack-query": "0.0.0-next.ee89076"
36
37
  },
37
38
  "devDependencies": {
38
- "zod": "^3.24.2"
39
+ "@tanstack/solid-query": "^5.85.9",
40
+ "zod": "^4.1.5"
39
41
  },
40
42
  "scripts": {
41
43
  "build": "unbuild",