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,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.1.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "utoipa-axum",
|
|
5
|
+
"description": "Utoipa's axum bindings for seamless integration for the two",
|
|
6
|
+
"contact": {
|
|
7
|
+
"name": "Juha Kukkonen",
|
|
8
|
+
"email": "juha7kukkonen@gmail.com"
|
|
9
|
+
},
|
|
10
|
+
"license": {
|
|
11
|
+
"name": "MIT OR Apache-2.0",
|
|
12
|
+
"identifier": "MIT OR Apache-2.0"
|
|
13
|
+
},
|
|
14
|
+
"version": "0.3.0"
|
|
15
|
+
},
|
|
16
|
+
"paths": {
|
|
17
|
+
"/api/health": {
|
|
18
|
+
"get": {
|
|
19
|
+
"operationId": "health",
|
|
20
|
+
"responses": {
|
|
21
|
+
"200": {
|
|
22
|
+
"content": {
|
|
23
|
+
"application/json": {
|
|
24
|
+
"schema": {
|
|
25
|
+
"$ref": "#/components/schemas/Health"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"/api/todos": {
|
|
34
|
+
"get": {
|
|
35
|
+
"operationId": "listTodos",
|
|
36
|
+
"responses": {
|
|
37
|
+
"200": {
|
|
38
|
+
"content": {
|
|
39
|
+
"application/json": {
|
|
40
|
+
"schema": {
|
|
41
|
+
"type": "array",
|
|
42
|
+
"items": {
|
|
43
|
+
"$ref": "#/components/schemas/Todo"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"post": {
|
|
52
|
+
"operationId": "createTodo",
|
|
53
|
+
"requestBody": {
|
|
54
|
+
"content": {
|
|
55
|
+
"application/json": {
|
|
56
|
+
"schema": {
|
|
57
|
+
"$ref": "#/components/schemas/NewTodo"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"required": true
|
|
62
|
+
},
|
|
63
|
+
"responses": {
|
|
64
|
+
"201": {
|
|
65
|
+
"content": {
|
|
66
|
+
"application/json": {
|
|
67
|
+
"schema": {
|
|
68
|
+
"$ref": "#/components/schemas/Todo"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"422": {
|
|
74
|
+
"description": "title is empty or longer than 200 characters"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"components": {
|
|
81
|
+
"schemas": {
|
|
82
|
+
"Health": {
|
|
83
|
+
"type": "object",
|
|
84
|
+
"required": [
|
|
85
|
+
"status"
|
|
86
|
+
],
|
|
87
|
+
"properties": {
|
|
88
|
+
"status": {
|
|
89
|
+
"type": "string"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"NewTodo": {
|
|
94
|
+
"type": "object",
|
|
95
|
+
"required": [
|
|
96
|
+
"title"
|
|
97
|
+
],
|
|
98
|
+
"properties": {
|
|
99
|
+
"title": {
|
|
100
|
+
"$ref": "#/components/schemas/TodoTitle"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"Todo": {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"required": [
|
|
107
|
+
"id",
|
|
108
|
+
"title",
|
|
109
|
+
"done",
|
|
110
|
+
"created_at"
|
|
111
|
+
],
|
|
112
|
+
"properties": {
|
|
113
|
+
"created_at": {
|
|
114
|
+
"type": "string",
|
|
115
|
+
"description": "RFC 3339 timestamp."
|
|
116
|
+
},
|
|
117
|
+
"done": {
|
|
118
|
+
"type": "boolean"
|
|
119
|
+
},
|
|
120
|
+
"id": {
|
|
121
|
+
"type": "integer",
|
|
122
|
+
"format": "int64"
|
|
123
|
+
},
|
|
124
|
+
"title": {
|
|
125
|
+
"type": "string"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"TodoTitle": {
|
|
130
|
+
"type": "string",
|
|
131
|
+
"description": "A title that is already trimmed and 1..=200 characters; it cannot be built any other way.",
|
|
132
|
+
"maxLength": 200,
|
|
133
|
+
"minLength": 1
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The definition of done. Exit 0 means SQL, Rust, the OpenAPI contract and the React code agree.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
5
|
+
[ -f "$root/.env" ] && { set -a; . "$root/.env"; set +a; }
|
|
6
|
+
export SQLX_OFFLINE=true
|
|
7
|
+
step() { printf '\n== %s\n' "$*"; }
|
|
8
|
+
|
|
9
|
+
cd "$root/server"
|
|
10
|
+
step "rustfmt"
|
|
11
|
+
cargo fmt --check
|
|
12
|
+
step "clippy (offline SQL metadata from .sqlx/)"
|
|
13
|
+
cargo clippy -q --all-targets -- -D warnings
|
|
14
|
+
|
|
15
|
+
step "contract: openapi.json and web/app/api match a fresh generation"
|
|
16
|
+
tmp="$(mktemp -d)"
|
|
17
|
+
trap 'rm -rf "$tmp"' EXIT
|
|
18
|
+
cargo run -q --bin openapi > "$tmp/openapi.json"
|
|
19
|
+
(cd "$root/web" && RR_OPENAPI="$tmp/openapi.json" RR_API_OUT="$tmp/api" bunx openapi-ts >/dev/null)
|
|
20
|
+
if ! diff -q "$root/openapi.json" "$tmp/openapi.json" >/dev/null || ! diff -rq "$root/web/app/api" "$tmp/api" >/dev/null; then
|
|
21
|
+
diff -ru "$root/openapi.json" "$tmp/openapi.json" | head -20 || true
|
|
22
|
+
diff -rq "$root/web/app/api" "$tmp/api" || true
|
|
23
|
+
echo "generated files are stale or hand-edited: run 'cd web && bun run gen' and commit" >&2
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
step "typecheck"
|
|
28
|
+
(cd "$root/web" && bun run typecheck >/dev/null)
|
|
29
|
+
step "web build (prerendered pages render)"
|
|
30
|
+
(cd "$root/web" && bun run build >/dev/null)
|
|
31
|
+
|
|
32
|
+
if [ -n "${DATABASE_URL:-}" ]; then
|
|
33
|
+
command -v sqlx >/dev/null || { echo "sqlx-cli missing: cargo install sqlx-cli --no-default-features --features postgres,rustls" >&2; exit 1; }
|
|
34
|
+
step "migrations + .sqlx/ up to date"
|
|
35
|
+
sqlx migrate run >/dev/null
|
|
36
|
+
cargo sqlx prepare --check -- --all-targets
|
|
37
|
+
step "tests"
|
|
38
|
+
cargo test -q
|
|
39
|
+
elif [ "${SKIP_DB:-}" = 1 ]; then
|
|
40
|
+
echo "SKIP_DB=1: skipped .sqlx check and tests. This is NOT done."
|
|
41
|
+
else
|
|
42
|
+
echo "DATABASE_URL is not set: start the DB (docker compose up -d --wait) or set SKIP_DB=1 for a partial check" >&2
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
if [ -d "$root/cli" ]; then
|
|
46
|
+
step "cli tests"
|
|
47
|
+
(cd "$root/cli" && bun test 2>&1 | tail -3)
|
|
48
|
+
fi
|
|
49
|
+
echo; echo "check OK"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Builds the web app, runs the real server binary, and checks what a browser and an API client get.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
5
|
+
[ -f "$root/.env" ] && { set -a; . "$root/.env"; set +a; }
|
|
6
|
+
: "${DATABASE_URL:?DATABASE_URL must be set (cp .env.example .env)}"
|
|
7
|
+
|
|
8
|
+
(cd "$root/web" && bun run build >/dev/null 2>&1)
|
|
9
|
+
(cd "$root/server" && cargo build -q --bin server)
|
|
10
|
+
|
|
11
|
+
port="$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1])')"
|
|
12
|
+
PORT="$port" WEB_DIST="$root/web/build/client" "$root/server/target/debug/server" >/dev/null 2>&1 &
|
|
13
|
+
pid=$!
|
|
14
|
+
trap 'kill "$pid" 2>/dev/null || true' EXIT
|
|
15
|
+
base="http://127.0.0.1:$port"
|
|
16
|
+
for _ in $(seq 50); do curl -sf "$base/api/health" >/dev/null && break; sleep 0.2; done
|
|
17
|
+
|
|
18
|
+
fail() { echo "smoke FAIL: $*" >&2; exit 1; }
|
|
19
|
+
expect() { # expect <status> <method> <path> [body]
|
|
20
|
+
local out; out="$(mktemp)"
|
|
21
|
+
local code; code="$(curl -s -o "$out" -w '%{http_code} %{content_type}' -X "$2" -H 'content-type: application/json' ${4:+--data "$4"} "$base$3")"
|
|
22
|
+
[[ "${code%% *}" == "$1" ]] || fail "$2 $3 → $code, want $1"
|
|
23
|
+
cat "$out"; rm -f "$out"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
expect 200 GET / | grep -q 'RR stack</h1>' || fail "/ is not the prerendered landing page"
|
|
27
|
+
expect 200 GET /app/todos | grep -q '<script' || fail "/app/todos did not return the SPA fallback"
|
|
28
|
+
curl -s -o /dev/null -w '%{content_type}' "$base/api/nope" | grep -q '^application/json' || fail "/api/nope is not JSON"
|
|
29
|
+
expect 404 GET /api/nope >/dev/null
|
|
30
|
+
expect 201 POST /api/todos '{"title":"smoke"}' >/dev/null
|
|
31
|
+
echo "smoke OK"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"db_name": "PostgreSQL",
|
|
3
|
+
"query": "INSERT INTO todos (title) VALUES ($1) RETURNING id, title, done, created_at",
|
|
4
|
+
"describe": {
|
|
5
|
+
"columns": [
|
|
6
|
+
{
|
|
7
|
+
"ordinal": 0,
|
|
8
|
+
"name": "id",
|
|
9
|
+
"type_info": "Int8",
|
|
10
|
+
"origin": {
|
|
11
|
+
"Table": {
|
|
12
|
+
"table": "todos",
|
|
13
|
+
"name": "id"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"ordinal": 1,
|
|
19
|
+
"name": "title",
|
|
20
|
+
"type_info": "Text",
|
|
21
|
+
"origin": {
|
|
22
|
+
"Table": {
|
|
23
|
+
"table": "todos",
|
|
24
|
+
"name": "title"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"ordinal": 2,
|
|
30
|
+
"name": "done",
|
|
31
|
+
"type_info": "Bool",
|
|
32
|
+
"origin": {
|
|
33
|
+
"Table": {
|
|
34
|
+
"table": "todos",
|
|
35
|
+
"name": "done"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"ordinal": 3,
|
|
41
|
+
"name": "created_at",
|
|
42
|
+
"type_info": "Timestamptz",
|
|
43
|
+
"origin": {
|
|
44
|
+
"Table": {
|
|
45
|
+
"table": "todos",
|
|
46
|
+
"name": "created_at"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"parameters": {
|
|
52
|
+
"Left": [
|
|
53
|
+
"Text"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"nullable": [
|
|
57
|
+
false,
|
|
58
|
+
false,
|
|
59
|
+
false,
|
|
60
|
+
false
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"hash": "2abc65ebb76339a9d9a9d09820c9cdd6ceba212593a9641b80cda81df39e2fed"
|
|
64
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"db_name": "PostgreSQL",
|
|
3
|
+
"query": "SELECT id, title, done, created_at FROM todos ORDER BY created_at DESC, id DESC",
|
|
4
|
+
"describe": {
|
|
5
|
+
"columns": [
|
|
6
|
+
{
|
|
7
|
+
"ordinal": 0,
|
|
8
|
+
"name": "id",
|
|
9
|
+
"type_info": "Int8",
|
|
10
|
+
"origin": {
|
|
11
|
+
"Table": {
|
|
12
|
+
"table": "todos",
|
|
13
|
+
"name": "id"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"ordinal": 1,
|
|
19
|
+
"name": "title",
|
|
20
|
+
"type_info": "Text",
|
|
21
|
+
"origin": {
|
|
22
|
+
"Table": {
|
|
23
|
+
"table": "todos",
|
|
24
|
+
"name": "title"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"ordinal": 2,
|
|
30
|
+
"name": "done",
|
|
31
|
+
"type_info": "Bool",
|
|
32
|
+
"origin": {
|
|
33
|
+
"Table": {
|
|
34
|
+
"table": "todos",
|
|
35
|
+
"name": "done"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"ordinal": 3,
|
|
41
|
+
"name": "created_at",
|
|
42
|
+
"type_info": "Timestamptz",
|
|
43
|
+
"origin": {
|
|
44
|
+
"Table": {
|
|
45
|
+
"table": "todos",
|
|
46
|
+
"name": "created_at"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"parameters": {
|
|
52
|
+
"Left": []
|
|
53
|
+
},
|
|
54
|
+
"nullable": [
|
|
55
|
+
false,
|
|
56
|
+
false,
|
|
57
|
+
false,
|
|
58
|
+
false
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"hash": "4713cdeecf4c3beeef699a78fc6f52857ba3a8f357565ba00d1d97095057e0f5"
|
|
62
|
+
}
|