@orpc/vue-colada 0.0.0-next.ca29a36 → 0.0.0-next.cac5dd3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ 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.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,11 +49,17 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
53
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
54
  - [@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
55
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
56
+ - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
57
+ - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
58
58
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
59
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
60
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
62
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
63
 
62
64
  ## `@orpc/vue-colada`
63
65
 
@@ -92,6 +94,14 @@ export function Setup() {
92
94
  }
93
95
  ```
94
96
 
97
+ ## Sponsors
98
+
99
+ <p align="center">
100
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
101
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
102
+ </a>
103
+ </p>
104
+
95
105
  ## License
96
106
 
97
107
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -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 };
@@ -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.ca29a36",
4
+ "version": "0.0.0-next.cac5dd3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,17 +19,12 @@
19
19
  ],
20
20
  "exports": {
21
21
  ".": {
22
- "types": "./dist/src/index.d.ts",
23
- "import": "./dist/index.js",
24
- "default": "./dist/index.js"
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": {
@@ -37,14 +32,14 @@
37
32
  "vue": ">=3.3.0"
38
33
  },
39
34
  "dependencies": {
40
- "@orpc/client": "0.0.0-next.ca29a36",
41
- "@orpc/shared": "0.0.0-next.ca29a36"
35
+ "@orpc/client": "0.0.0-next.cac5dd3",
36
+ "@orpc/shared": "0.0.0-next.cac5dd3"
42
37
  },
43
38
  "devDependencies": {
44
- "pinia": "^2.3.0"
39
+ "pinia": "^3.0.0"
45
40
  },
46
41
  "scripts": {
47
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
42
+ "build": "unbuild",
48
43
  "build:watch": "pnpm run build --watch",
49
44
  "type:check": "tsc -b"
50
45
  }
package/dist/index.js DELETED
@@ -1,103 +0,0 @@
1
- // src/key.ts
2
- import { RPCJsonSerializer } from "@orpc/client/rpc";
3
- import { stringifyJSON } from "@orpc/shared";
4
- function buildKey(path, options) {
5
- if (options?.input === void 0) {
6
- return path;
7
- }
8
- const [json, meta] = new RPCJsonSerializer().serialize(options.input);
9
- return [
10
- ...path,
11
- { input: stringifyJSON({ json, meta }) }
12
- ];
13
- }
14
-
15
- // src/general-utils.ts
16
- function createGeneralUtils(path) {
17
- return {
18
- key(options) {
19
- return buildKey(path, options);
20
- }
21
- };
22
- }
23
-
24
- // src/procedure-utils.ts
25
- import { computed } from "vue";
26
-
27
- // src/utils.ts
28
- import { isObject } from "@orpc/shared";
29
- import { isRef } from "vue";
30
- function unrefDeep(value) {
31
- if (isRef(value)) {
32
- return unrefDeep(value.value);
33
- }
34
- if (Array.isArray(value)) {
35
- return value.map(unrefDeep);
36
- }
37
- if (isObject(value)) {
38
- return Object.keys(value).reduce((acc, key) => {
39
- acc[key] = unrefDeep(value[key]);
40
- return acc;
41
- }, {});
42
- }
43
- return value;
44
- }
45
-
46
- // src/procedure-utils.ts
47
- function createProcedureUtils(client, path) {
48
- return {
49
- call: client,
50
- queryOptions(...[{ input, context, ...rest } = {}]) {
51
- return {
52
- key: computed(() => buildKey(path, { input: unrefDeep(input) })),
53
- query: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
54
- ...rest
55
- };
56
- },
57
- mutationOptions(...[{ context, ...rest } = {}]) {
58
- return {
59
- key: (input) => buildKey(path, { input }),
60
- mutation: (input) => client(input, { context: unrefDeep(context) }),
61
- ...rest
62
- };
63
- }
64
- };
65
- }
66
-
67
- // src/router-utils.ts
68
- function createRouterUtils(client, path = []) {
69
- const generalUtils = createGeneralUtils(path);
70
- const procedureUtils = createProcedureUtils(client, path);
71
- const recursive = new Proxy({
72
- ...generalUtils,
73
- ...procedureUtils
74
- }, {
75
- get(target, prop) {
76
- const value = Reflect.get(target, prop);
77
- if (typeof prop !== "string") {
78
- return value;
79
- }
80
- const nextUtils = createRouterUtils(client[prop], [...path, prop]);
81
- if (typeof value !== "function") {
82
- return nextUtils;
83
- }
84
- return new Proxy(value, {
85
- get(_, prop2) {
86
- return Reflect.get(nextUtils, prop2);
87
- }
88
- });
89
- }
90
- });
91
- return recursive;
92
- }
93
-
94
- // src/index.ts
95
- var createORPCVueColadaUtils = createRouterUtils;
96
- export {
97
- buildKey,
98
- createGeneralUtils,
99
- createORPCVueColadaUtils,
100
- createProcedureUtils,
101
- createRouterUtils
102
- };
103
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- import type { EntryKey } from '@pinia/colada';
2
- import type { BuildKeyOptions } from './key';
3
- export interface GeneralUtils<TInput> {
4
- key(options?: BuildKeyOptions<TInput>): EntryKey;
5
- }
6
- export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
7
- //# sourceMappingURL=general-utils.d.ts.map
@@ -1,8 +0,0 @@
1
- import { createRouterUtils } from './router-utils';
2
- export * from './general-utils';
3
- export * from './key';
4
- export * from './procedure-utils';
5
- export * from './router-utils';
6
- export * from './types';
7
- export declare const createORPCVueColadaUtils: typeof createRouterUtils;
8
- //# sourceMappingURL=index.d.ts.map
package/dist/src/key.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { EntryKey } from '@pinia/colada';
2
- export interface BuildKeyOptions<TInput> {
3
- input?: TInput;
4
- }
5
- export declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
6
- //# sourceMappingURL=key.d.ts.map
@@ -1,10 +0,0 @@
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
@@ -1,12 +0,0 @@
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
@@ -1,25 +0,0 @@
1
- import type { ClientContext } from '@orpc/client';
2
- import type { AnyFunction, SetOptional } from '@orpc/shared';
3
- import type { UseMutationOptions, UseQueryOptions } from '@pinia/colada';
4
- import type { MaybeRef } from 'vue';
5
- export type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
6
- [K in keyof T]: MaybeRefDeep<T[K]>;
7
- } : T>;
8
- export type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
9
- export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> = (undefined extends TInput ? {
10
- input?: MaybeRefDeep<TInput>;
11
- } : {
12
- input: MaybeRefDeep<TInput>;
13
- }) & (Record<never, never> extends TClientContext ? {
14
- context?: MaybeRefDeep<TClientContext>;
15
- } : {
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>;
21
- } : {
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
- //# sourceMappingURL=types.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { Ref } from 'vue';
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
- } : T;
6
- export declare function unrefDeep<T>(value: T): UnrefDeep<T>;
7
- //# sourceMappingURL=utils.d.ts.map