Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ node_modules
*.vsix

.svelte-kit
.astro/
.turbo
1 change: 0 additions & 1 deletion examples/astro/.astro/content-assets.mjs

This file was deleted.

1 change: 0 additions & 1 deletion examples/astro/.astro/content-modules.mjs

This file was deleted.

1 change: 0 additions & 1 deletion examples/astro/.astro/data-store.json

This file was deleted.

5 changes: 0 additions & 5 deletions examples/astro/.astro/settings.json

This file was deleted.

1 change: 0 additions & 1 deletion examples/astro/.astro/types.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions examples/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@rspc/client": "workspace:*",
"@rspc/react-query": "workspace:*",
"@rspc/solid-query": "workspace:*",
"@tanstack/react-query": "^5.66.0",
"@tanstack/solid-query": "^5.66.0",
"@tanstack/react-query": "^5.79.0",
"@tanstack/solid-query": "^5.79.0",
"astro": "5.2.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
83 changes: 59 additions & 24 deletions examples/astro/src/components/solid.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,75 @@
/** @jsxImportSource solid-js */

import { createClient, FetchTransport } from "@rspc/client";
import { createSolidQueryHooks } from "@rspc/solid-query";
import { QueryClient } from "@tanstack/solid-query";
import { createClient, fetchExecute, sseExecute, } from "@rspc/client/next";
import { createRSPCOptionsProxy, inferInput, inferOutput, useSubscription, } from "@rspc/solid-query";
import { QueryClient, QueryClientProvider, useQuery, useMutation, skipToken } from "@tanstack/solid-query";
import { Show } from "solid-js";

// Export from Rust. Run `cargo run -p example-axum` to start server and export it!
import { Procedures } from "../../../bindings";

const fetchQueryClient = new QueryClient();
const fetchClient = createClient<Procedures>({
transport: new FetchTransport("http://localhost:4000/rspc"),
const fetchQueryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false
}
}
});
const url = "http://localhost:4000/rspc";
const client = createClient<Procedures>((args) => {
if (args.type === "subscription") return sseExecute({ url }, args);
else return fetchExecute({ url, batch: true, stream: true }, args);
})

export const rspc = createSolidQueryHooks<Procedures>();
const rspc = createRSPCOptionsProxy<Procedures>(client);

function Example() {
const echo = rspc.createQuery(() => ["echo", "somevalue"]);
const sendMsg = rspc.createMutation(() => "sendMsg");

sendMsg.mutate("Sending");

return (
<div style="background-color: rgba(255, 105, 97, .5);">
<h1>SolidJS</h1>
<p>{echo.data}</p>
{/* TODO: Finish SolidJS example */}
</div>
);
type Version = inferOutput<typeof rspc.version>
const version = useQuery(rspc.version.queryOptions())
const validate = useQuery(rspc.validator.queryOptions({ mail: "[email protected]" }))

const mutation = useMutation(rspc.sendMsg.mutationOptions({
onSettled() {
fetchQueryClient.invalidateQueries({
queryKey: rspc.version.queryKey()
})
},
}))

const subscription = useSubscription(rspc.basicSubscription.subscriptionOptions(null, {
enabled: true,
onData(value) {
console.log("Data received", value)
},
onError(err) {
console.error(err.type, err.error)
},
}))

return (
<div>
<h1>SolidJS</h1>
<Show when={!version.isLoading} fallback={<p>Loading</p>}>
<p>{version.data}</p>
</Show>
<p>subscription {JSON.stringify(subscription.data)}</p>
<Show when={subscription.error}>
{error =>
<p>Error {error().type}</p>
}
</Show>
<p>status {subscription.status}</p>
<button onClick={() => mutation.mutate("Message")}>Trigger mutation</button>
</div>
);
}

function App() {
return (
<rspc.Provider client={fetchClient} queryClient={fetchQueryClient}>
<Example />
</rspc.Provider>
);
return (
<QueryClientProvider client={fetchQueryClient}>
<Example />
</QueryClientProvider>
);
}

