@orpc/solid-query 0.0.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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/index.d.mts +72 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.mjs +74 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 oRPC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/solid-query">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fsolid-query?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
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.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
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), 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.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
|
+
|
|
51
|
+
## Packages
|
|
52
|
+
|
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
59
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
60
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
61
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
62
|
+
|
|
63
|
+
## `@orpc/solid-query`
|
|
64
|
+
|
|
65
|
+
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
|
+
|
|
67
|
+
```ts
|
|
68
|
+
export function Example() {
|
|
69
|
+
const query = createQuery(() => orpc.planet.find.queryOptions({
|
|
70
|
+
input: { id: 123 }, // Specify input if needed
|
|
71
|
+
context: { cache: true }, // Provide client context if needed
|
|
72
|
+
// additional options...
|
|
73
|
+
}))
|
|
74
|
+
|
|
75
|
+
const query = createInfiniteQuery(() => orpc.planet.list.infiniteOptions({
|
|
76
|
+
input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
|
|
77
|
+
context: { cache: true }, // Provide client context if needed
|
|
78
|
+
initialPageParam: undefined,
|
|
79
|
+
getNextPageParam: lastPage => lastPage.nextPageParam,
|
|
80
|
+
// additional options...
|
|
81
|
+
}))
|
|
82
|
+
|
|
83
|
+
const mutation = createMutation(() => orpc.planet.create.mutationOptions({
|
|
84
|
+
context: { cache: true }, // Provide client context if needed
|
|
85
|
+
// additional options...
|
|
86
|
+
}))
|
|
87
|
+
|
|
88
|
+
mutation.mutate({ name: 'Earth' })
|
|
89
|
+
|
|
90
|
+
const queryClient = useQueryClient()
|
|
91
|
+
|
|
92
|
+
// Invalidate all planet queries
|
|
93
|
+
queryClient.invalidateQueries({
|
|
94
|
+
queryKey: orpc.planet.key(),
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// Invalidate only regular (non-infinite) planet queries
|
|
98
|
+
queryClient.invalidateQueries({
|
|
99
|
+
queryKey: orpc.planet.key({ type: 'query' })
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// Invalidate the planet find query with id 123
|
|
103
|
+
queryClient.invalidateQueries({
|
|
104
|
+
queryKey: orpc.planet.find.key({ input: { id: 123 } })
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Utils at any level (procedure or router)
|
|
14
|
+
*/
|
|
15
|
+
interface GeneralUtils<TInput> {
|
|
16
|
+
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
17
|
+
}
|
|
18
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
19
|
+
|
|
20
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
|
|
21
|
+
input?: TInput;
|
|
22
|
+
} : {
|
|
23
|
+
input: TInput;
|
|
24
|
+
}) & (Record<never, never> extends TClientContext ? {
|
|
25
|
+
context?: TClientContext;
|
|
26
|
+
} : {
|
|
27
|
+
context: TClientContext;
|
|
28
|
+
}) & SetOptional<SolidQueryOptions<TOutput, TError, TSelectData>, 'queryKey'>;
|
|
29
|
+
interface QueryOptionsBase<TOutput, TError extends Error> {
|
|
30
|
+
queryKey: QueryKey;
|
|
31
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
32
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
33
|
+
}
|
|
34
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
|
|
35
|
+
input: (pageParam: TPageParam) => TInput;
|
|
36
|
+
} & (Record<never, never> extends TClientContext ? {
|
|
37
|
+
context?: TClientContext;
|
|
38
|
+
} : {
|
|
39
|
+
context: TClientContext;
|
|
40
|
+
}) & SetOptional<SolidInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
|
|
41
|
+
interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
|
|
42
|
+
queryKey: QueryKey;
|
|
43
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
44
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
45
|
+
}
|
|
46
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
47
|
+
context?: TClientContext;
|
|
48
|
+
} : {
|
|
49
|
+
context: TClientContext;
|
|
50
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
|
51
|
+
type MutationOptions<TInput, TOutput, TError extends Error, TMutationContext> = SolidMutationOptions<TOutput, TError, TInput, TMutationContext>;
|
|
52
|
+
|
|
53
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
54
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
55
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
56
|
+
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>>;
|
|
57
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
|
58
|
+
}
|
|
59
|
+
interface CreateProcedureUtilsOptions {
|
|
60
|
+
path: string[];
|
|
61
|
+
}
|
|
62
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
63
|
+
|
|
64
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
65
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
66
|
+
} & GeneralUtils<unknown>;
|
|
67
|
+
interface CreateRouterUtilsOptions {
|
|
68
|
+
path?: string[];
|
|
69
|
+
}
|
|
70
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
71
|
+
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Utils at any level (procedure or router)
|
|
14
|
+
*/
|
|
15
|
+
interface GeneralUtils<TInput> {
|
|
16
|
+
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
17
|
+
}
|
|
18
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
19
|
+
|
|
20
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
|
|
21
|
+
input?: TInput;
|
|
22
|
+
} : {
|
|
23
|
+
input: TInput;
|
|
24
|
+
}) & (Record<never, never> extends TClientContext ? {
|
|
25
|
+
context?: TClientContext;
|
|
26
|
+
} : {
|
|
27
|
+
context: TClientContext;
|
|
28
|
+
}) & SetOptional<SolidQueryOptions<TOutput, TError, TSelectData>, 'queryKey'>;
|
|
29
|
+
interface QueryOptionsBase<TOutput, TError extends Error> {
|
|
30
|
+
queryKey: QueryKey;
|
|
31
|
+
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
32
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
33
|
+
}
|
|
34
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
|
|
35
|
+
input: (pageParam: TPageParam) => TInput;
|
|
36
|
+
} & (Record<never, never> extends TClientContext ? {
|
|
37
|
+
context?: TClientContext;
|
|
38
|
+
} : {
|
|
39
|
+
context: TClientContext;
|
|
40
|
+
}) & SetOptional<SolidInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
|
|
41
|
+
interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
|
|
42
|
+
queryKey: QueryKey;
|
|
43
|
+
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
44
|
+
retry?(failureCount: number, error: TError): boolean;
|
|
45
|
+
}
|
|
46
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
47
|
+
context?: TClientContext;
|
|
48
|
+
} : {
|
|
49
|
+
context: TClientContext;
|
|
50
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
|
51
|
+
type MutationOptions<TInput, TOutput, TError extends Error, TMutationContext> = SolidMutationOptions<TOutput, TError, TInput, TMutationContext>;
|
|
52
|
+
|
|
53
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
54
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
55
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
56
|
+
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>>;
|
|
57
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): MutationOptions<TInput, TOutput, TError, UMutationContext>;
|
|
58
|
+
}
|
|
59
|
+
interface CreateProcedureUtilsOptions {
|
|
60
|
+
path: string[];
|
|
61
|
+
}
|
|
62
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
63
|
+
|
|
64
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
65
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
66
|
+
} & GeneralUtils<unknown>;
|
|
67
|
+
interface CreateRouterUtilsOptions {
|
|
68
|
+
path?: string[];
|
|
69
|
+
}
|
|
70
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
71
|
+
|
|
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 };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
9
|
+
|
|
10
|
+
function createGeneralUtils(path) {
|
|
11
|
+
return {
|
|
12
|
+
key(options) {
|
|
13
|
+
return buildKey(path, options);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createProcedureUtils(client, options) {
|
|
19
|
+
return {
|
|
20
|
+
call: client,
|
|
21
|
+
queryOptions(...[optionsIn = {}]) {
|
|
22
|
+
return {
|
|
23
|
+
queryKey: buildKey(options.path, { type: "query", input: optionsIn.input }),
|
|
24
|
+
queryFn: ({ signal }) => client(optionsIn.input, { signal, context: optionsIn.context }),
|
|
25
|
+
...optionsIn
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
infiniteOptions(optionsIn) {
|
|
29
|
+
return {
|
|
30
|
+
queryKey: buildKey(options.path, { type: "infinite", input: optionsIn.input(optionsIn.initialPageParam) }),
|
|
31
|
+
queryFn: ({ pageParam, signal }) => {
|
|
32
|
+
return client(optionsIn.input(pageParam), { signal, context: optionsIn.context });
|
|
33
|
+
},
|
|
34
|
+
...optionsIn
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
mutationOptions(...[optionsIn = {}]) {
|
|
38
|
+
return {
|
|
39
|
+
mutationKey: buildKey(options.path, { type: "mutation" }),
|
|
40
|
+
mutationFn: (input) => client(input, { context: optionsIn.context }),
|
|
41
|
+
...optionsIn
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createRouterUtils(client, options = {}) {
|
|
48
|
+
const path = options.path ?? [];
|
|
49
|
+
const generalUtils = createGeneralUtils(path);
|
|
50
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
|
51
|
+
const recursive = new Proxy({
|
|
52
|
+
...generalUtils,
|
|
53
|
+
...procedureUtils
|
|
54
|
+
}, {
|
|
55
|
+
get(target, prop) {
|
|
56
|
+
const value = Reflect.get(target, prop);
|
|
57
|
+
if (typeof prop !== "string") {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
|
|
61
|
+
if (typeof value !== "function") {
|
|
62
|
+
return nextUtils;
|
|
63
|
+
}
|
|
64
|
+
return new Proxy(value, {
|
|
65
|
+
get(_, prop2) {
|
|
66
|
+
return Reflect.get(nextUtils, prop2);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return recursive;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { buildKey, createGeneralUtils, createRouterUtils as createORPCSolidQueryUtils, createProcedureUtils, createRouterUtils };
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orpc/solid-query",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://orpc.unnoq.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/unnoq/orpc.git",
|
|
10
|
+
"directory": "packages/solid-query"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"unnoq",
|
|
14
|
+
"orpc",
|
|
15
|
+
"solid-query",
|
|
16
|
+
"tanstack query",
|
|
17
|
+
"solid"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@tanstack/solid-query": ">=5.59.0",
|
|
31
|
+
"solid-js": ">=1.9.0",
|
|
32
|
+
"@orpc/client": "0.47.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@orpc/shared": "0.47.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"zod": "^3.24.2"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "unbuild",
|
|
42
|
+
"build:watch": "pnpm run build --watch",
|
|
43
|
+
"type:check": "tsc -b"
|
|
44
|
+
}
|
|
45
|
+
}
|