@orpc/vue-colada 0.0.0-next.ed15210 → 0.0.0-next.eea495c
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 +106 -0
- package/dist/index.d.mts +79 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.mjs +71 -0
- package/package.json +10 -18
- package/dist/index.js +0 -96
- package/dist/src/index.d.ts +0 -8
- package/dist/src/key.d.ts +0 -6
- package/dist/src/types.d.ts +0 -27
- package/dist/src/utils-general.d.ts +0 -11
- package/dist/src/utils-procedure.d.ts +0 -11
- package/dist/src/utils-router.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -7
package/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
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/vue-colada">
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fvue-colada?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
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Highlights
|
29
|
+
|
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
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
42
|
+
|
43
|
+
## Documentation
|
44
|
+
|
45
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
46
|
+
|
47
|
+
## Packages
|
48
|
+
|
49
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
50
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
53
|
+
- [@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
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
55
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
56
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
57
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
58
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
59
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
60
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
61
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
62
|
+
|
63
|
+
## `@orpc/vue-colada`
|
64
|
+
|
65
|
+
Integration with [Pinia Colada](https://pinia-colada.esm.dev/). Read the [documentation](https://orpc.unnoq.com/docs/pinia-colada) for more information.
|
66
|
+
|
67
|
+
```ts
|
68
|
+
export function Setup() {
|
69
|
+
const query = useQuery(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 mutation = useMutation(orpc.planet.create.mutationOptions({
|
76
|
+
context: { cache: true }, // Provide client context if needed
|
77
|
+
// additional options...
|
78
|
+
}))
|
79
|
+
|
80
|
+
mutation.mutate({ name: 'Earth' })
|
81
|
+
|
82
|
+
const queryCache = useQueryCache()
|
83
|
+
|
84
|
+
// Invalidate all planet queries
|
85
|
+
queryCache.invalidateQueries({
|
86
|
+
key: orpc.planet.key(),
|
87
|
+
})
|
88
|
+
|
89
|
+
// Invalidate the planet find query with id 123
|
90
|
+
queryCache.invalidateQueries({
|
91
|
+
key: orpc.planet.find.key({ input: { id: 123 } })
|
92
|
+
})
|
93
|
+
}
|
94
|
+
```
|
95
|
+
|
96
|
+
## Sponsors
|
97
|
+
|
98
|
+
<p align="center">
|
99
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
100
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
101
|
+
</a>
|
102
|
+
</p>
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
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,79 @@
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
+
import { EntryKey, UseQueryOptions, UseMutationOptions, _EmptyObject } from '@pinia/colada';
|
3
|
+
import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { MaybeRefOrGetter } from 'vue';
|
5
|
+
|
6
|
+
interface BuildKeyOptions<TInput> {
|
7
|
+
input?: TInput;
|
8
|
+
}
|
9
|
+
declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
|
10
|
+
|
11
|
+
interface GeneralUtils<TInput> {
|
12
|
+
/**
|
13
|
+
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
14
|
+
*
|
15
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
16
|
+
*/
|
17
|
+
key(options?: BuildKeyOptions<TInput>): EntryKey;
|
18
|
+
}
|
19
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
20
|
+
|
21
|
+
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
22
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
|
23
|
+
input?: MaybeRefOrGetter<TInput>;
|
24
|
+
} : {
|
25
|
+
input: MaybeRefOrGetter<TInput>;
|
26
|
+
}) & (Record<never, never> extends TClientContext ? {
|
27
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
28
|
+
} : {
|
29
|
+
context: MaybeRefOrGetter<TClientContext>;
|
30
|
+
}) & SetOptional<QueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>;
|
31
|
+
type QueryOptions<TOutput, TError, TInitialData extends TOutput | undefined> = UseQueryOptions<TOutput, TError, TInitialData>;
|
32
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (Record<never, never> extends TClientContext ? {
|
33
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
34
|
+
} : {
|
35
|
+
context: MaybeRefOrGetter<TClientContext>;
|
36
|
+
}) & SetOptional<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>;
|
37
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = UseMutationOptions<TOutput, TInput, TError, TMutationContext>;
|
38
|
+
|
39
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
40
|
+
/**
|
41
|
+
* Calling corresponding procedure client
|
42
|
+
*
|
43
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#calling-procedure-clients Pinia Colada Calling Procedure Client Docs}
|
44
|
+
*/
|
45
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
46
|
+
/**
|
47
|
+
* Generate options used for useQuery/...
|
48
|
+
*
|
49
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#query-options-utility Pinia Colada Query Options Utility Docs}
|
50
|
+
*/
|
51
|
+
queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): QueryOptions<TOutput, TError, UInitialData>;
|
52
|
+
/**
|
53
|
+
* Generate options used for useMutation/...
|
54
|
+
*
|
55
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#mutation-options Pinia Colada Mutation Options Docs}
|
56
|
+
*/
|
57
|
+
mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...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>(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
|
+
/**
|
71
|
+
* Create a router utils from a client.
|
72
|
+
*
|
73
|
+
* @info Both client-side and server-side clients are supported.
|
74
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada Pinia Colada Docs}
|
75
|
+
*/
|
76
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
77
|
+
|
78
|
+
export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueColadaUtils, createProcedureUtils, createRouterUtils };
|
79
|
+
export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptions, QueryOptionsIn, RouterUtils, UseQueryFnContext };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
2
|
+
import { EntryKey, UseQueryOptions, UseMutationOptions, _EmptyObject } from '@pinia/colada';
|
3
|
+
import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { MaybeRefOrGetter } from 'vue';
|
5
|
+
|
6
|
+
interface BuildKeyOptions<TInput> {
|
7
|
+
input?: TInput;
|
8
|
+
}
|
9
|
+
declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
|
10
|
+
|
11
|
+
interface GeneralUtils<TInput> {
|
12
|
+
/**
|
13
|
+
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
14
|
+
*
|
15
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
16
|
+
*/
|
17
|
+
key(options?: BuildKeyOptions<TInput>): EntryKey;
|
18
|
+
}
|
19
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
20
|
+
|
21
|
+
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
22
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
|
23
|
+
input?: MaybeRefOrGetter<TInput>;
|
24
|
+
} : {
|
25
|
+
input: MaybeRefOrGetter<TInput>;
|
26
|
+
}) & (Record<never, never> extends TClientContext ? {
|
27
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
28
|
+
} : {
|
29
|
+
context: MaybeRefOrGetter<TClientContext>;
|
30
|
+
}) & SetOptional<QueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>;
|
31
|
+
type QueryOptions<TOutput, TError, TInitialData extends TOutput | undefined> = UseQueryOptions<TOutput, TError, TInitialData>;
|
32
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (Record<never, never> extends TClientContext ? {
|
33
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
34
|
+
} : {
|
35
|
+
context: MaybeRefOrGetter<TClientContext>;
|
36
|
+
}) & SetOptional<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>;
|
37
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = UseMutationOptions<TOutput, TInput, TError, TMutationContext>;
|
38
|
+
|
39
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
40
|
+
/**
|
41
|
+
* Calling corresponding procedure client
|
42
|
+
*
|
43
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#calling-procedure-clients Pinia Colada Calling Procedure Client Docs}
|
44
|
+
*/
|
45
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
46
|
+
/**
|
47
|
+
* Generate options used for useQuery/...
|
48
|
+
*
|
49
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#query-options-utility Pinia Colada Query Options Utility Docs}
|
50
|
+
*/
|
51
|
+
queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): QueryOptions<TOutput, TError, UInitialData>;
|
52
|
+
/**
|
53
|
+
* Generate options used for useMutation/...
|
54
|
+
*
|
55
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada#mutation-options Pinia Colada Mutation Options Docs}
|
56
|
+
*/
|
57
|
+
mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...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>(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
|
+
/**
|
71
|
+
* Create a router utils from a client.
|
72
|
+
*
|
73
|
+
* @info Both client-side and server-side clients are supported.
|
74
|
+
* @see {@link https://orpc.unnoq.com/docs/pinia-colada Pinia Colada Docs}
|
75
|
+
*/
|
76
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
77
|
+
|
78
|
+
export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueColadaUtils, createProcedureUtils, createRouterUtils };
|
79
|
+
export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptions, QueryOptionsIn, RouterUtils, UseQueryFnContext };
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
import { StandardRPCJsonSerializer } from '@orpc/client/standard';
|
2
|
+
import { stringifyJSON } from '@orpc/shared';
|
3
|
+
import { toValue, computed } from 'vue';
|
4
|
+
|
5
|
+
function buildKey(path, options) {
|
6
|
+
if (options?.input === void 0) {
|
7
|
+
return path;
|
8
|
+
}
|
9
|
+
const [json, meta] = new StandardRPCJsonSerializer().serialize(options.input);
|
10
|
+
return [
|
11
|
+
...path,
|
12
|
+
{ input: stringifyJSON({ json, meta }) }
|
13
|
+
];
|
14
|
+
}
|
15
|
+
|
16
|
+
function createGeneralUtils(path) {
|
17
|
+
return {
|
18
|
+
key(options) {
|
19
|
+
return buildKey(path, options);
|
20
|
+
}
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
function createProcedureUtils(client, options) {
|
25
|
+
return {
|
26
|
+
call: client,
|
27
|
+
queryOptions(...[{ input, context, ...rest } = {}]) {
|
28
|
+
return {
|
29
|
+
key: computed(() => buildKey(options.path, { input: toValue(input) })),
|
30
|
+
query: ({ signal }) => client(toValue(input), { signal, context: toValue(context) }),
|
31
|
+
...rest
|
32
|
+
};
|
33
|
+
},
|
34
|
+
mutationOptions(...[{ context, ...rest } = {}]) {
|
35
|
+
return {
|
36
|
+
key: (input) => buildKey(options.path, { input }),
|
37
|
+
mutation: (input) => client(input, { context: toValue(context) }),
|
38
|
+
...rest
|
39
|
+
};
|
40
|
+
}
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
function createRouterUtils(client, options = {}) {
|
45
|
+
const path = options.path ?? [];
|
46
|
+
const generalUtils = createGeneralUtils(path);
|
47
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
48
|
+
const recursive = new Proxy({
|
49
|
+
...generalUtils,
|
50
|
+
...procedureUtils
|
51
|
+
}, {
|
52
|
+
get(target, prop) {
|
53
|
+
const value = Reflect.get(target, prop);
|
54
|
+
if (typeof prop !== "string") {
|
55
|
+
return value;
|
56
|
+
}
|
57
|
+
const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
|
58
|
+
if (typeof value !== "function") {
|
59
|
+
return nextUtils;
|
60
|
+
}
|
61
|
+
return new Proxy(value, {
|
62
|
+
get(_, prop2) {
|
63
|
+
return Reflect.get(nextUtils, prop2);
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
67
|
+
});
|
68
|
+
return recursive;
|
69
|
+
}
|
70
|
+
|
71
|
+
export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueColadaUtils, createProcedureUtils, createRouterUtils };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/vue-colada",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.eea495c",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -19,35 +19,27 @@
|
|
19
19
|
],
|
20
20
|
"exports": {
|
21
21
|
".": {
|
22
|
-
"types": "./dist/
|
23
|
-
"import": "./dist/index.
|
24
|
-
"default": "./dist/index.
|
25
|
-
},
|
26
|
-
"./🔒/*": {
|
27
|
-
"types": "./dist/src/*.d.ts"
|
22
|
+
"types": "./dist/index.d.mts",
|
23
|
+
"import": "./dist/index.mjs",
|
24
|
+
"default": "./dist/index.mjs"
|
28
25
|
}
|
29
26
|
},
|
30
27
|
"files": [
|
31
|
-
"!**/*.map",
|
32
|
-
"!**/*.tsbuildinfo",
|
33
28
|
"dist"
|
34
29
|
],
|
35
30
|
"peerDependencies": {
|
36
|
-
"@pinia/colada": ">=0.13.
|
37
|
-
"vue": ">=3.3.0"
|
38
|
-
"@orpc/client": "0.0.0-next.ed15210",
|
39
|
-
"@orpc/contract": "0.0.0-next.ed15210"
|
31
|
+
"@pinia/colada": ">=0.13.5",
|
32
|
+
"vue": ">=3.3.0"
|
40
33
|
},
|
41
34
|
"dependencies": {
|
42
|
-
"@orpc/
|
35
|
+
"@orpc/shared": "0.0.0-next.eea495c",
|
36
|
+
"@orpc/client": "0.0.0-next.eea495c"
|
43
37
|
},
|
44
38
|
"devDependencies": {
|
45
|
-
"
|
46
|
-
"@vue/test-utils": "^2.4.6",
|
47
|
-
"pinia": "^2.3.0"
|
39
|
+
"pinia": "^3.0.0"
|
48
40
|
},
|
49
41
|
"scripts": {
|
50
|
-
"build": "
|
42
|
+
"build": "unbuild",
|
51
43
|
"build:watch": "pnpm run build --watch",
|
52
44
|
"type:check": "tsc -b"
|
53
45
|
}
|
package/dist/index.js
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
// src/key.ts
|
2
|
-
import { SuperJSON } from "@orpc/server/fetch";
|
3
|
-
function buildKey(path, options) {
|
4
|
-
return [
|
5
|
-
"__ORPC__",
|
6
|
-
...path,
|
7
|
-
...options?.input !== void 0 ? [{ input: JSON.stringify(SuperJSON.serialize(options.input)) }] : []
|
8
|
-
];
|
9
|
-
}
|
10
|
-
|
11
|
-
// src/utils.ts
|
12
|
-
import { isRef } from "vue";
|
13
|
-
function deepUnref(value) {
|
14
|
-
if (isRef(value)) {
|
15
|
-
return deepUnref(value.value);
|
16
|
-
}
|
17
|
-
if (Array.isArray(value)) {
|
18
|
-
return value.map(deepUnref);
|
19
|
-
}
|
20
|
-
if (value && typeof value === "object") {
|
21
|
-
return Object.keys(value).reduce((acc, key) => {
|
22
|
-
acc[key] = deepUnref(value[key]);
|
23
|
-
return acc;
|
24
|
-
}, {});
|
25
|
-
}
|
26
|
-
return value;
|
27
|
-
}
|
28
|
-
|
29
|
-
// src/utils-general.ts
|
30
|
-
function createGeneralUtils(path) {
|
31
|
-
return {
|
32
|
-
key(options) {
|
33
|
-
return buildKey(path, deepUnref(options));
|
34
|
-
}
|
35
|
-
};
|
36
|
-
}
|
37
|
-
|
38
|
-
// src/utils-procedure.ts
|
39
|
-
import { computed } from "vue";
|
40
|
-
function createProcedureUtils(client, path) {
|
41
|
-
return {
|
42
|
-
queryOptions(...[options]) {
|
43
|
-
const input = options?.input;
|
44
|
-
return {
|
45
|
-
key: computed(() => buildKey(path, { input: deepUnref(input) })),
|
46
|
-
query: ({ signal }) => client(deepUnref(input), { signal, context: deepUnref(options?.context) }),
|
47
|
-
...options
|
48
|
-
};
|
49
|
-
},
|
50
|
-
mutationOptions(...[options]) {
|
51
|
-
return {
|
52
|
-
key: (input) => buildKey(path, { input }),
|
53
|
-
mutation: (input, _) => client(input, { context: deepUnref(options?.context) }),
|
54
|
-
...options
|
55
|
-
};
|
56
|
-
}
|
57
|
-
};
|
58
|
-
}
|
59
|
-
|
60
|
-
// src/utils-router.ts
|
61
|
-
function createRouterUtils(client, path = []) {
|
62
|
-
const generalUtils = createGeneralUtils(path);
|
63
|
-
const procedureUtils = createProcedureUtils(client, path);
|
64
|
-
const recursive = new Proxy({
|
65
|
-
...generalUtils,
|
66
|
-
...procedureUtils
|
67
|
-
}, {
|
68
|
-
get(target, prop) {
|
69
|
-
const value = Reflect.get(target, prop);
|
70
|
-
if (typeof prop !== "string") {
|
71
|
-
return value;
|
72
|
-
}
|
73
|
-
const nextUtils = createRouterUtils(client[prop], [...path, prop]);
|
74
|
-
if (typeof value !== "function") {
|
75
|
-
return nextUtils;
|
76
|
-
}
|
77
|
-
return new Proxy(value, {
|
78
|
-
get(_, prop2) {
|
79
|
-
return Reflect.get(nextUtils, prop2);
|
80
|
-
}
|
81
|
-
});
|
82
|
-
}
|
83
|
-
});
|
84
|
-
return recursive;
|
85
|
-
}
|
86
|
-
|
87
|
-
// src/index.ts
|
88
|
-
var createORPCVueColadaUtils = createRouterUtils;
|
89
|
-
export {
|
90
|
-
buildKey,
|
91
|
-
createGeneralUtils,
|
92
|
-
createORPCVueColadaUtils,
|
93
|
-
createProcedureUtils,
|
94
|
-
createRouterUtils
|
95
|
-
};
|
96
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import { createRouterUtils } from './utils-router';
|
2
|
-
export * from './key';
|
3
|
-
export * from './types';
|
4
|
-
export * from './utils-general';
|
5
|
-
export * from './utils-procedure';
|
6
|
-
export * from './utils-router';
|
7
|
-
export declare const createORPCVueColadaUtils: typeof createRouterUtils;
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/key.d.ts
DELETED
package/dist/src/types.d.ts
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
import type { AnyFunction, SetOptional } from '@orpc/shared';
|
2
|
-
import type { UseMutationOptions, UseQueryOptions } from '@pinia/colada';
|
3
|
-
import type { MaybeRef } from 'vue';
|
4
|
-
export type MaybeDeepRef<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
5
|
-
[K in keyof T]: MaybeDeepRef<T[K]>;
|
6
|
-
} : T>;
|
7
|
-
export type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
8
|
-
export type InferCursor<T> = T extends {
|
9
|
-
cursor?: any;
|
10
|
-
} ? T['cursor'] : never;
|
11
|
-
export type QueryOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TInput ? {
|
12
|
-
input?: MaybeDeepRef<TInput>;
|
13
|
-
} : {
|
14
|
-
input: MaybeDeepRef<TInput>;
|
15
|
-
}) & (undefined extends TClientContext ? {
|
16
|
-
context?: MaybeDeepRef<TClientContext>;
|
17
|
-
} : {
|
18
|
-
context: MaybeDeepRef<TClientContext>;
|
19
|
-
}) & SetOptional<UseQueryOptions<TOutput, TError>, 'key' | 'query'>;
|
20
|
-
export type QueryOptions<TOutput, TError extends Error> = UseQueryOptions<TOutput, TError>;
|
21
|
-
export type MutationOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
|
22
|
-
context?: MaybeDeepRef<TClientContext>;
|
23
|
-
} : {
|
24
|
-
context: MaybeDeepRef<TClientContext>;
|
25
|
-
}) & SetOptional<UseMutationOptions<TOutput, TInput, TError>, 'mutation'>;
|
26
|
-
export type MutationOptions<TInput, TOutput, TError extends Error> = UseMutationOptions<TOutput, TInput, TError>;
|
27
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { EntryKey } from '@pinia/colada';
|
2
|
-
import type { BuildKeyOptions } from './key';
|
3
|
-
import type { MaybeDeepRef } from './types';
|
4
|
-
/**
|
5
|
-
* Utils at any level (procedure or router)
|
6
|
-
*/
|
7
|
-
export interface GeneralUtils<TInput> {
|
8
|
-
key: (options?: MaybeDeepRef<BuildKeyOptions<TInput>>) => EntryKey;
|
9
|
-
}
|
10
|
-
export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
11
|
-
//# sourceMappingURL=utils-general.d.ts.map
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { Client } from '@orpc/contract';
|
2
|
-
import type { MutationOptions, MutationOptionsExtra, QueryOptions, QueryOptionsExtra } from './types';
|
3
|
-
/**
|
4
|
-
* Utils at procedure level
|
5
|
-
*/
|
6
|
-
export interface ProcedureUtils<TClientContext, TInput, TOutput, TError extends Error> {
|
7
|
-
queryOptions: <U extends QueryOptionsExtra<TClientContext, TInput, TOutput, TError>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => QueryOptions<TOutput, TError>;
|
8
|
-
mutationOptions: <U extends MutationOptionsExtra<TClientContext, TInput, TOutput, TError>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)) => MutationOptions<TInput, TOutput, TError>;
|
9
|
-
}
|
10
|
-
export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
11
|
-
//# sourceMappingURL=utils-procedure.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { Client, NestedClient } from '@orpc/contract';
|
2
|
-
import { type GeneralUtils } from './utils-general';
|
3
|
-
import { type ProcedureUtils } from './utils-procedure';
|
4
|
-
export type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
5
|
-
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
6
|
-
} & GeneralUtils<unknown>;
|
7
|
-
/**
|
8
|
-
* @param client - The client create form `@orpc/client`
|
9
|
-
* @param path - The base path for query key
|
10
|
-
*/
|
11
|
-
export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
|
12
|
-
//# sourceMappingURL=utils-router.d.ts.map
|
package/dist/src/utils.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import type { AnyFunction } from '@orpc/shared';
|
2
|
-
import type { Ref } from 'vue';
|
3
|
-
export type DeepUnref<T> = T extends Ref<infer U> ? DeepUnref<U> : T extends AnyFunction ? T : T extends object ? {
|
4
|
-
[K in keyof T]: DeepUnref<T[K]>;
|
5
|
-
} : T;
|
6
|
-
export declare function deepUnref<T>(value: T): DeepUnref<T>;
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|