Skip to content

Commit 0d79ab9

Browse files
authored
feat(vue-colada): Pinia Colada integration (#65)
* wip * e2e tests * lint fixed * docs * docs * update pnpm lock * fix docs
1 parent 011bc88 commit 0d79ab9

31 files changed

Lines changed: 1430 additions & 2 deletions
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Vue Colada
3+
description: Simplify oRPC usage with minimal integration Pinia Colada
4+
---
5+
6+
## Installation
7+
8+
```package-install
9+
@orpc/client @orpc/vue-colada @pinia/colada
10+
```
11+
12+
## Setup
13+
14+
```ts twoslash
15+
import { createORPCVueColadaUtils } from '@orpc/vue-colada';
16+
import { createORPCClient } from '@orpc/client';
17+
import { ORPCLink } from '@orpc/client/fetch';
18+
import type { router } from 'examples/server';
19+
20+
const orpcLink = new ORPCLink({
21+
url: 'http://localhost:3000/api',
22+
// fetch: optional override for the default fetch function
23+
// headers: provide additional headers
24+
});
25+
26+
// Create an ORPC client
27+
export const client = createORPCClient<typeof router>(orpcLink);
28+
29+
// Create Vue Query utilities for ORPC
30+
export const orpc = createORPCVueColadaUtils(client);
31+
32+
// @noErrors
33+
orpc.getting.
34+
// ^|
35+
```
36+
37+
## Multiple ORPC Instances
38+
39+
To prevent conflicts when using multiple ORPC instances, you can provide a unique base path to `createORPCVueColadaUtils`.
40+
41+
```tsx twoslash
42+
import { createORPCVueColadaUtils } from '@orpc/vue-colada'
43+
44+
// Create separate ORPC instances with unique base paths
45+
const userORPC = createORPCVueColadaUtils('fake-client' as any, ['__user-api__'])
46+
const postORPC = createORPCVueColadaUtils('fake-client' as any, ['__post-api__'])
47+
```
48+
49+
This ensures that each instance manages its own set of query keys and avoids any conflicts.
50+
51+
## Usage
52+
53+
### Standard Queries and Mutations
54+
55+
```ts twoslash
56+
import { useMutation, useQuery, useQueryCache } from '@pinia/colada'
57+
import { orpc } from 'examples/vue-colada'
58+
59+
// Fetch data
60+
const { data: gettingData } = useQuery(orpc.getting.queryOptions({ input: { name: 'unnoq' } }))
61+
62+
// Perform mutations
63+
const { mutate: postMutate } = useMutation(orpc.post.create.mutationOptions())
64+
65+
// Invalidate queries
66+
const queryCache = useQueryCache()
67+
queryCache.invalidateQueries({ key: orpc.key() }) // Invalidate all queries
68+
queryCache.invalidateQueries({ key: orpc.post.find.key({ input: { id: 'example' } }) }) // Specific queries
69+
```
70+
71+
> **Note**: This library enhances [Pinia Colada](https://pinia-colada.esm.dev/) by managing keys and functions for you, providing a seamless developer experience.

apps/content/content/home/landing.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mutate({
8383
});
8484
```
8585

86-
We now support [React Query Integration](/docs/client/react-query) and [Vue Query Integration](/docs/client/vue-query).
86+
We now support [React Query Integration](/docs/client/react-query), [Vue Query Integration](/docs/client/vue-query), and [Pinia Colada Integration](/docs/client/vue-colada).
8787

8888
## Access via OpenAPI Standard
8989

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { RouterClient } from '@orpc/server'
2+
import type { router } from 'examples/server'
3+
import { createORPCVueColadaUtils } from '@orpc/vue-colada'
4+
5+
export const orpc = createORPCVueColadaUtils({} as RouterClient<typeof router /** or contract router */, unknown>)

apps/content/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@orpc/react": "workspace:*",
2929
"@orpc/react-query": "workspace:*",
3030
"@orpc/server": "workspace:*",
31+
"@orpc/vue-colada": "workspace:*",
3132
"@orpc/vue-query": "workspace:*",
3233
"@orpc/zod": "workspace:*",
3334
"@tanstack/react-query": "^5.62.7",

apps/content/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
{ "path": "../../packages/react" },
3333
{ "path": "../../packages/react-query" },
3434
{ "path": "../../packages/vue-query" },
35+
{ "path": "../../packages/vue-colada" },
3536
{ "path": "../../packages/zod" },
3637
{ "path": "../../packages/next" }
3738
],

packages/server/src/fetch/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './composite-handler'
22
export * from './orpc-handler'
33
export * from './orpc-payload-codec'
44
export * from './orpc-procedure-matcher'
5+
export * as SuperJSON from './super-json'
56
export * from './types'

packages/vue-colada/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Hidden folders and files
2+
.*
3+
!.gitignore
4+
!.*.example
5+
6+
# Common generated folders
7+
logs/
8+
node_modules/
9+
out/
10+
dist/
11+
dist-ssr/
12+
build/
13+
coverage/
14+
temp/
15+
16+
# Common generated files
17+
*.log
18+
*.log.*
19+
*.tsbuildinfo
20+
*.vitest-temp.json
21+
vite.config.ts.timestamp-*
22+
vitest.config.ts.timestamp-*
23+
24+
# Common manual ignore files
25+
*.local
26+
*.pem

packages/vue-colada/package.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "@orpc/vue-colada",
3+
"type": "module",
4+
"version": "0.21.0",
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+
"publishConfig": {
21+
"exports": {
22+
".": {
23+
"types": "./dist/src/index.d.ts",
24+
"import": "./dist/index.js",
25+
"default": "./dist/index.js"
26+
},
27+
"./🔒/*": {
28+
"types": "./dist/src/*.d.ts"
29+
}
30+
}
31+
},
32+
"exports": {
33+
".": "./src/index.ts",
34+
"./🔒/*": {
35+
"types": "./src/*.ts"
36+
}
37+
},
38+
"files": [
39+
"!**/*.map",
40+
"!**/*.tsbuildinfo",
41+
"dist"
42+
],
43+
"scripts": {
44+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
45+
"build:watch": "pnpm run build --watch",
46+
"type:check": "tsc -b"
47+
},
48+
"peerDependencies": {
49+
"@orpc/client": "workspace:*",
50+
"@orpc/contract": "workspace:*",
51+
"@orpc/server": "workspace:*",
52+
"@pinia/colada": ">=0.13.1",
53+
"vue": ">=3.3.0"
54+
},
55+
"dependencies": {
56+
"@orpc/server": "workspace:*"
57+
},
58+
"devDependencies": {
59+
"@pinia/colada": "^0.13.1",
60+
"@vue/test-utils": "^2.4.6",
61+
"pinia": "^2.3.0"
62+
}
63+
}

packages/vue-colada/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createRouterUtils } from './utils-router'
2+
3+
export * from './key'
4+
export * from './types'
5+
export * from './utils-general'
6+
export * from './utils-procedure'
7+
export * from './utils-router'
8+
9+
export const createORPCVueColadaUtils = createRouterUtils
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { buildKey } from './key'
2+
3+
describe('buildKey', () => {
4+
it('works', () => {
5+
expect(buildKey(['path'])).toEqual(['__ORPC__', 'path'])
6+
expect(buildKey(['path', 'path2'], { input: { a: 1 } }))
7+
.toEqual(['__ORPC__', 'path', 'path2', { input: '{"data":{"a":1},"meta":[]}' }])
8+
expect(buildKey(['path'], { input: undefined }))
9+
.toEqual(['__ORPC__', 'path'])
10+
11+
const date = new Date()
12+
expect(buildKey(['path', 'path2'], { input: { a: date } }))
13+
.toEqual(['__ORPC__', 'path', 'path2', { input: `{"data":{"a":"${date.toISOString()}"},"meta":[["date",["a"]]]}` }])
14+
})
15+
})

0 commit comments

Comments
 (0)