litestar-vite 0.2.7__py3-none-any.whl → 0.2.9__py3-none-any.whl

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.

Potentially problematic release.


This version of litestar-vite might be problematic. Click here for more details.

@@ -18,6 +18,7 @@ from litestar.exceptions.responses import (
18
18
  )
19
19
  from litestar.plugins.flash import flash
20
20
  from litestar.repository.exceptions import (
21
+ ConflictError, # pyright: ignore[reportUnknownVariableType,reportAttributeAccessIssue]
21
22
  NotFoundError, # pyright: ignore[reportUnknownVariableType,reportAttributeAccessIssue]
22
23
  RepositoryError, # pyright: ignore[reportUnknownVariableType,reportAttributeAccessIssue]
23
24
  )
@@ -47,13 +48,14 @@ class _HTTPConflictException(HTTPException):
47
48
  def exception_to_http_response(request: Request[UserT, AuthT, StateT], exc: Exception) -> Response[Any]:
48
49
  """Handler for all exceptions subclassed from HTTPException."""
49
50
  inertia_enabled = getattr(request, "inertia_enabled", False) or getattr(request, "is_inertia", False)
50
- if isinstance(exc, NotFoundError):
51
- http_exc = NotFoundException
52
- elif isinstance(exc, RepositoryError):
53
- http_exc = _HTTPConflictException # type: ignore[assignment]
54
- else:
55
- http_exc = InternalServerException # type: ignore[assignment]
51
+
56
52
  if not inertia_enabled:
53
+ if isinstance(exc, NotFoundError):
54
+ http_exc = NotFoundException
55
+ elif isinstance(exc, (RepositoryError, ConflictError)):
56
+ http_exc = _HTTPConflictException # type: ignore[assignment]
57
+ else:
58
+ http_exc = InternalServerException # type: ignore[assignment]
57
59
  if request.app.debug and http_exc not in (PermissionDeniedException, NotFoundError):
58
60
  return cast("Response[Any]", create_debug_response(request, exc))
59
61
  return cast("Response[Any]", create_exception_response(request, http_exc(detail=str(exc.__cause__))))
