Skip to content

Commit 85c7049

Browse files
committed
docs: bun playground
1 parent ae7f562 commit 85c7049

38 files changed

Lines changed: 3365 additions & 94 deletions

apps/content/docs/playgrounds.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ featuring pre-configured examples accessible instantly via StackBlitz or local s
77

88
| Environment | StackBlitz | GitHub Source |
99
| ------------------ | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
10-
| Next.js Playground | [Open in StackBlitz](https://stackblitz.com/github/middleapi/orpc/tree/main/playgrounds/next) | [View Source](https://github.com/middleapi/orpc/tree/main/playgrounds/next) |
10+
| Bun Playground | [Open in StackBlitz](https://stackblitz.com/github/middleapi/orpc/tree/main/playgrounds/bun) | [View Source](https://github.com/middleapi/orpc/tree/main/playgrounds/bun) |
1111
| NestJS Playground | [Open in StackBlitz](https://stackblitz.com/github/middleapi/orpc/tree/main/playgrounds/nest) | [View Source](https://github.com/middleapi/orpc/tree/main/playgrounds/nest) |
12+
| Next.js Playground | [Open in StackBlitz](https://stackblitz.com/github/middleapi/orpc/tree/main/playgrounds/next) | [View Source](https://github.com/middleapi/orpc/tree/main/playgrounds/next) |
1213

1314
:::warning
1415
StackBlitz has its own limitations, so some features may not work as expected.
@@ -19,8 +20,9 @@ StackBlitz has its own limitations, so some features may not work as expected.
1920
Prefer working locally? Clone the playground with:
2021

2122
```bash
22-
npx giget gh:middleapi/orpc/playgrounds/next orpc-next-playground
23+
npx giget gh:middleapi/orpc/playgrounds/bun orpc-bun-playground
2324
npx giget gh:middleapi/orpc/playgrounds/nest orpc-nest-playground
25+
npx giget gh:middleapi/orpc/playgrounds/next orpc-next-playground
2426
```
2527

2628
Then install dependencies and start the dev server:
@@ -41,7 +43,7 @@ npm run dev
4143
Collect OpenTelemetry traces with [Jaeger](https://www.jaegertracing.io/) by running this in a separate terminal:
4244

4345
```bash
44-
npm run jaeger:run
46+
npm run jaeger
4547
```
4648

4749
Then play with your app and open `http://localhost:16686` to see the traces in the Jaeger dashboard.

apps/content/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@orpc/valibot": "workspace:*",
2626
"@orpc/zod": "workspace:*",
2727
"@shikijs/vitepress-twoslash": "^4.2.0",
28-
"@tanstack/react-query": "^5.101.1",
28+
"@tanstack/react-query": "^5.101.2",
2929
"@tanstack/solid-query": "^5.101.0",
3030
"@tanstack/svelte-query": "^6.1.34",
3131
"@tanstack/vue-query": "^5.101.0",

packages/evlog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@
5151
"@standardserver/core": "^0.0.25"
5252
},
5353
"devDependencies": {
54-
"evlog": "^2.18.1"
54+
"evlog": "^2.19.2"
5555
}
5656
}

packages/tanstack-query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@angular/core": "^22.0.1",
4949
"@tanstack/angular-query-experimental": "^5.101.0",
5050
"@tanstack/query-core": "^5.101.0",
51-
"@tanstack/react-query": "^5.101.1",
51+
"@tanstack/react-query": "^5.101.2",
5252
"@tanstack/solid-query": "^5.101.0",
5353
"@tanstack/svelte-query": "^6.1.34",
5454
"@tanstack/vue-query": "^5.101.0",

playgrounds/bun/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

playgrounds/bun/README.md

Lines changed: 146 additions & 0 deletions
Large diffs are not rendered by default.

playgrounds/bun/bun-env.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Generated by `bun init`
2+
3+
declare module '*.svg' {
4+
/**
5+
* A path to the SVG file
6+
*/
7+
const path: `${string}.svg`
8+
export = path
9+
}
10+
11+
declare module '*.css' {}
12+
13+
declare module '*.module.css' {
14+
/**
15+
* A record of class names to their corresponding CSS module classes
16+
*/
17+
const classes: { readonly [key: string]: string }
18+
export = classes
19+
}

playgrounds/bun/bunfig.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[serve.static]
2+
env = "BUN_PUBLIC_*"

playgrounds/bun/package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@orpc/bun-playground",
3+
"type": "module",
4+
"version": "0.1.0",
5+
"private": true,
6+
"scripts": {
7+
"dev": "bun --hot src/index.ts",
8+
"build": "bun build ./src/index.html --outdir=dist --sourcemap --target=browser --minify --define:process.env.NODE_ENV='\"production\"' --env='BUN_PUBLIC_*'",
9+
"start": "NODE_ENV=production bun src/index.ts",
10+
"type:check": "tsc --noEmit",
11+
"jaeger": "docker run -p 16686:16686 -p 4318:4318 jaegertracing/all-in-one:latest"
12+
},
13+
"devDependencies": {
14+
"@opentelemetry/api": "^1.9.1",
15+
"@opentelemetry/auto-instrumentations-node": "^0.77.0",
16+
"@opentelemetry/exporter-trace-otlp-http": "^0.219.0",
17+
"@opentelemetry/resources": "^2.8.0",
18+
"@opentelemetry/sdk-node": "^0.219.0",
19+
"@opentelemetry/sdk-trace-node": "^2.8.0",
20+
"@orpc/client": "beta",
21+
"@orpc/evlog": "beta",
22+
"@orpc/json-schema": "beta",
23+
"@orpc/next": "beta",
24+
"@orpc/openapi": "beta",
25+
"@orpc/opentelemetry": "beta",
26+
"@orpc/publisher": "beta",
27+
"@orpc/server": "beta",
28+
"@orpc/tanstack-query": "beta",
29+
"@orpc/zod": "beta",
30+
"@tanstack/react-query": "^5.101.2",
31+
"@types/bun": "latest",
32+
"@types/react": "^19.2.17",
33+
"@types/react-dom": "^19",
34+
"evlog": "^2.19.2",
35+
"react": "^19.2.7",
36+
"react-dom": "^19.2.7",
37+
"ts-pattern": "^5.9.0"
38+
}
39+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
'use client'
2+
3+
import { orpc } from '../lib/orpc'
4+
import { useMutation, useQuery } from '@tanstack/react-query'
5+
import { match } from 'ts-pattern'
6+
import { parseFormData } from '@orpc/openapi/helpers'
7+
8+
const CHANNEL = 'default'
9+
10+
export function ChatRoom() {
11+
const query = useQuery(orpc.message.subscribe.streamedOptions({
12+
input: { channel: CHANNEL },
13+
context: { retry: Infinity },
14+
queryFnOptions: { maxChunks: 10 },
15+
}))
16+
17+
const mutation = useMutation(orpc.message.publish.mutationOptions())
18+
19+
const statusLabel = match(query)
20+
.with({ status: 'pending' }, () => 'Joining')
21+
.with({ status: 'error' }, () => 'Error')
22+
.with({ status: 'success' }, () => 'Listening')
23+
.exhaustive()
24+
25+
return (
26+
<section className="module module--violet" aria-labelledby="chat-room-title">
27+
<span className="corner tl" />
28+
<span className="corner tr" />
29+
<span className="corner bl" />
30+
<span className="corner br" />
31+
32+
<div className="module-head">
33+
<div>
34+
<span className="module-id">CH-03 · PUB/SUB</span>
35+
<h2 className="module-title" id="chat-room-title">
36+
oRPC and Tanstack Query | Pub/Sub Example
37+
</h2>
38+
<p className="module-desc">
39+
A live subscription over oRPC. Open this page in two tabs to chat across the channel.
40+
</p>
41+
</div>
42+
<span className="status-pill">
43+
<span className="dot" />
44+
<span className="status-text">{statusLabel}</span>
45+
</span>
46+
</div>
47+
48+
<div className="channel-log">
49+
{match(query)
50+
.with({ status: 'pending' }, () => <p className="channel-empty">joining...</p>)
51+
.with({ status: 'error' }, q => <p className="module-error">{String(q.error)}</p>)
52+
.with({ status: 'success' }, q => q.data.length === 0
53+
? (
54+
<p className="channel-empty">
55+
waiting for new messages..., please open in multiple tabs for chatting together
56+
</p>
57+
)
58+
: (
59+
<ul className="msg-list">
60+
{q.data.map(({ message }, i) => (
61+
<li key={i} className="msg">
62+
<span className="msg-text">{message}</span>
63+
</li>
64+
))}
65+
</ul>
66+
))
67+
.exhaustive()}
68+
</div>
69+
70+
<form
71+
className="channel-form"
72+
action={form => mutation.mutate({ ...parseFormData(form), channel: CHANNEL })}
73+
>
74+
<div className="prompt-wrap">
75+
<span className="prompt-char"></span>
76+
<input type="text" name="message" required minLength={1} placeholder="message..." />
77+
</div>
78+
<button type="submit" className="btn" disabled={query.isPending || mutation.isPending}>
79+
{mutation.isPending ? 'Sending…' : 'Send'}
80+
</button>
81+
</form>
82+
</section>
83+
)
84+
}

0 commit comments

Comments
 (0)