@orpc/vue-colada 0.0.0-next.c4a591c → 0.0.0-next.c58d6c4

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 ADDED
@@ -0,0 +1,105 @@
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/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
53
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
54
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
55
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
56
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
57
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
58
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
59
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
60
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
+
62
+ ## `@orpc/vue-colada`
63
+
64
+ Integration with [Pinia Colada](https://pinia-colada.esm.dev/). Read the [documentation](https://orpc.unnoq.com/docs/integrations/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
+ ## Sponsors
96
+
97
+ <p align="center">
98
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
99
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
100
+ </a>
101
+ </p>
102
+
103
+ ## License
104
+
105
+ 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-colada",
3
3
  "type": "module",
4
- "version": "0.0.0-next.c4a591c",
4
+ "version": "0.0.0-next.c58d6c4",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,35 +19,29 @@
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": {
36
- "@pinia/colada": ">=0.13.1",
37
- "vue": ">=3.3.0",
38
- "@orpc/client": "0.0.0-next.c4a591c",
39
- "@orpc/contract": "0.0.0-next.c4a591c"
31
+ "@pinia/colada": ">=0.16.0",
32
+ "vue": ">=3.3.0"
40
33
  },
41
34
  "dependencies": {
42
- "@orpc/server": "0.0.0-next.c4a591c"
35
+ "@orpc/client": "0.0.0-next.c58d6c4",
36
+ "@orpc/shared": "0.0.0-next.c58d6c4"
43
37
  },
44
38
  "devDependencies": {
45
- "@pinia/colada": "^0.13.1",
46
- "@vue/test-utils": "^2.4.6",
47
- "pinia": "^2.3.0"
39
+ "@pinia/colada": "^0.17.0",
40
+ "pinia": "^3.0.2",
41
+ "vue": "^3.5.16"
48
42
  },
49
43
  "scripts": {
50
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
44
+ "build": "unbuild",
51
45
  "build:watch": "pnpm run build --watch",
52
46
  "type:check": "tsc -b"
53
47
  }
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
@@ -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
@@ -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,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
@@ -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