@orpc/vue-colada 0.0.0-next.0021fba

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 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,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
+ - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
34
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), 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.
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/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/).
55
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
57
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
58
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
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/integrations/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.
@@ -0,0 +1,80 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
2
+ import { EntryKey, UseQueryOptions, UseMutationOptions, _EmptyObject } from '@pinia/colada';
3
+ import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
+ import { MaybeRefOrGetter } from 'vue';
5
+
6
+ interface BuildKeyOptions<TInput> {
7
+ type?: 'query' | 'mutation';
8
+ input?: PartialDeep<TInput>;
9
+ }
10
+ declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
11
+
12
+ interface GeneralUtils<TInput> {
13
+ /**
14
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
15
+ *
16
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
17
+ */
18
+ key(options?: BuildKeyOptions<TInput>): EntryKey;
19
+ }
20
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
21
+
22
+ type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
23
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
24
+ input?: MaybeRefOrGetter<TInput>;
25
+ } : {
26
+ input: MaybeRefOrGetter<TInput>;
27
+ }) & (Record<never, never> extends TClientContext ? {
28
+ context?: MaybeRefOrGetter<TClientContext>;
29
+ } : {
30
+ context: MaybeRefOrGetter<TClientContext>;
31
+ }) & SetOptional<QueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>;
32
+ type QueryOptions<TOutput, TError, TInitialData extends TOutput | undefined> = UseQueryOptions<TOutput, TError, TInitialData>;
33
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (Record<never, never> extends TClientContext ? {
34
+ context?: MaybeRefOrGetter<TClientContext>;
35
+ } : {
36
+ context: MaybeRefOrGetter<TClientContext>;
37
+ }) & SetOptional<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>;
38
+ type MutationOptions<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = UseMutationOptions<TOutput, TInput, TError, TMutationContext>;
39
+
40
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
41
+ /**
42
+ * Calling corresponding procedure client
43
+ *
44
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#calling-procedure-clients Pinia Colada Calling Procedure Client Docs}
45
+ */
46
+ call: Client<TClientContext, TInput, TOutput, TError>;
47
+ /**
48
+ * Generate options used for useQuery/...
49
+ *
50
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#query-options-utility Pinia Colada Query Options Utility Docs}
51
+ */
52
+ queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): NoInfer<QueryOptions<TOutput, TError, UInitialData>>;
53
+ /**
54
+ * Generate options used for useMutation/...
55
+ *
56
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#mutation-options Pinia Colada Mutation Options Docs}
57
+ */
58
+ mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
59
+ }
60
+ interface CreateProcedureUtilsOptions {
61
+ path: string[];
62
+ }
63
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
64
+
65
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
66
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
67
+ } & GeneralUtils<unknown>;
68
+ interface CreateRouterUtilsOptions {
69
+ path?: string[];
70
+ }
71
+ /**
72
+ * Create a router utils from a client.
73
+ *
74
+ * @info Both client-side and server-side clients are supported.
75
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada Pinia Colada Docs}
76
+ */
77
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
78
+
79
+ export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueColadaUtils, createProcedureUtils, createRouterUtils };
80
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptions, QueryOptionsIn, RouterUtils, UseQueryFnContext };
@@ -0,0 +1,80 @@
1
+ import { ClientContext, Client, NestedClient } from '@orpc/client';
2
+ import { EntryKey, UseQueryOptions, UseMutationOptions, _EmptyObject } from '@pinia/colada';
3
+ import { PartialDeep, SetOptional, MaybeOptionalOptions } from '@orpc/shared';
4
+ import { MaybeRefOrGetter } from 'vue';
5
+
6
+ interface BuildKeyOptions<TInput> {
7
+ type?: 'query' | 'mutation';
8
+ input?: PartialDeep<TInput>;
9
+ }
10
+ declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
11
+
12
+ interface GeneralUtils<TInput> {
13
+ /**
14
+ * Generate a query/mutation key for checking status, invalidate, set, get, etc.
15
+ *
16
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
17
+ */
18
+ key(options?: BuildKeyOptions<TInput>): EntryKey;
19
+ }
20
+ declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
21
+
22
+ type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
23
+ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
24
+ input?: MaybeRefOrGetter<TInput>;
25
+ } : {
26
+ input: MaybeRefOrGetter<TInput>;
27
+ }) & (Record<never, never> extends TClientContext ? {
28
+ context?: MaybeRefOrGetter<TClientContext>;
29
+ } : {
30
+ context: MaybeRefOrGetter<TClientContext>;
31
+ }) & SetOptional<QueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>;
32
+ type QueryOptions<TOutput, TError, TInitialData extends TOutput | undefined> = UseQueryOptions<TOutput, TError, TInitialData>;
33
+ type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (Record<never, never> extends TClientContext ? {
34
+ context?: MaybeRefOrGetter<TClientContext>;
35
+ } : {
36
+ context: MaybeRefOrGetter<TClientContext>;
37
+ }) & SetOptional<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>;
38
+ type MutationOptions<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = UseMutationOptions<TOutput, TInput, TError, TMutationContext>;
39
+
40
+ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
41
+ /**
42
+ * Calling corresponding procedure client
43
+ *
44
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#calling-procedure-clients Pinia Colada Calling Procedure Client Docs}
45
+ */
46
+ call: Client<TClientContext, TInput, TOutput, TError>;
47
+ /**
48
+ * Generate options used for useQuery/...
49
+ *
50
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#query-options-utility Pinia Colada Query Options Utility Docs}
51
+ */
52
+ queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): NoInfer<QueryOptions<TOutput, TError, UInitialData>>;
53
+ /**
54
+ * Generate options used for useMutation/...
55
+ *
56
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada#mutation-options Pinia Colada Mutation Options Docs}
57
+ */
58
+ mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
59
+ }
60
+ interface CreateProcedureUtilsOptions {
61
+ path: string[];
62
+ }
63
+ declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
64
+
65
+ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
66
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
67
+ } & GeneralUtils<unknown>;
68
+ interface CreateRouterUtilsOptions {
69
+ path?: string[];
70
+ }
71
+ /**
72
+ * Create a router utils from a client.
73
+ *
74
+ * @info Both client-side and server-side clients are supported.
75
+ * @see {@link https://orpc.unnoq.com/docs/integrations/pinia-colada Pinia Colada Docs}
76
+ */
77
+ declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
78
+
79
+ export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueColadaUtils, createProcedureUtils, createRouterUtils };
80
+ export type { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptions, QueryOptionsIn, RouterUtils, UseQueryFnContext };
package/dist/index.mjs ADDED
@@ -0,0 +1,72 @@
1
+ import { StandardRPCJsonSerializer } from '@orpc/client/standard';
2
+ import { toValue, computed } from 'vue';
3
+
4
+ function buildKey(path, options = {}) {
5
+ const [json] = new StandardRPCJsonSerializer().serialize(options.input);
6
+ const withInput = json !== void 0 ? { input: json } : {};
7
+ const withType = options.type !== void 0 ? { type: options.type } : {};
8
+ return [
9
+ path,
10
+ {
11
+ ...withInput,
12
+ ...withType
13
+ }
14
+ ];
15
+ }
16
+
17
+ function createGeneralUtils(path) {
18
+ return {
19
+ key(options) {
20
+ return buildKey(path, options);
21
+ }
22
+ };
23
+ }
24
+
25
+ function createProcedureUtils(client, options) {
26
+ return {
27
+ call: client,
28
+ queryOptions(...[{ input, context, ...rest } = {}]) {
29
+ return {
30
+ key: computed(() => buildKey(options.path, { type: "query", input: toValue(input) })),
31
+ query: ({ signal }) => client(toValue(input), { signal, context: toValue(context) }),
32
+ ...rest
33
+ };
34
+ },
35
+ mutationOptions(...[{ context, ...rest } = {}]) {
36
+ return {
37
+ key: (input) => buildKey(options.path, { type: "mutation", input }),
38
+ mutation: (input) => client(input, { context: toValue(context) }),
39
+ ...rest
40
+ };
41
+ }
42
+ };
43
+ }
44
+
45
+ function createRouterUtils(client, options = {}) {
46
+ const path = options.path ?? [];
47
+ const generalUtils = createGeneralUtils(path);
48
+ const procedureUtils = createProcedureUtils(client, { path });
49
+ const recursive = new Proxy({
50
+ ...generalUtils,
51
+ ...procedureUtils
52
+ }, {
53
+ get(target, prop) {
54
+ const value = Reflect.get(target, prop);
55
+ if (typeof prop !== "string") {
56
+ return value;
57
+ }
58
+ const nextUtils = createRouterUtils(client[prop], { ...options, path: [...path, prop] });
59
+ if (typeof value !== "function") {
60
+ return nextUtils;
61
+ }
62
+ return new Proxy(value, {
63
+ get(_, prop2) {
64
+ return Reflect.get(nextUtils, prop2);
65
+ }
66
+ });
67
+ }
68
+ });
69
+ return recursive;
70
+ }
71
+
72
+ export { buildKey, createGeneralUtils, createRouterUtils as createORPCVueColadaUtils, createProcedureUtils, createRouterUtils };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@orpc/vue-colada",
3
+ "type": "module",
4
+ "version": "0.0.0-next.0021fba",
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/vue-colada"
11
+ },
12
+ "keywords": [
13
+ "unnoq",
14
+ "orpc",
15
+ "vue",
16
+ "vue-colada",
17
+ "pinia-colada",
18
+ "tanstack"
19
+ ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.mts",
23
+ "import": "./dist/index.mjs",
24
+ "default": "./dist/index.mjs"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "peerDependencies": {
31
+ "@pinia/colada": ">=0.16.0",
32
+ "vue": ">=3.3.0"
33
+ },
34
+ "dependencies": {
35
+ "@orpc/client": "0.0.0-next.0021fba",
36
+ "@orpc/shared": "0.0.0-next.0021fba"
37
+ },
38
+ "devDependencies": {
39
+ "@pinia/colada": "^0.17.1",
40
+ "pinia": "^3.0.2",
41
+ "vue": "^3.5.18"
42
+ },
43
+ "scripts": {
44
+ "build": "unbuild",
45
+ "build:watch": "pnpm run build --watch",
46
+ "type:check": "tsc -b"
47
+ }
48
+ }