Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Dec 31, 2024
1 parent 6039b55 commit 32e2448
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 3 deletions.
71 changes: 71 additions & 0 deletions apps/content/content/docs/client/vue-colada.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Vue Colada
description: Simplify oRPC usage with minimal integration Pinia Colada
---

## Installation

```package-install
@orpc/client @orpc/vue-colada @pinia/colada
```

## Setup

```ts twoslash
import { createORPCVueColadaUtils } from '@orpc/vue-colada';
import { createORPCClient } from '@orpc/client';
import { ORPCLink } from '@orpc/client/fetch';
import type { router } from 'examples/server';

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
// fetch: optional override for the default fetch function
// headers: provide additional headers
});

// Create an ORPC client
export const client = createORPCClient<typeof router>(orpcLink);

// Create Vue Query utilities for ORPC
export const orpc = createORPCVueColadaUtils(client);

// @noErrors
orpc.getting.
// ^|
```

## Multiple ORPC Instances

To prevent conflicts when using multiple ORPC instances, you can provide a unique base path to `createORPCVueColadaUtils`.

```tsx twoslash
import { createORPCVueColadaUtils } from '@orpc/vue-colada'

// Create separate ORPC instances with unique base paths
const userORPC = createORPCVueColadaUtils('fake-client' as any, ['__user-api__'])
const postORPC = createORPCVueColadaUtils('fake-client' as any, ['__post-api__'])
```

This ensures that each instance manages its own set of query keys and avoids any conflicts.

## Usage

### Standard Queries and Mutations

```ts twoslash
import { useMutation, useQuery, useQueryCache } from '@pinia/colada'
import { orpc } from 'examples/vue-colada'

// Fetch data
const { data: gettingData } = useQuery(orpc.getting.queryOptions({ input: { name: 'unnoq' } }))

// Perform mutations
const { mutate: postMutate } = useMutation(orpc.post.create.mutationOptions())

// Invalidate queries
const queryCache = useQueryCache()
queryCache.invalidateQueries({ queryKey: orpc.key() }) // Invalidate all queries
queryCache.invalidateQueries({ queryKey: orpc.post.find.key({ input: { id: 'example' } }) }) // Specific queries
```

> **Note**: This library enhances [Pinia Colada](https://pinia-colada.esm.dev/) by managing keys and functions for you, providing a seamless developer experience.
5 changes: 5 additions & 0 deletions apps/content/examples/vue-colada.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { RouterClient } from '@orpc/server'
import type { router } from 'examples/server'
import { createORPCVueColadaUtils } from '@orpc/vue-colada'

export const orpc = createORPCVueColadaUtils({} as RouterClient<typeof router /** or contract router */, unknown>)
1 change: 1 addition & 0 deletions apps/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@orpc/react": "workspace:*",
"@orpc/react-query": "workspace:*",
"@orpc/server": "workspace:*",
"@orpc/vue-colada": "workspace:*",
"@orpc/vue-query": "workspace:*",
"@orpc/zod": "workspace:*",
"@tanstack/react-query": "^5.62.7",
Expand Down
1 change: 1 addition & 0 deletions apps/content/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{ "path": "../../packages/react" },
{ "path": "../../packages/react-query" },
{ "path": "../../packages/vue-query" },
{ "path": "../../packages/vue-colada" },
{ "path": "../../packages/zod" },
{ "path": "../../packages/next" }
],
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-colada/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export * from './utils-general'
export * from './utils-procedure'
export * from './utils-router'

export const createORPCVueQueryUtils = createRouterUtils
export const createORPCVueColadaUtils = createRouterUtils
4 changes: 2 additions & 2 deletions packages/vue-colada/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PiniaColada } from '@pinia/colada'
import { mount as baseMount } from '@vue/test-utils'
import { createPinia } from 'pinia'
import { z } from 'zod'
import { createORPCVueQueryUtils } from '../src'
import { createORPCVueColadaUtils } from '../src'

export const orpcServer = os

Expand Down Expand Up @@ -102,7 +102,7 @@ const orpcLink = new ORPCLink({

export const orpcClient = createORPCClient<typeof appRouter, { batch?: boolean } | undefined>(orpcLink)

export const orpc = createORPCVueQueryUtils(orpcClient)
export const orpc = createORPCVueColadaUtils(orpcClient)

export const mount: typeof baseMount = (component, options) => {
return baseMount(component, {
Expand Down

0 comments on commit 32e2448

Please sign in to comment.