diff --git a/.coverage b/.coverage index 98b3c14..929cd29 100644 Binary files a/.coverage and b/.coverage differ diff --git a/CHANGELOG.md b/CHANGELOG.md index 229ee32..d715cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,24 +1,40 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.6] - 2024-07-17 + +- Cache vite manifest content +- Better type vite manifest +- Allow for multiple css files to be in the manifest file +- Deprecate use_typescript in favour of entrypoint_filename + - Will be removed in 1.0.0 +- Introduce root_directory to InertiaConfig instead of assuming it +- Introduce assets_prefix to InertiaConfig instead of assuming it + +## [0.1.5] - 2024-07-17 + +- Introduce new dev dependency: BeautifulSoup +- Use it instead of manual parsing as this is more reliable and less painful + ## [0.1.4] - 2024-05-31 -* Handle better JSONification of Pydantic models - * Use `json.loads(model.model_dump.json())` rather than `model.model_dump()` +- Handle better JSONification of Pydantic models + - Use `json.loads(model.model_dump.json())` rather than `model.model_dump()` To avoid issues with some common field types (UUID, datetime, etc.) -* Expose a `_render_json` method on inertia to allow easier overriding. +- Expose a `_render_json` method on inertia to allow easier overriding. ## [0.1.3] - 2024-05-08 -* Bump FastAPI version from 0.110.2 to 0.111.0 +- Bump FastAPI version from 0.110.2 to 0.111.0 ## [0.1.2] - 2024-04-23 -* Update `README.md` and available versions +- Update `README.md` and available versions ## [0.1.1] - 2024-04-23 -* Initial release. +- Initial release. diff --git a/README.md b/README.md index 1f7b5e6..a79cb17 100644 --- a/README.md +++ b/README.md @@ -34,22 +34,23 @@ pip install fastapi-inertia You can configure the adapter by passing a `InertiaConfig` object to the `Inertia` class. The following options are available: -| key | default | options | description | -| ------------------- | -------------------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -| environment | development | development,production | The environment to use | -| version | 1.0.0 | Any valid string | The version of your server | -| json_encoder | InertiaJsonEncoder | Any class that extends json.JSONEncoder | The JSON encoder used to encode page data when HTML is returned | -| manifest_json_path | ./dist/.vite/manifest.json | Any valid path | The path to the manifest.json file. Needed in production | -| dev_url | http://localhost:5173 | Any valid url | The URL to the development server | -| ssr_url | http://localhost:13714 | Any valid url | The URL to the SSR server | -| ssr_enabled | False | True,False | Whether to [enable SSR](#enable-ssr). You need to install the `requests` package, to have set the manifest_json_path and started the SSR server | -| root_directory | src | Any valid path | The directory in which is located the javascript code in your frontend. Will be used to find the relevant files in your manifest.json. | -| entrypoint_filename | main.js | Any valid file | The entrypoint for you frontend. Will be used to find the relevant files in your manifest.json. | -| use_typescript | False | True,False | Whether to use TypeScript | -| use_flash_messages | False | True,False | Whether to use [flash messages](#flash-messages). You need to use Starlette's SessionMiddleware to use this feature | -| flash_message_key | messages | Any valid string | The key to use for [flash errors](#flash-errors) | -| use_flash_errors | False | True,False | Whether to use flash errors | -| flash_error_key | errors | Any valid string | The key to use for flash errors | +| key | default | options | description | +| ------------------- | ---------------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | +| environment | development | development,production | The environment to use | +| version | 1.0.0 | Any valid string | The version of your server | +| json_encoder | InertiaJsonEncoder | Any class that extends json.JSONEncoder | The JSON encoder used to encode page data when HTML is returned | +| manifest_json_path | "" | Any valid path | The path to the manifest.json file. Needed in production | +| dev_url | http://localhost:5173 | Any valid url | The URL to the development server | +| ssr_url | http://localhost:13714 | Any valid url | The URL to the SSR server | +| ssr_enabled | False | True,False | Whether to [enable SSR](#enable-ssr). You need to install the `requests` package, to have set the manifest_json_path and started the SSR server | +| root_directory | src | Any valid path | The directory in which is located the javascript code in your frontend. Will be used to find the relevant files in your manifest.json. | +| entrypoint_filename | main.js | Any valid file | The entrypoint for you frontend. Will be used to find the relevant files in your manifest.json. | +| assets_prefix | "" | Any valid string | An optional prefix for your assets. Will prefix the links generated from the assets mentioned in manifest.json. | +| use_typescript | False | True,False | Whether to use TypeScript | +| use_flash_messages | False | True,False | Whether to use [flash messages](#flash-messages). You need to use Starlette's SessionMiddleware to use this feature | +| flash_message_key | messages | Any valid string | The key to use for [flash errors](#flash-errors) | +| use_flash_errors | False | True,False | Whether to use flash errors | +| flash_error_key | errors | Any valid string | The key to use for flash errors | ## Examples diff --git a/inertia/config.py b/inertia/config.py index 7309085..f8e02f6 100644 --- a/inertia/config.py +++ b/inertia/config.py @@ -1,6 +1,7 @@ from functools import lru_cache import json -from typing import Literal, Type, Optional, TypedDict, Dict, cast +from typing import Literal, Type, Optional, TypedDict, Dict, Union, cast +import warnings from json import JSONEncoder from .utils import InertiaJsonEncoder from dataclasses import dataclass @@ -18,7 +19,7 @@ class InertiaConfig: dev_url: str = "http://localhost:5173" ssr_url: str = "http://localhost:13714" ssr_enabled: bool = False - manifest_json_path: str = "./dist/.vite/manifest.json" + manifest_json_path: str = "" root_directory: str = "src" entrypoint_filename: str = "main.js" use_flash_messages: bool = False @@ -26,6 +27,16 @@ class InertiaConfig: flash_message_key: str = "messages" flash_error_key: str = "errors" assets_prefix: str = "" + use_typescript: Union[bool, None] = None + + def __post_init__(self) -> None: + if self.use_typescript is not None: + warnings.warn( + "use_typescript is deprecated: Please use entrypoint_filename instead. It will be removed in 1.0.0", + DeprecationWarning, + stacklevel=2, + ) + self.entrypoint_filename = "main.ts" if self.use_typescript else "main.js" class ViteManifestChunk(TypedDict):