@orpc/vue-colada 0.0.0-next.e7d7758 → 0.0.0-next.f17a1a0
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 +97 -0
- package/dist/index.js +34 -28
- package/dist/src/{utils-general.d.ts → general-utils.d.ts} +2 -6
- package/dist/src/index.d.ts +4 -4
- package/dist/src/procedure-utils.d.ts +10 -0
- package/dist/src/router-utils.d.ts +12 -0
- package/dist/src/types.d.ts +16 -16
- package/dist/src/utils.d.ts +4 -4
- package/package.json +5 -9
- package/dist/src/utils-procedure.d.ts +0 -26
- package/dist/src/utils-router.d.ts +0 -12
package/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
|
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, 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), 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/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
|
+
|
62
|
+
## `@orpc/vue-colada`
|
63
|
+
|
64
|
+
Integration with [Pinia Colada](https://pinia-colada.esm.dev/). Read the [documentation](https://orpc.unnoq.com/docs/pinia-colada) for more information.
|
65
|
+
|
66
|
+
```ts
|
67
|
+
export function Setup() {
|
68
|
+
const query = useQuery(orpc.planet.find.queryOptions({
|
69
|
+
input: { id: 123 }, // Specify input if needed
|
70
|
+
context: { cache: true }, // Provide client context if needed
|
71
|
+
// additional options...
|
72
|
+
}))
|
73
|
+
|
74
|
+
const mutation = useMutation(orpc.planet.create.mutationOptions({
|
75
|
+
context: { cache: true }, // Provide client context if needed
|
76
|
+
// additional options...
|
77
|
+
}))
|
78
|
+
|
79
|
+
mutation.mutate({ name: 'Earth' })
|
80
|
+
|
81
|
+
const queryCache = useQueryCache()
|
82
|
+
|
83
|
+
// Invalidate all planet queries
|
84
|
+
queryCache.invalidateQueries({
|
85
|
+
key: orpc.planet.key(),
|
86
|
+
})
|
87
|
+
|
88
|
+
// Invalidate the planet find query with id 123
|
89
|
+
queryCache.invalidateQueries({
|
90
|
+
key: orpc.planet.find.key({ input: { id: 123 } })
|
91
|
+
})
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
## License
|
96
|
+
|
97
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.js
CHANGED
@@ -1,63 +1,69 @@
|
|
1
1
|
// src/key.ts
|
2
|
-
import {
|
2
|
+
import { RPCJsonSerializer } from "@orpc/client/rpc";
|
3
3
|
function buildKey(path, options) {
|
4
|
+
if (options?.input === void 0) {
|
5
|
+
return path;
|
6
|
+
}
|
7
|
+
const [json, meta] = new RPCJsonSerializer().serialize(options.input);
|
4
8
|
return [
|
5
|
-
"__ORPC__",
|
6
9
|
...path,
|
7
|
-
|
10
|
+
{ input: JSON.stringify({ json, meta }) }
|
8
11
|
];
|
9
12
|
}
|
10
13
|
|
14
|
+
// src/general-utils.ts
|
15
|
+
function createGeneralUtils(path) {
|
16
|
+
return {
|
17
|
+
key(options) {
|
18
|
+
return buildKey(path, options);
|
19
|
+
}
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
// src/procedure-utils.ts
|
24
|
+
import { computed } from "vue";
|
25
|
+
|
11
26
|
// src/utils.ts
|
27
|
+
import { isObject } from "@orpc/shared";
|
12
28
|
import { isRef } from "vue";
|
13
|
-
function
|
29
|
+
function unrefDeep(value) {
|
14
30
|
if (isRef(value)) {
|
15
|
-
return
|
31
|
+
return unrefDeep(value.value);
|
16
32
|
}
|
17
33
|
if (Array.isArray(value)) {
|
18
|
-
return value.map(
|
34
|
+
return value.map(unrefDeep);
|
19
35
|
}
|
20
|
-
if (value
|
36
|
+
if (isObject(value)) {
|
21
37
|
return Object.keys(value).reduce((acc, key) => {
|
22
|
-
acc[key] =
|
38
|
+
acc[key] = unrefDeep(value[key]);
|
23
39
|
return acc;
|
24
40
|
}, {});
|
25
41
|
}
|
26
42
|
return value;
|
27
43
|
}
|
28
44
|
|
29
|
-
// src/utils
|
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";
|
45
|
+
// src/procedure-utils.ts
|
40
46
|
function createProcedureUtils(client, path) {
|
41
47
|
return {
|
42
|
-
|
43
|
-
|
48
|
+
call: client,
|
49
|
+
queryOptions(...[{ input, context, ...rest } = {}]) {
|
44
50
|
return {
|
45
|
-
key: computed(() => buildKey(path, { input:
|
46
|
-
query: ({ signal }) => client(
|
47
|
-
...
|
51
|
+
key: computed(() => buildKey(path, { input: unrefDeep(input) })),
|
52
|
+
query: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
|
53
|
+
...rest
|
48
54
|
};
|
49
55
|
},
|
50
|
-
mutationOptions(...[
|
56
|
+
mutationOptions(...[{ context, ...rest } = {}]) {
|
51
57
|
return {
|
52
58
|
key: (input) => buildKey(path, { input }),
|
53
|
-
mutation: (input
|
54
|
-
...
|
59
|
+
mutation: (input) => client(input, { context: unrefDeep(context) }),
|
60
|
+
...rest
|
55
61
|
};
|
56
62
|
}
|
57
63
|
};
|
58
64
|
}
|
59
65
|
|
60
|
-
// src/utils
|
66
|
+
// src/router-utils.ts
|
61
67
|
function createRouterUtils(client, path = []) {
|
62
68
|
const generalUtils = createGeneralUtils(path);
|
63
69
|
const procedureUtils = createProcedureUtils(client, path);
|
@@ -1,11 +1,7 @@
|
|
1
1
|
import type { EntryKey } from '@pinia/colada';
|
2
2
|
import type { BuildKeyOptions } from './key';
|
3
|
-
import type { MaybeDeepRef } from './types';
|
4
|
-
/**
|
5
|
-
* Utils at any level (procedure or router)
|
6
|
-
*/
|
7
3
|
export interface GeneralUtils<TInput> {
|
8
|
-
key
|
4
|
+
key(options?: BuildKeyOptions<TInput>): EntryKey;
|
9
5
|
}
|
10
6
|
export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
11
|
-
//# sourceMappingURL=utils
|
7
|
+
//# sourceMappingURL=general-utils.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { createRouterUtils } from './utils
|
1
|
+
import { createRouterUtils } from './router-utils';
|
2
|
+
export * from './general-utils';
|
2
3
|
export * from './key';
|
4
|
+
export * from './procedure-utils';
|
5
|
+
export * from './router-utils';
|
3
6
|
export * from './types';
|
4
|
-
export * from './utils-general';
|
5
|
-
export * from './utils-procedure';
|
6
|
-
export * from './utils-router';
|
7
7
|
export declare const createORPCVueColadaUtils: typeof createRouterUtils;
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { Client, ClientContext } from '@orpc/client';
|
2
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import type { MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn } from './types';
|
4
|
+
export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
5
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
6
|
+
queryOptions(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError>>): QueryOptions<TOutput, TError>;
|
7
|
+
mutationOptions(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError>>): MutationOptions<TInput, TOutput, TError>;
|
8
|
+
}
|
9
|
+
export declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
10
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Client, NestedClient } from '@orpc/client';
|
2
|
+
import { type GeneralUtils } from './general-utils';
|
3
|
+
import { type ProcedureUtils } from './procedure-utils';
|
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 - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
|
9
|
+
* @param path - The base path for query key, when it it will be prefix to all keys
|
10
|
+
*/
|
11
|
+
export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
|
12
|
+
//# sourceMappingURL=router-utils.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
+
import type { ClientContext } from '@orpc/client';
|
1
2
|
import type { AnyFunction, SetOptional } from '@orpc/shared';
|
2
3
|
import type { UseMutationOptions, UseQueryOptions } from '@pinia/colada';
|
3
4
|
import type { MaybeRef } from 'vue';
|
4
|
-
export type
|
5
|
-
[K in keyof T]:
|
5
|
+
export type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
|
6
|
+
[K in keyof T]: MaybeRefDeep<T[K]>;
|
6
7
|
} : T>;
|
7
8
|
export type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
8
|
-
export type
|
9
|
-
|
10
|
-
} ? T['cursor'] : never;
|
11
|
-
export type QueryOptions<TInput, TOutput, TClientContext> = (undefined extends TInput ? {
|
12
|
-
input?: MaybeDeepRef<TInput>;
|
9
|
+
export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> = (undefined extends TInput ? {
|
10
|
+
input?: MaybeRefDeep<TInput>;
|
13
11
|
} : {
|
14
|
-
input:
|
15
|
-
}) & (
|
16
|
-
context?:
|
12
|
+
input: MaybeRefDeep<TInput>;
|
13
|
+
}) & (Record<never, never> extends TClientContext ? {
|
14
|
+
context?: MaybeRefDeep<TClientContext>;
|
17
15
|
} : {
|
18
|
-
context:
|
19
|
-
}) & SetOptional<UseQueryOptions<TOutput>, 'key' | 'query'>;
|
20
|
-
export type
|
21
|
-
|
16
|
+
context: MaybeRefDeep<TClientContext>;
|
17
|
+
}) & SetOptional<UseQueryOptions<TOutput, TError>, 'key' | 'query'>;
|
18
|
+
export type QueryOptions<TOutput, TError extends Error> = UseQueryOptions<TOutput, TError>;
|
19
|
+
export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> = (Record<never, never> extends TClientContext ? {
|
20
|
+
context?: MaybeRefDeep<TClientContext>;
|
22
21
|
} : {
|
23
|
-
context:
|
24
|
-
}) & SetOptional<UseMutationOptions<TOutput, TInput>, 'mutation'>;
|
22
|
+
context: MaybeRefDeep<TClientContext>;
|
23
|
+
}) & SetOptional<UseMutationOptions<TOutput, TInput, TError>, 'mutation'>;
|
24
|
+
export type MutationOptions<TInput, TOutput, TError extends Error> = UseMutationOptions<TOutput, TInput, TError>;
|
25
25
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import type { AnyFunction } from '@orpc/shared';
|
2
1
|
import type { Ref } from 'vue';
|
3
|
-
|
4
|
-
|
2
|
+
import { type AnyFunction } from '@orpc/shared';
|
3
|
+
export type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
|
4
|
+
[K in keyof T]: UnrefDeep<T[K]>;
|
5
5
|
} : T;
|
6
|
-
export declare function
|
6
|
+
export declare function unrefDeep<T>(value: T): UnrefDeep<T>;
|
7
7
|
//# sourceMappingURL=utils.d.ts.map
|
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.f17a1a0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -33,18 +33,14 @@
|
|
33
33
|
"dist"
|
34
34
|
],
|
35
35
|
"peerDependencies": {
|
36
|
-
"@pinia/colada": ">=0.13.
|
37
|
-
"vue": ">=3.3.0"
|
38
|
-
"@orpc/client": "0.0.0-next.e7d7758",
|
39
|
-
"@orpc/contract": "0.0.0-next.e7d7758",
|
40
|
-
"@orpc/server": "0.0.0-next.e7d7758"
|
36
|
+
"@pinia/colada": ">=0.13.5",
|
37
|
+
"vue": ">=3.3.0"
|
41
38
|
},
|
42
39
|
"dependencies": {
|
43
|
-
"@orpc/
|
40
|
+
"@orpc/shared": "0.0.0-next.f17a1a0",
|
41
|
+
"@orpc/client": "0.0.0-next.f17a1a0"
|
44
42
|
},
|
45
43
|
"devDependencies": {
|
46
|
-
"@pinia/colada": "^0.13.1",
|
47
|
-
"@vue/test-utils": "^2.4.6",
|
48
44
|
"pinia": "^2.3.0"
|
49
45
|
},
|
50
46
|
"scripts": {
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import type { ProcedureClient } from '@orpc/server';
|
2
|
-
import type { IsEqual } from '@orpc/shared';
|
3
|
-
import type { EntryKey } from '@pinia/colada';
|
4
|
-
import type { ComputedRef } from 'vue';
|
5
|
-
import type { MutationOptions, QueryOptions, UseQueryFnContext } from './types';
|
6
|
-
/**
|
7
|
-
* Utils at procedure level
|
8
|
-
*/
|
9
|
-
export interface ProcedureUtils<TInput, TOutput, TClientContext> {
|
10
|
-
queryOptions: <U extends QueryOptions<TInput, TOutput, TClientContext>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TClientContext>> extends true ? {
|
11
|
-
key: ComputedRef<EntryKey>;
|
12
|
-
query: (ctx: UseQueryFnContext) => Promise<TOutput>;
|
13
|
-
} : Omit<{
|
14
|
-
key: ComputedRef<EntryKey>;
|
15
|
-
query: (ctx: UseQueryFnContext) => Promise<TOutput>;
|
16
|
-
}, keyof U> & U;
|
17
|
-
mutationOptions: <U extends MutationOptions<TInput, TOutput, TClientContext>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)) => IsEqual<U, MutationOptions<TInput, TOutput, TClientContext>> extends true ? {
|
18
|
-
key: (input: TInput) => EntryKey;
|
19
|
-
mutation: (input: TInput) => Promise<TOutput>;
|
20
|
-
} : Omit<{
|
21
|
-
key: (input: TInput) => EntryKey;
|
22
|
-
mutation: (input: TInput) => Promise<TOutput>;
|
23
|
-
}, keyof U> & U;
|
24
|
-
}
|
25
|
-
export declare function createProcedureUtils<TInput, TOutput, TClientContext>(client: ProcedureClient<TInput, TOutput, TClientContext>, path: string[]): ProcedureUtils<TInput, TOutput, TClientContext>;
|
26
|
-
//# sourceMappingURL=utils-procedure.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { ProcedureClient, RouterClient } from '@orpc/server';
|
2
|
-
import { type GeneralUtils } from './utils-general';
|
3
|
-
import { type ProcedureUtils } from './utils-procedure';
|
4
|
-
export type RouterUtils<T extends RouterClient<any, any>> = T extends ProcedureClient<infer TInput, infer TOutput, infer TClientContext> ? ProcedureUtils<TInput, TOutput, TClientContext> & GeneralUtils<TInput> : {
|
5
|
-
[K in keyof T]: T[K] extends RouterClient<any, 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 RouterClient<any, any>>(client: T, path?: string[]): RouterUtils<T>;
|
12
|
-
//# sourceMappingURL=utils-router.d.ts.map
|