Skip to content

Commit 9e1b7d2

Browse files
authored
fix(routes): correctly handle litestar routes (#138)
- Implemented a Vite plugin for generating TypeScript types from OpenAPI schemas and route metadata. - Added utility to generate TypeScript types from routes.json metadata for type-safe routing. - Updated shared index to export new types and functions. - Refactored SvelteKit integration to utilize the new type generation plugin. - Created tests for the route type generation utility to ensure correctness. - Enhanced Python code for better route handling and configuration parsing. - Improved HTML escaping for JSON strings in Inertia helpers.
1 parent 0ed316e commit 9e1b7d2

38 files changed

+2308
-1349
lines changed

.github/workflows/docs.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ jobs:
3232
- name: Install litestar-vite package
3333
run: uv pip install -e .
3434

35+
- name: Set up Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: '22'
39+
cache: 'npm'
40+
41+
- name: Build JS plugin
42+
run: |
43+
npm ci
44+
npm run build
45+
3546
- name: Install VHS
3647
run: |
3748
# Install VHS via go (more reliable than charm install script)

docs/_tapes/assets-cli.tape

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ Type "litestar --app app:app assets build"
4949
Enter
5050
Sleep 5s
5151

52-
Type "# 'status' shows your integration at a glance"
53-
Enter
54-
Sleep 500ms
55-
56-
Type "litestar --app app:app assets status"
57-
Enter
58-
Sleep 2s
59-
6052
Type "# Same tools, unified interface!"
6153
Enter
62-
Sleep 2s
54+
Sleep 5s

docs/_tapes/scaffolding.tape

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Hide
2020
Type "source .venv/bin/activate"
2121
Enter
2222
Sleep 500ms
23-
# Create a temporary demo directory
23+
Hide
2424
Type "cd /tmp && rm -rf litestar-demo && mkdir litestar-demo && cd litestar-demo"
2525
Enter
2626
Sleep 500ms
@@ -54,9 +54,6 @@ Enter
5454
Sleep 500ms
5555
Show
5656

57-
Type "# Start with a basic Litestar app"
58-
Enter
59-
Sleep 500ms
6057

6158
Type "cat app.py"
6259
Enter

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@
137137
(PY_CLASS, "InertiaTypeGenConfig"),
138138
(PY_CLASS, "ScrollPropsConfig"),
139139
(PY_CLASS, "litestar_vite.inertia.types.ScrollPropsConfig"),
140+
# Logging and markup types
141+
(PY_CLASS, "LoggingConfig"),
142+
(PY_CLASS, "litestar_vite.config.LoggingConfig"),
143+
(PY_CLASS, "Markup"),
140144
]
141145
nitpick_ignore_regex = [
142146
(PY_RE, r"litestar_vite.*\.T"),

docs/frameworks/astro.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,15 @@ Add interactive islands with ``client:*`` directives:
139139
</body>
140140
</html>
141141
142-
.. code-block:: typescript
142+
.. code-block:: tsx
143143
144144
// src/components/Counter.tsx (React, Vue, Svelte, etc.)
145145
import { useState } from 'react'
146-
import type { Summary } from '../generated/types.gen'
147146
import { route } from '../generated/routes'
148147
149148
export default function Counter() {
150149
const [count, setCount] = useState(0)
151-
const [summary, setSummary] = useState<Summary | null>(null)
150+
const [summary, setSummary] = useState(null)
152151
153152
async function loadSummary() {
154153
const res = await fetch(route('summary'))

docs/frameworks/htmx.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ Return partial HTML for HTMX swaps using ``HTMXTemplate``:
7979
:start-after: # [docs-start:htmx-fragment]
8080
:end-before: # [docs-end:htmx-fragment]
8181
:caption: Fragment endpoint with HTMXTemplate
82-
:dedent: 4
8382

8483
The ``HTMXTemplate`` response allows:
8584

docs/reference/html_transform.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
==================
1+
===================
22
HTML Transformation
3-
==================
3+
===================
44

55
HTML transformation utilities for injecting scripts, metadata, and attributes
66
into HTML documents.

docs/reference/inertia/config.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
====================
1+
=====================
22
Inertia Configuration
3-
====================
3+
=====================
44

55
Configuration classes for Inertia.js integration.
66

docs/reference/inertia/exception_handler.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=======================
1+
=========================
22
Inertia Exception Handler
3-
=======================
3+
=========================
44

55
Exception handling utilities for Inertia.js requests.
66

docs/usage/migration-v015.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,14 @@ If your user model has different required fields (e.g., ``uuid`` instead of ``id
376376
),
377377
)
378378
379-
# Define your own User interface in TypeScript
379+
Then define your own User interface in TypeScript:
380+
381+
.. code-block:: typescript
382+
380383
declare module 'litestar-vite/inertia' {
381384
interface User {
382-
uuid: string // No id!
383-
username: string // No email!
385+
uuid: string
386+
username: string
384387
}
385388
}
386389

0 commit comments

Comments
 (0)