diff --git a/.gitignore b/.gitignore index 1890973a..143ad8b1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ node_modules *.vsix .svelte-kit +.astro/ .turbo diff --git a/examples/astro/.astro/content-assets.mjs b/examples/astro/.astro/content-assets.mjs deleted file mode 100644 index 2b8b8234..00000000 --- a/examples/astro/.astro/content-assets.mjs +++ /dev/null @@ -1 +0,0 @@ -export default new Map(); \ No newline at end of file diff --git a/examples/astro/.astro/content-modules.mjs b/examples/astro/.astro/content-modules.mjs deleted file mode 100644 index 2b8b8234..00000000 --- a/examples/astro/.astro/content-modules.mjs +++ /dev/null @@ -1 +0,0 @@ -export default new Map(); \ No newline at end of file diff --git a/examples/astro/.astro/data-store.json b/examples/astro/.astro/data-store.json deleted file mode 100644 index 0338e3d1..00000000 --- a/examples/astro/.astro/data-store.json +++ /dev/null @@ -1 +0,0 @@ -[["Map",1,2],"meta::meta",["Map",3,4,5,6],"astro-version","5.2.5","astro-config-digest","{\"root\":{},\"srcDir\":{},\"publicDir\":{},\"outDir\":{},\"cacheDir\":{},\"compressHTML\":true,\"base\":\"/\",\"trailingSlash\":\"ignore\",\"output\":\"static\",\"scopedStyleStrategy\":\"attribute\",\"build\":{\"format\":\"directory\",\"client\":{},\"server\":{},\"assets\":\"_astro\",\"serverEntry\":\"entry.mjs\",\"redirects\":true,\"inlineStylesheets\":\"auto\",\"concurrency\":1},\"server\":{\"open\":false,\"host\":false,\"port\":4321,\"streaming\":true},\"redirects\":{},\"image\":{\"endpoint\":{\"route\":\"/_image\"},\"service\":{\"entrypoint\":\"astro/assets/services/sharp\",\"config\":{}},\"domains\":[],\"remotePatterns\":[]},\"devToolbar\":{\"enabled\":true},\"markdown\":{\"syntaxHighlight\":\"shiki\",\"shikiConfig\":{\"langs\":[],\"langAlias\":{},\"theme\":\"github-dark\",\"themes\":{},\"wrap\":false,\"transformers\":[]},\"remarkPlugins\":[],\"rehypePlugins\":[],\"remarkRehype\":{},\"gfm\":true,\"smartypants\":true},\"security\":{\"checkOrigin\":true},\"env\":{\"schema\":{},\"validateSecrets\":false},\"experimental\":{\"clientPrerender\":false,\"contentIntellisense\":false,\"responsiveImages\":false,\"serializeConfig\":false},\"legacy\":{\"collections\":false}}"] \ No newline at end of file diff --git a/examples/astro/.astro/settings.json b/examples/astro/.astro/settings.json deleted file mode 100644 index b6b6899b..00000000 --- a/examples/astro/.astro/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "_variables": { - "lastUpdateCheck": 1741917295476 - } -} \ No newline at end of file diff --git a/examples/astro/.astro/types.d.ts b/examples/astro/.astro/types.d.ts deleted file mode 100644 index f964fe0c..00000000 --- a/examples/astro/.astro/types.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/examples/astro/package.json b/examples/astro/package.json index e0e5bf91..4ea4fa2e 100644 --- a/examples/astro/package.json +++ b/examples/astro/package.json @@ -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", diff --git a/examples/astro/src/components/solid.tsx b/examples/astro/src/components/solid.tsx index 23af3c54..f9d1bfca 100644 --- a/examples/astro/src/components/solid.tsx +++ b/examples/astro/src/components/solid.tsx @@ -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({ - transport: new FetchTransport("http://localhost:4000/rspc"), +const fetchQueryClient = new QueryClient({ + defaultOptions: { + queries: { + retry: false + } + } }); +const url = "http://localhost:4000/rspc"; +const client = createClient((args) => { + if (args.type === "subscription") return sseExecute({ url }, args); + else return fetchExecute({ url, batch: true, stream: true }, args); +}) -export const rspc = createSolidQueryHooks(); +const rspc = createRSPCOptionsProxy(client); function Example() { - const echo = rspc.createQuery(() => ["echo", "somevalue"]); - const sendMsg = rspc.createMutation(() => "sendMsg"); - - sendMsg.mutate("Sending"); - - return ( - - SolidJS - {echo.data} - {/* TODO: Finish SolidJS example */} - - ); + type Version = inferOutput + const version = useQuery(rspc.version.queryOptions()) + const validate = useQuery(rspc.validator.queryOptions({ mail: "example@example.com" })) + + 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 ( + + SolidJS + Loading}> + {version.data} + + subscription {JSON.stringify(subscription.data)} + + {error => + Error {error().type} + } + + status {subscription.status} + mutation.mutate("Message")}>Trigger mutation + + ); } function App() { - return ( - - - - ); + return ( + + + + ); } export default App; diff --git a/examples/astro/src/pages/index.astro b/examples/astro/src/pages/index.astro index 377b16ac..0dca9e70 100644 --- a/examples/astro/src/pages/index.astro +++ b/examples/astro/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import ReactComponent from "../components/react"; +// import ReactComponent from "../components/react"; import SolidComponent from "../components/solid"; --- @@ -26,7 +26,7 @@ import SolidComponent from "../components/solid"; - +
{echo.data}
{version.data}
subscription {JSON.stringify(subscription.data)}
Error {error().type}
status {subscription.status}