create-rr-stack 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +113 -2
- package/index.ts +48 -0
- package/package.json +34 -4
- package/scaffold.ts +89 -0
- package/template/.env.example +3 -0
- package/template/.github/workflows/ci.yml +38 -0
- package/template/AGENTS.md +44 -0
- package/template/CLAUDE.md +1 -0
- package/template/LICENSE +21 -0
- package/template/README.md +114 -0
- package/template/_gitignore +7 -0
- package/template/compose.yml +17 -0
- package/template/openapi.json +137 -0
- package/template/scripts/check.sh +49 -0
- package/template/scripts/smoke.sh +31 -0
- package/template/server/.sqlx/query-2abc65ebb76339a9d9a9d09820c9cdd6ceba212593a9641b80cda81df39e2fed.json +64 -0
- package/template/server/.sqlx/query-4713cdeecf4c3beeef699a78fc6f52857ba3a8f357565ba00d1d97095057e0f5.json +62 -0
- package/template/server/Cargo.lock +2135 -0
- package/template/server/Cargo.toml +34 -0
- package/template/server/clippy.toml +2 -0
- package/template/server/migrations/0001_todos.sql +6 -0
- package/template/server/src/bin/openapi.rs +4 -0
- package/template/server/src/health.rs +15 -0
- package/template/server/src/lib.rs +80 -0
- package/template/server/src/main.rs +22 -0
- package/template/server/src/todos.rs +94 -0
- package/template/server/tests/health.rs +31 -0
- package/template/server/tests/todos.rs +83 -0
- package/template/web/_gitignore +7 -0
- package/template/web/app/api/@tanstack/react-query.gen.ts +84 -0
- package/template/web/app/api/client/client.gen.ts +277 -0
- package/template/web/app/api/client/index.ts +27 -0
- package/template/web/app/api/client/types.gen.ts +218 -0
- package/template/web/app/api/client/utils.gen.ts +316 -0
- package/template/web/app/api/client.gen.ts +16 -0
- package/template/web/app/api/core/auth.gen.ts +48 -0
- package/template/web/app/api/core/bodySerializer.gen.ts +82 -0
- package/template/web/app/api/core/params.gen.ts +178 -0
- package/template/web/app/api/core/pathSerializer.gen.ts +171 -0
- package/template/web/app/api/core/queryKeySerializer.gen.ts +117 -0
- package/template/web/app/api/core/serverSentEvents.gen.ts +242 -0
- package/template/web/app/api/core/types.gen.ts +110 -0
- package/template/web/app/api/core/utils.gen.ts +140 -0
- package/template/web/app/api/index.ts +4 -0
- package/template/web/app/api/sdk.gen.ts +32 -0
- package/template/web/app/api/types.gen.ts +74 -0
- package/template/web/app/app.css +15 -0
- package/template/web/app/root.tsx +82 -0
- package/template/web/app/routes/home.tsx +21 -0
- package/template/web/app/routes/todos.tsx +47 -0
- package/template/web/app/routes.ts +6 -0
- package/template/web/bun.lock +572 -0
- package/template/web/openapi-ts.config.ts +11 -0
- package/template/web/package.json +30 -0
- package/template/web/public/favicon.ico +0 -0
- package/template/web/react-router.config.ts +7 -0
- package/template/web/tsconfig.json +26 -0
- package/template/web/vite.config.ts +13 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
|
|
4
|
+
import {
|
|
5
|
+
type ArraySeparatorStyle,
|
|
6
|
+
serializeArrayParam,
|
|
7
|
+
serializeObjectParam,
|
|
8
|
+
serializePrimitiveParam,
|
|
9
|
+
} from './pathSerializer.gen';
|
|
10
|
+
|
|
11
|
+
export interface PathSerializer {
|
|
12
|
+
path: Record<string, unknown>;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const PATH_PARAM_RE: RegExp = /\{[^{}]+\}/g;
|
|
17
|
+
|
|
18
|
+
export const defaultPathSerializer = ({ path, url: _url }: PathSerializer): string => {
|
|
19
|
+
let url = _url;
|
|
20
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
21
|
+
if (matches) {
|
|
22
|
+
for (const match of matches) {
|
|
23
|
+
let explode = false;
|
|
24
|
+
let name = match.substring(1, match.length - 1);
|
|
25
|
+
let style: ArraySeparatorStyle = 'simple';
|
|
26
|
+
|
|
27
|
+
if (name.endsWith('*')) {
|
|
28
|
+
explode = true;
|
|
29
|
+
name = name.substring(0, name.length - 1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (name.startsWith('.')) {
|
|
33
|
+
name = name.substring(1);
|
|
34
|
+
style = 'label';
|
|
35
|
+
} else if (name.startsWith(';')) {
|
|
36
|
+
name = name.substring(1);
|
|
37
|
+
style = 'matrix';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const value = path[name];
|
|
41
|
+
|
|
42
|
+
if (value === undefined || value === null) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof value === 'object') {
|
|
52
|
+
url = url.replace(
|
|
53
|
+
match,
|
|
54
|
+
serializeObjectParam({
|
|
55
|
+
explode,
|
|
56
|
+
name,
|
|
57
|
+
style,
|
|
58
|
+
value: value as Record<string, unknown>,
|
|
59
|
+
valueOnly: true,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (style === 'matrix') {
|
|
66
|
+
url = url.replace(
|
|
67
|
+
match,
|
|
68
|
+
`;${serializePrimitiveParam({
|
|
69
|
+
name,
|
|
70
|
+
value: value as string,
|
|
71
|
+
})}`,
|
|
72
|
+
);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const replaceValue = encodeURIComponent(
|
|
77
|
+
style === 'label' ? `.${value as string}` : (value as string),
|
|
78
|
+
);
|
|
79
|
+
url = url.replace(match, replaceValue);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return url;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const getUrl = ({
|
|
86
|
+
baseUrl,
|
|
87
|
+
path,
|
|
88
|
+
query,
|
|
89
|
+
querySerializer,
|
|
90
|
+
url: _url,
|
|
91
|
+
}: {
|
|
92
|
+
baseUrl?: string;
|
|
93
|
+
path?: Record<string, unknown>;
|
|
94
|
+
query?: Record<string, unknown>;
|
|
95
|
+
querySerializer: QuerySerializer;
|
|
96
|
+
url: string;
|
|
97
|
+
}): string => {
|
|
98
|
+
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
99
|
+
let url = (baseUrl ?? '') + pathUrl;
|
|
100
|
+
if (path) {
|
|
101
|
+
url = defaultPathSerializer({ path, url });
|
|
102
|
+
}
|
|
103
|
+
let search = query ? querySerializer(query) : '';
|
|
104
|
+
if (search.startsWith('?')) {
|
|
105
|
+
search = search.substring(1);
|
|
106
|
+
}
|
|
107
|
+
if (search) {
|
|
108
|
+
url += `?${search}`;
|
|
109
|
+
}
|
|
110
|
+
return url;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export function getValidRequestBody(options: {
|
|
114
|
+
body?: unknown;
|
|
115
|
+
bodySerializer?: BodySerializer | null;
|
|
116
|
+
serializedBody?: unknown;
|
|
117
|
+
}): unknown {
|
|
118
|
+
const hasBody = options.body !== undefined;
|
|
119
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
120
|
+
|
|
121
|
+
if (isSerializedBody) {
|
|
122
|
+
if ('serializedBody' in options) {
|
|
123
|
+
const hasSerializedBody =
|
|
124
|
+
options.serializedBody !== undefined && options.serializedBody !== '';
|
|
125
|
+
|
|
126
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// not all clients implement a serializedBody property (i.e., client-axios)
|
|
130
|
+
return options.body !== '' ? options.body : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// plain/text body
|
|
134
|
+
if (hasBody) {
|
|
135
|
+
return options.body;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// no body was provided
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export { createTodo, health, listTodos, type Options } from './sdk.gen';
|
|
4
|
+
export type { ClientOptions, CreateTodoData, CreateTodoErrors, CreateTodoResponse, CreateTodoResponses, Health, HealthData, HealthResponse, HealthResponses, ListTodosData, ListTodosResponse, ListTodosResponses, NewTodo, Todo, TodoTitle } from './types.gen';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { Client, ClientMeta, Options as Options2, RequestResult, TDataShape } from './client';
|
|
4
|
+
import { client } from './client.gen';
|
|
5
|
+
import type { CreateTodoData, CreateTodoErrors, CreateTodoResponses, HealthData, HealthResponses, ListTodosData, ListTodosResponses } from './types.gen';
|
|
6
|
+
|
|
7
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options2<TData, ThrowOnError, TResponse> & {
|
|
8
|
+
/**
|
|
9
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
10
|
+
* individual options. This might be also useful if you want to implement a
|
|
11
|
+
* custom client.
|
|
12
|
+
*/
|
|
13
|
+
client?: Client;
|
|
14
|
+
/**
|
|
15
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
16
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
17
|
+
*/
|
|
18
|
+
meta?: keyof ClientMeta extends never ? Record<string, unknown> : ClientMeta;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const health = <ThrowOnError extends boolean = false>(options?: Options<HealthData, ThrowOnError>): RequestResult<HealthResponses, unknown, ThrowOnError> => (options?.client ?? client).get<HealthResponses, unknown, ThrowOnError>({ url: '/api/health', ...options });
|
|
22
|
+
|
|
23
|
+
export const listTodos = <ThrowOnError extends boolean = false>(options?: Options<ListTodosData, ThrowOnError>): RequestResult<ListTodosResponses, unknown, ThrowOnError> => (options?.client ?? client).get<ListTodosResponses, unknown, ThrowOnError>({ url: '/api/todos', ...options });
|
|
24
|
+
|
|
25
|
+
export const createTodo = <ThrowOnError extends boolean = false>(options: Options<CreateTodoData, ThrowOnError>): RequestResult<CreateTodoResponses, CreateTodoErrors, ThrowOnError> => (options.client ?? client).post<CreateTodoResponses, CreateTodoErrors, ThrowOnError>({
|
|
26
|
+
url: '/api/todos',
|
|
27
|
+
...options,
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
...options.headers
|
|
31
|
+
}
|
|
32
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type ClientOptions = {
|
|
4
|
+
baseUrl: `${string}://${string}` | (string & {});
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type Health = {
|
|
8
|
+
status: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type NewTodo = {
|
|
12
|
+
title: TodoTitle;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type Todo = {
|
|
16
|
+
/**
|
|
17
|
+
* RFC 3339 timestamp.
|
|
18
|
+
*/
|
|
19
|
+
created_at: string;
|
|
20
|
+
done: boolean;
|
|
21
|
+
id: number;
|
|
22
|
+
title: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A title that is already trimmed and 1..=200 characters; it cannot be built any other way.
|
|
27
|
+
*/
|
|
28
|
+
export type TodoTitle = string;
|
|
29
|
+
|
|
30
|
+
export type HealthData = {
|
|
31
|
+
body?: never;
|
|
32
|
+
path?: never;
|
|
33
|
+
query?: never;
|
|
34
|
+
url: '/api/health';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type HealthResponses = {
|
|
38
|
+
200: Health;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type HealthResponse = HealthResponses[keyof HealthResponses];
|
|
42
|
+
|
|
43
|
+
export type ListTodosData = {
|
|
44
|
+
body?: never;
|
|
45
|
+
path?: never;
|
|
46
|
+
query?: never;
|
|
47
|
+
url: '/api/todos';
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type ListTodosResponses = {
|
|
51
|
+
200: Array<Todo>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type ListTodosResponse = ListTodosResponses[keyof ListTodosResponses];
|
|
55
|
+
|
|
56
|
+
export type CreateTodoData = {
|
|
57
|
+
body: NewTodo;
|
|
58
|
+
path?: never;
|
|
59
|
+
query?: never;
|
|
60
|
+
url: '/api/todos';
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type CreateTodoErrors = {
|
|
64
|
+
/**
|
|
65
|
+
* title is empty or longer than 200 characters
|
|
66
|
+
*/
|
|
67
|
+
422: unknown;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type CreateTodoResponses = {
|
|
71
|
+
201: Todo;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type CreateTodoResponse = CreateTodoResponses[keyof CreateTodoResponses];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
3
|
+
@theme {
|
|
4
|
+
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif,
|
|
5
|
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
html,
|
|
9
|
+
body {
|
|
10
|
+
@apply bg-white dark:bg-gray-950;
|
|
11
|
+
|
|
12
|
+
@media (prefers-color-scheme: dark) {
|
|
13
|
+
color-scheme: dark;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRouteErrorResponse,
|
|
3
|
+
Links,
|
|
4
|
+
Meta,
|
|
5
|
+
Outlet,
|
|
6
|
+
Scripts,
|
|
7
|
+
ScrollRestoration,
|
|
8
|
+
} from "react-router";
|
|
9
|
+
|
|
10
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import type { Route } from "./+types/root";
|
|
13
|
+
import "./app.css";
|
|
14
|
+
|
|
15
|
+
export const links: Route.LinksFunction = () => [
|
|
16
|
+
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
|
|
17
|
+
{
|
|
18
|
+
rel: "preconnect",
|
|
19
|
+
href: "https://fonts.gstatic.com",
|
|
20
|
+
crossOrigin: "anonymous",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
rel: "stylesheet",
|
|
24
|
+
href: "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export function Layout({ children }: { children: React.ReactNode }) {
|
|
29
|
+
return (
|
|
30
|
+
<html lang="en">
|
|
31
|
+
<head>
|
|
32
|
+
<meta charSet="utf-8" />
|
|
33
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
34
|
+
<Meta />
|
|
35
|
+
<Links />
|
|
36
|
+
</head>
|
|
37
|
+
<body>
|
|
38
|
+
{children}
|
|
39
|
+
<ScrollRestoration />
|
|
40
|
+
<Scripts />
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function App() {
|
|
47
|
+
const [queryClient] = useState(() => new QueryClient());
|
|
48
|
+
return (
|
|
49
|
+
<QueryClientProvider client={queryClient}>
|
|
50
|
+
<Outlet />
|
|
51
|
+
</QueryClientProvider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|
56
|
+
let message = "Oops!";
|
|
57
|
+
let details = "An unexpected error occurred.";
|
|
58
|
+
let stack: string | undefined;
|
|
59
|
+
|
|
60
|
+
if (isRouteErrorResponse(error)) {
|
|
61
|
+
message = error.status === 404 ? "404" : "Error";
|
|
62
|
+
details =
|
|
63
|
+
error.status === 404
|
|
64
|
+
? "The requested page could not be found."
|
|
65
|
+
: error.statusText || details;
|
|
66
|
+
} else if (import.meta.env.DEV && error && error instanceof Error) {
|
|
67
|
+
details = error.message;
|
|
68
|
+
stack = error.stack;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<main className="pt-16 p-4 container mx-auto">
|
|
73
|
+
<h1>{message}</h1>
|
|
74
|
+
<p>{details}</p>
|
|
75
|
+
{stack && (
|
|
76
|
+
<pre className="w-full p-4 overflow-x-auto">
|
|
77
|
+
<code>{stack}</code>
|
|
78
|
+
</pre>
|
|
79
|
+
)}
|
|
80
|
+
</main>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Link } from "react-router";
|
|
2
|
+
import type { Route } from "./+types/home";
|
|
3
|
+
|
|
4
|
+
export function meta({}: Route.MetaArgs) {
|
|
5
|
+
return [
|
|
6
|
+
{ title: "RR stack" },
|
|
7
|
+
{ name: "description", content: "React + Rust, typed end to end." },
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function Home() {
|
|
12
|
+
return (
|
|
13
|
+
<main className="mx-auto max-w-xl p-8">
|
|
14
|
+
<h1 className="text-3xl font-bold">RR stack</h1>
|
|
15
|
+
<p className="mt-2">This page is prerendered at build time, so search engines see it.</p>
|
|
16
|
+
<Link className="mt-4 inline-block underline" to="/app/todos">
|
|
17
|
+
Open the app
|
|
18
|
+
</Link>
|
|
19
|
+
</main>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { createTodoMutation, listTodosOptions, listTodosQueryKey } from "~/api/@tanstack/react-query.gen";
|
|
4
|
+
|
|
5
|
+
export default function Todos() {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
const todos = useQuery(listTodosOptions());
|
|
8
|
+
const [title, setTitle] = useState("");
|
|
9
|
+
const create = useMutation({
|
|
10
|
+
...createTodoMutation(),
|
|
11
|
+
onSuccess: () => {
|
|
12
|
+
setTitle("");
|
|
13
|
+
return queryClient.invalidateQueries({ queryKey: listTodosQueryKey() });
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<main className="mx-auto max-w-xl p-8">
|
|
19
|
+
<h1 className="text-2xl font-bold">Todos</h1>
|
|
20
|
+
<form
|
|
21
|
+
className="mt-4 flex gap-2"
|
|
22
|
+
onSubmit={(e) => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
create.mutate({ body: { title } });
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<input
|
|
28
|
+
className="flex-1 border px-2 py-1"
|
|
29
|
+
aria-label="New todo"
|
|
30
|
+
value={title}
|
|
31
|
+
onChange={(e) => setTitle(e.target.value)}
|
|
32
|
+
/>
|
|
33
|
+
<button className="border px-3" type="submit" disabled={create.isPending}>
|
|
34
|
+
Add
|
|
35
|
+
</button>
|
|
36
|
+
</form>
|
|
37
|
+
{create.error && <p className="mt-2 text-red-600">{String(create.error)}</p>}
|
|
38
|
+
{todos.isPending && <p className="mt-4">Loading…</p>}
|
|
39
|
+
{todos.error && <p className="mt-4 text-red-600">Could not load todos.</p>}
|
|
40
|
+
<ul className="mt-4 list-disc pl-6">
|
|
41
|
+
{todos.data?.map((todo) => (
|
|
42
|
+
<li key={todo.id}>{todo.title}</li>
|
|
43
|
+
))}
|
|
44
|
+
</ul>
|
|
45
|
+
</main>
|
|
46
|
+
);
|
|
47
|
+
}
|