export default App;
4 changes: 2 additions & 2 deletions examples/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import ReactComponent from "../components/react";
// import ReactComponent from "../components/react";
import SolidComponent from "../components/solid";
---

Expand All @@ -26,7 +26,7 @@ import SolidComponent from "../components/solid";
</head>

<body>
<ReactComponent client:only="react" />
<!-- <ReactComponent client:only="react" /> -->
<SolidComponent client:only="solid" />
</body>
</html>
2 changes: 1 addition & 1 deletion examples/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rspc-zer = { version = "0.0.0", path = "../../crates/zer" }
example-core = { path = "../core" }

tokio = { version = "1.43.0", features = ["full"] }
axum = { version = "0.8.1", features = ["multipart"] }
axum = { version = "0.8.4", features = ["multipart"] }
tower-http = { version = "0.6.2", default-features = false, features = [
"cors",
] }
Expand Down
19 changes: 16 additions & 3 deletions examples/deno/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { createClient, fetchExecute, sseExecute } from "@rspc/client/next";

import { Procedures } from "../bindings.ts";

const url = "http://[::]:4000/rspc";

const client = createClient<Procedures>((args) => {
if (args.type === "subscription") return sseExecute({ url }, args);
else return fetchExecute({ url, batch: true, stream: true }, args);
if (args.type === "subscription") return sseExecute({ url }, args);
else return fetchExecute({ url, batch: true, stream: true }, args);
});

client.version.query().then((v) => console.log("version", v));
client.flush.query().then((v) => console.log("flush", v));
client.flush2.query().then((v) => console.log("flush2", v));

client.sendMsg.mutate("message").then(v => console.log("message", v))

client.basicSubscription.subscribe(null, {
onData(value) {
console.log(value)
},
onError(err) {
console.error(err)
},
onComplete() {
console.log("completed")
},
})
4 changes: 4 additions & 0 deletions examples/deno/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../packages/tsconfig.json",
"compilerOptions": {}
}
2 changes: 1 addition & 1 deletion examples/nextjs/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
32 changes: 16 additions & 16 deletions examples/nextjs/src/rspc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { QueryClient } from "@tanstack/react-query";
import type { Procedures } from "../../bindings";

export const client = createClient<Procedures>({
transport:
typeof window === "undefined"
? // WebsocketTransport can not be used Server Side, so we provide FetchTransport instead.
// If you do not plan on using Subscriptions you can use FetchTransport on Client Side as well.
new FetchTransport("http://localhost:4000/rspc")
: new WebsocketTransport("ws://localhost:4000/rspc/ws"),
transport:
typeof window === "undefined"
? // WebsocketTransport can not be used Server Side, so we provide FetchTransport instead.
// If you do not plan on using Subscriptions you can use FetchTransport on Client Side as well.
new FetchTransport("http://localhost:4000/rspc")
: new WebsocketTransport("ws://localhost:4000/rspc/ws"),
});

export const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false, // If you want to retry when requests fail, remove this.
},
},
defaultOptions: {
queries: {
retry: false, // If you want to retry when requests fail, remove this.
},
},
});

export const {
useContext,
useMutation,
useQuery,
useSubscription,
Provider: RSPCProvider,
useContext,
useMutation,
useQuery,
useSubscription,
Provider: RSPCProvider,
} = createReactQueryHooks<Procedures>();
2 changes: 1 addition & 1 deletion integrations/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws = ["axum/ws"]

[dependencies]
rspc-procedure = { version = "0.0.1", path = "../../crates/procedure" }
axum = { version = "0.8.1", features = ["ws", "json", "multipart"] }
axum = { version = "0.8.4", features = ["ws", "json", "multipart"] }
serde_json = "1"