@@ -88,16 +90,13 @@ def create_inertia_exception_response(request: Request[UserT, AuthT, StateT], ex
88
90
  return InertiaBack(request)
89
91
  if isinstance(exc, PermissionDeniedException):
90
92
  return InertiaBack(request)
91
- if status_code == HTTP_401_UNAUTHORIZED or isinstance(exc, NotAuthorizedException):
92
- if (
93
- inertia_plugin.config.redirect_unauthorized_to is not None
94
- and str(request.url) != inertia_plugin.config.redirect_unauthorized_to
95
- ):
96
- return InertiaRedirect(request, redirect_to=inertia_plugin.config.redirect_unauthorized_to)
97
- if str(request.url) != inertia_plugin.config.redirect_unauthorized_to:
98
- return InertiaResponse[Any](
99
- media_type=preferred_type,
100
- content=content,
101
- status_code=status_code,
102
- )
103
- return InertiaBack(request)
93
+ if (status_code == HTTP_401_UNAUTHORIZED or isinstance(exc, NotAuthorizedException)) and (
94
+ inertia_plugin.config.redirect_unauthorized_to is not None
95
+ and str(request.url) != inertia_plugin.config.redirect_unauthorized_to
96
+ ):
97
+ return InertiaRedirect(request, redirect_to=inertia_plugin.config.redirect_unauthorized_to)
98
+ return InertiaResponse[Any](
99
+ media_type=preferred_type,
100
+ content=content,
101
+ status_code=status_code,
102
+ )
@@ -114,3 +114,13 @@ class InertiaRequest(Request[UserT, AuthT, StateT]):
114
114
  def inertia_enabled(self) -> bool:
115
115
  """True if the route handler contains an inertia enabled configuration."""
116
116
  return bool(self.inertia.route_component is not None)
117
+
118
+ @property
119
+ def is_partial_render(self) -> bool:
120
+ """True if the route handler contains an inertia enabled configuration."""
121
+ return self.inertia.is_partial_render
122
+
123
+ @property
124
+ def partial_keys(self) -> set[str]:
125
+ """True if the route handler contains an inertia enabled configuration."""
126
+ return set(self.inertia.partial_keys)
@@ -33,7 +33,6 @@ if TYPE_CHECKING:
33
33
  from litestar.connection.base import AuthT, StateT, UserT
34
34
  from litestar.types import ResponseCookies, ResponseHeaders, TypeEncodersMap
35
35
 
36
- from litestar_vite.inertia.request import InertiaRequest
37
36
  from litestar_vite.inertia.routes import Routes
38
37
 
39
38
  from .plugin import InertiaPlugin
@@ -65,7 +64,10 @@ def error(
65
64
  connection.logger.warning(msg)
66
65
 
67
66
 
68
- def get_shared_props(request: ASGIConnection[Any, Any, Any, Any]) -> Dict[str, Any]: # noqa: UP006
67
+ def get_shared_props(
68
+ request: ASGIConnection[Any, Any, Any, Any],
69
+ partial_data: set[str] | None = None,
70
+ ) -> Dict[str, Any]: # noqa: UP006
69
71
  """Return shared session props for a request
70
72
 
71
73
 
@@ -217,9 +219,11 @@ class InertiaResponse(Response[T]):
217
219
  removal_in="3.0.0",
218
220
  alternative="request.app",
219
221
  )
220
- inertia_enabled = getattr(request, "inertia_enabled", False) or getattr(request, "is_inertia", False)
221
- is_inertia = getattr(request, "is_inertia", False)
222
-
222
+ inertia_enabled = cast(
223
+ "bool",
224
+ getattr(request, "inertia_enabled", False) or getattr(request, "is_inertia", False),
225
+ )
226
+ is_inertia = cast("bool", getattr(request, "is_inertia", False))
223
227
  headers = {**headers, **self.headers} if headers is not None else self.headers
224
228
  cookies = self.cookies if cookies is None else itertools.chain(self.cookies, cookies)
225
229
  type_encoders = (
@@ -238,15 +242,18 @@ class InertiaResponse(Response[T]):
238
242
  media_type=media_type,
239
243
  status_code=self.status_code or status_code,
240
244
  )
245
+ is_partial_render = cast("bool", getattr(request, "is_partial_render", False))
246
+ partial_keys = cast("set[str]", getattr(request, "partial_keys", {}))
241
247
  vite_plugin = request.app.plugins.get(VitePlugin)
242
248
  template_engine = vite_plugin.template_config.to_engine()
243
249
  headers.update(
244
250
  {"Vary": "Accept", **get_headers(InertiaHeaderType(enabled=True))},
245
251
  )
246
- shared_props = get_shared_props(request)
252
+ shared_props = get_shared_props(request, partial_data=partial_keys if is_partial_render else None)
253
+ shared_props["content"] = self.content
247
254
  page_props = PageProps[T](
248
255
  component=request.inertia.route_component, # type: ignore[attr-defined] # pyright: ignore[reportUnknownArgumentType,reportUnknownMemberType,reportAttributeAccessIssue]
249
- props={"content": self.content, **shared_props}, # pyright: ignore[reportArgumentType]
256
+ props=shared_props, # pyright: ignore[reportArgumentType]
250
257
  version=template_engine.asset_loader.version_id,
251
258
  url=request.url.path,
252
259
  )
@@ -317,9 +324,9 @@ class InertiaExternalRedirect(Response[Any]):
317
324
  and pass redirect url.
318
325
  """
319
326
  super().__init__(
320
- content=kwargs.get("content", ""),
327
+ content=b"",
321
328
  status_code=HTTP_409_CONFLICT,
322
- headers={"X-Inertia": "true", "X-Inertia-Location": quote(redirect_to, safe="/#%[]=:;$&()+,!?*@'~")},
329
+ headers={"X-Inertia-Location": quote(redirect_to, safe="/#%[]=:;$&()+,!?*@'~")},
323
330
  cookies=request.cookies,
324
331
  **kwargs,
325
332
  )
@@ -337,7 +344,7 @@ class InertiaRedirect(Redirect):
337
344
  """Initialize external redirect, Set status code to 409 (required by Inertia),
338
345
  and pass redirect url.
339
346
  """
340
- referer = urlparse(request.headers.get("referer", str(request.base_url)))
347
+ referer = urlparse(request.headers.get("Referer", str(request.base_url)))
341
348
  redirect_to = urlunparse(urlparse(redirect_to)._replace(scheme=referer.scheme))
342
349
  super().__init__(
343
350
  path=redirect_to,
@@ -358,12 +365,8 @@ class InertiaBack(Redirect):
358
365
  """Initialize external redirect, Set status code to 409 (required by Inertia),
359
366
  and pass redirect url.
360
367
  """
361
- referer = request.headers.get("referer", str(request.base_url))
362
- inertia_enabled = getattr(request, "inertia_enabled", False) or getattr(request, "is_inertia", False)
363
- if inertia_enabled:
364
- referer = cast("InertiaRequest[Any, Any, Any]", request).inertia.referer or referer
365
368
  super().__init__(
366
- path=request.headers.get("referer", str(request.base_url)),
369
+ path=request.headers.get("Referer", str(request.base_url)),
367
370
  status_code=HTTP_307_TEMPORARY_REDIRECT if request.method == "GET" else HTTP_303_SEE_OTHER,
368
371
  cookies=request.cookies,
369
372
  **kwargs,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: litestar-vite
3
- Version: 0.2.7
3
+ Version: 0.2.9
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -10,11 +10,11 @@ litestar_vite/template_engine.py,sha256=ffC4KPtUUNkuC0tJ0bD1Bu7c8lE33vKP0US1fWUY
10
10
  litestar_vite/inertia/__init__.py,sha256=RLeCWGHsHyBPpUjSXRhYOQlTh9cG33Q115zGH89M6XE,863
11
11
  litestar_vite/inertia/_utils.py,sha256=ijO9Lgka7ZPIAHkby9szbTGoSg0nDShC2bqWT9cDxi0,1956
12
12
  litestar_vite/inertia/config.py,sha256=ziEO-xQ5SoE7niri39PMXYgieM94Yf0y4BCFyaMs6P0,1125
13
- litestar_vite/inertia/exception_handler.py,sha256=S-55sCQ6zLSMICo8l9co0RbT5Dr_TzJlRQBg7YpsRXM,4774
13
+ litestar_vite/inertia/exception_handler.py,sha256=qqhVmosjlGE4gs03AYF1kaNtPdhqGzWHYHjrHxfm900,4735
14
14
  litestar_vite/inertia/middleware.py,sha256=NEDcAoT7GMWA9hEGvANZ3MG5_p3MmZX57RF95T71les,1716
15
15
  litestar_vite/inertia/plugin.py,sha256=ebAG9XnDBahttuc7WIUgBd3o_Ys8MdPS273LPNs5H8A,2344
16
- litestar_vite/inertia/request.py,sha256=hk8m1pmDiMbWhVurRDHfDPD24nMHp56JzUKV6SBDeqA,3665
17
- litestar_vite/inertia/response.py,sha256=XcAXmQ6Ex_XZVc5UF9ULxzOgJ2EKlivJKKVm_EPAebw,15985
16
+ litestar_vite/inertia/request.py,sha256=5IWZLkQxIOuvYA7RRW5uQZD9skjqr4lEbM4V7HCzCnY,4034
17
+ litestar_vite/inertia/response.py,sha256=Au7jQnqjY3wJAHNmiwteCZxKTKGCpnkjMTSzBVRwkXs,15927
18
18
  litestar_vite/inertia/routes.py,sha256=QksJm2RUfL-WbuhOieYnPXXWO5GYnPtmsYEm6Ef8Yeo,1782
19
19
  litestar_vite/inertia/types.py,sha256=tLp0pm1N__hcWC875khf6wH1nuFlKS9-VjDqgsRkXnw,702
20
20
  litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -24,7 +24,7 @@ litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYu
24
24
  litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
26
26
  litestar_vite/templates/vite.config.ts.j2,sha256=FZ4OJaB8Kjby_nlx4_LCP8eCe1LRi8kW2GspCiVMfDY,1115
27
- litestar_vite-0.2.7.dist-info/METADATA,sha256=tMy61p67HGfR89sAeQECdLdltWx1B767mzjw_emFujU,6180
28
- litestar_vite-0.2.7.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
29
- litestar_vite-0.2.7.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
- litestar_vite-0.2.7.dist-info/RECORD,,
27
+ litestar_vite-0.2.9.dist-info/METADATA,sha256=Z32djOlmFMe6ZeWKPrAv0VjDeuklsutMmDEcBYoO3bU,6180
28
+ litestar_vite-0.2.9.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
29
+ litestar_vite-0.2.9.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
+ litestar_vite-0.2.9.dist-info/RECORD,,