Skip to content

Commit 4274a8d

Browse files
authored
Generate TyepScript interface completely from Python (#112)
1 parent 6b7c7cb commit 4274a8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1354
-2577
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
node-version: 18
2626

2727
- run: pip install -r src/python-fastui/requirements/all.txt
28+
- run: pip install src/python-fastui
2829

2930
- run: npm install
3031

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ repos:
3939
entry: npm run typecheck
4040
language: system
4141
pass_filenames: false
42-
- id: js-json-schema
43-
name: js-json-schema
44-
types_or: [ts, tsx]
45-
entry: npm run generate-json-schema
42+
- id: python-generate-ts
43+
name: python-generate-ts
44+
types_or: [python]
45+
entry: fastui generate fastui:FastUI src/npm-fastui/src/models.d.ts
4646
language: system
4747
pass_filenames: false

demo/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def auth_login(user: Annotated[str | None, Depends(get_user)]) -> list[AnyCompon
3535
)
3636
),
3737
c.Heading(text='Login'),
38-
c.ModelForm[LoginForm](submit_url='/api/auth/login'),
38+
c.ModelForm(model=LoginForm, submit_url='/api/auth/login'),
3939
title='Authentication',
4040
)
4141
else:

demo/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ def form_content(kind: FormKind):
8585
return [
8686
c.Heading(text='Login Form', level=2),
8787
c.Paragraph(text='Simple login form with email and password.'),
88-
c.ModelForm[LoginForm](submit_url='/api/forms/login'),
88+
c.ModelForm(model=LoginForm, submit_url='/api/forms/login'),
8989
]
9090
case 'select':
9191
return [
9292
c.Heading(text='Select Form', level=2),
9393
c.Paragraph(text='Form showing different ways of doing select.'),
94-
c.ModelForm[SelectForm](submit_url='/api/forms/select'),
94+
c.ModelForm(model=SelectForm, submit_url='/api/forms/select'),
9595
]
9696
case 'big':
9797
return [
9898
c.Heading(text='Large Form', level=2),
9999
c.Paragraph(text='Form with a lot of fields.'),
100-
c.ModelForm[BigModel](submit_url='/api/forms/big'),
100+
c.ModelForm(model=BigModel, submit_url='/api/forms/big'),
101101
]
102102
case _:
103103
raise ValueError(f'Invalid kind {kind!r}')

demo/tables.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ def cities_view(page: int = 1, country: str | None = None) -> list[AnyComponent]
5858
filter_form_initial['country'] = {'value': country, 'label': country_name}
5959
return demo_page(
6060
*tabs(),
61-
c.ModelForm[FilterForm](
61+
c.ModelForm(
62+
model=FilterForm,
6263
submit_url='.',
6364
initial=filter_form_initial,
6465
method='GOTO',
6566
submit_on_change=True,
6667
display_mode='inline',
6768
),
68-
c.Table[City](
69+
c.Table(
6970
data=cities[(page - 1) * page_size : page * page_size],
71+
data_model=City,
7072
columns=[
7173
DisplayLookup(field='city', on_click=GoToEvent(url='./{id}'), table_width_percent=33),
7274
DisplayLookup(field='country', table_width_percent=33),
@@ -107,7 +109,7 @@ class User(BaseModel):
107109
def users_view() -> list[AnyComponent]:
108110
return demo_page(
109111
*tabs(),
110-
c.Table[User](
112+
c.Table(
111113
data=users,
112114
columns=[
113115
DisplayLookup(field='name', on_click=GoToEvent(url='/table/users/{id}/')),

0 commit comments

Comments
 (0)