# TODO: Drop these
Expand Down
4 changes: 2 additions & 2 deletions integrations/axum/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where
handle_json_rpc(
ctx,
jsonrpc::Request {
jsonrpc: None,
// jsonrpc: None,
id: RequestId::Null,
inner: match kind {
ProcedureKind::Query => jsonrpc::RequestInner::Query {
Expand Down Expand Up @@ -228,7 +228,7 @@ async fn handle_websocket<TCtx, TCtxFn, TCtxFnMarker, TState>(
biased; // Note: Order is important here
msg = rx.recv() => {
match socket.send(Message::Text(match serde_json::to_string(&msg) {
Ok(v) => v,
Ok(v) => v.into(),
Err(_err) => {
// #[cfg(feature = "tracing")]
// tracing::error!("Error serializing websocket message: {}", _err);
Expand Down
5 changes: 3 additions & 2 deletions integrations/axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
html_favicon_url = "https://github.com/specta-rs/rspc/raw/main/.github/logo.png"
)]

mod endpoint;
// mod endpoint;
mod extractors;
mod jsonrpc;
mod jsonrpc_exec;
// mod legacy;
pub mod next;
mod request;

pub use endpoint::endpoint;
// pub use endpoint::endpoint;

// pub use endpoint::Endpoint;
// pub use request::AxumRequest;
// pub use v2::{Endpoint, flush};
pub use next::{Endpoint, flush};
2 changes: 2 additions & 0 deletions integrations/tauri/permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Allows making rspc requests

#### This default permission set includes the following:

- `allow-handle-rpc`

## Permission Table
Expand Down
15 changes: 9 additions & 6 deletions integrations/tauri/permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"minimum": 1.0
},
"description": {
"description": "Human-readable description of what the permission does. Tauri convention is to use <h4> headings in markdown content for Tauri documentation generation purposes.",
"description": "Human-readable description of what the permission does. Tauri convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
"type": [
"string",
"null"
Expand Down Expand Up @@ -111,7 +111,7 @@
"type": "string"
},
"description": {
"description": "Human-readable description of what the permission does. Tauri internal convention is to use <h4> headings in markdown content for Tauri documentation generation purposes.",
"description": "Human-readable description of what the permission does. Tauri internal convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
"type": [
"string",
"null"
Expand Down Expand Up @@ -297,17 +297,20 @@
{
"description": "Enables the handle_rpc command without any pre-configured scope.",
"type": "string",
"const": "allow-handle-rpc"
"const": "allow-handle-rpc",
"markdownDescription": "Enables the handle_rpc command without any pre-configured scope."
},
{
"description": "Denies the handle_rpc command without any pre-configured scope.",
"type": "string",
"const": "deny-handle-rpc"
"const": "deny-handle-rpc",
"markdownDescription": "Denies the handle_rpc command without any pre-configured scope."
},
{
"description": "Allows making rspc requests",
"description": "Allows making rspc requests\n#### This default permission set includes:\n\n- `allow-handle-rpc`",
"type": "string",
"const": "default"
"const": "default",
"markdownDescription": "Allows making rspc requests\n#### This default permission set includes:\n\n- `allow-handle-rpc`"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react": "pnpm --filter @rspc/react -- ",
"solid": "pnpm --filter @rspc/solid -- ",
"tauri": "pnpm --filter @rspc/tauri -- ",
"fix": "biome lint --apply . && biome format --write . && biome check . --apply"
"fix": "biome lint --write . && biome format --write . && biome check . --write"
},
"engines": {
"pnpm": ">=7.0.0",
Expand All @@ -26,7 +26,7 @@
"node": ">=16.0.0"
},
"devDependencies": {
"biome": "^0.3.3",
"@biomejs/biome": "^1.9.4",
"turbo": "^2.4.0"
},
"packageManager": "[email protected]"
Expand Down
16 changes: 4 additions & 12 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
"default": "./dist/index.cjs"
},
"./next": {
"types": "./dist/next/index.d.cts",
"types": "./dist/next/index.d.ts",
"import": "./dist/next/index.js",
"default": "./dist/next/index.cjs"
}
},
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
Expand All @@ -34,14 +32,8 @@
"typescript": "^5.7.3"
},
"tsup": {
"entry": [
"src/index.ts",
"src/next/index.ts"
],
"format": [
"esm",
"cjs"
],
"entry": ["src/index.ts", "src/next/index.ts"],
"format": ["esm", "cjs"],
"dts": true,
"splitting": true,
"clean": true,
Expand Down
Loading