Skip to content

Latest commit

 

History

History
359 lines (292 loc) · 20.3 KB

CHANGELOG.md

File metadata and controls

359 lines (292 loc) · 20.3 KB

Changelog

vNext

  • refactor auth middleware for supporting bearer, cookie and query. loco-rs#560
  • SeaORM upgraded: rc1 -> rc4. loco-rs#585
  • Adding Cache to app content. loco-rs#570
  • Apply a layer to a specific handler using layer method. loco-rs#554
  • Add the debug macro to the templates to improve the errors. loco-rs#547
  • Opentelemetry initializer. loco-rs#531
  • Refactor auth middleware for supporting bearer, cookie and query loco-rs#560
  • Add redirect response loco-rs#563
  • Breaking changes Adding a custom claims Option<serde_json::Value> to the UserClaims struct (type changed). loco-rs#578
  • Breaking changes Refactored DSL and Pagination: namespace changes. loco-rs#566
    • Replaced model::query::dsl:: with model::query.
    • Replaced model::query::exec::paginate with model::query::paginate.
    • Updated the PaginatedResponse struct. Refer to its usage example here.
  • Breaking changes When introducing the Cache system which is much more flexible than having just Redis, we now call the 'redis' member simply a 'queue' which indicates it should be used only for the internal queue and not as a general purpose cache. In the application configuration setting redis, change to queue. loco-rs#590
# before:
redis:
# after:
queue:
  • Breaking changes We have made a few parts of the context pluggable, such as the storage and new cache subsystems, this is why we decided to let you configure the context entirely before starting up your app. As a result, if you have a storage building hook code it should move to after_context, see example here. loco-rs#570

v0.4.0

  • Refactored model validation for better developer experience. Added a few traits and structs to loco::prelude for a smoother import story. Introducing Validatable:
impl Validatable for super::_entities::users::ActiveModel {
    fn validator(&self) -> Box<dyn Validate> {
        Box::new(Validator {
            name: self.name.as_ref().to_owned(),
            email: self.email.as_ref().to_owned(),
        })
    }
}

// now you can call `user.validate()` freely
  • Refactored type field mapping to be centralized. Now model, scaffold share the same field mapping, so no more gaps like loco-rs#513 (e.g. when calling loco generate model title:string the ability to map string into something useful in the code generation side) NOTE the _integer class of types are now just _int, e.g. big_int, so that it correlate with the int field name in a better way

  • Adding to to quiery dsl is_in and is_not_in. loco-rs#507

  • Added: in your configuration you can now use an initializers: section for initializer specific settings

    # Initializers Configuration
    initializers:
    # oauth2:
    #   authorization_code: # Authorization code grant type
    #     - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config.
    #       ... other fields
  • Docs: fix schema data types mapping. loco-rs#506

  • Let Result accept other errors. loco-rs#505

  • Allow trailing slashes in URIs by adding the NormalizePathLayer. loco-rs#481

  • BREAKING Move from Result<impl IntoResponse> to Result<Response>. This enables much greater flexibility building APIs, where with Result<Response> you mix and match response types based on custom logic (returning JSON and HTML/String in the same route).

  • Added: mime responders similar to respond_to in Rails:

  1. Use the Format extractor
  2. Match on respond_to
  3. Create different content for different response formats

The following route will always return JSON, unless explicitly asked for HTML with a Content-Type: text/html (or Accept: ) header:

pub async fn get_one(
    Format(respond_to): Format,
    Path(id): Path<i32>,
    State(ctx): State<AppContext>,
) -> Result<Response> {
    let item = load_item(&ctx, id).await?;
    match respond_to {
        RespondTo::Html => format::html(&format!("<html><body>{:?}</body></html>", item.title)),
        _ => format::json(item),
    }
}

0.3.2

  • Redisgin pagination. loco-rs#463
  • Wrap seaorm query and condition for common use cases. loco-rs#463
  • Adding to loco-extras initializer for extra or multiple db. loco-rs#471
  • Scaffold now supporting different templates such as API,HTML or htmx, this future is in beta.loco-rs#474
  • Fix generatore fields types + adding tests. loco-rs#459
  • Fix channel cors. loco-rs#430
  • Improve auth controller compatibility with frontend loco-rs#472

0.3.1

  • Breaking changes Upgrade sea-orm to v1.0.0-rc.1. loco-rs#420 Needs to update sea-orm crate to use v1.0.0-rc.1 version.
  • Implemented file upload support with versatile strategies. loco-rs#423
  • Create a loco_extra crate to share common basic implementations. loco-rs#425
  • Update shuttle deployment template to 0.38. loco-rs#422
  • Enhancement: Move the Serve to Hook flow with the ability to override default serve settings. loco-rs#418
  • Avoid cloning sea_query::ColumnDef. loco-rs#415
  • Allow required UUID type in a scaffold. loco-rs#408
  • Cover SqlxMySqlPoolConnection in db.rs. loco-rs#411
  • Update worker docs and change default worker mode. loco-rs#412
  • Added server-side view generation through a new ViewEngine infrastructure and Tera server-side templates: loco-rs#389
  • Added generate model --migration-only loco-rs#400
  • Add JSON to scaffold gen. loco-rs#396
  • Add --binding(-b) and --port(-b) to cargo loco start.loco-rs#402

0.2.3

v0.2.2

  • fix: public fields in mailer-op. e51b7e
  • fix: handle missing db permissions. e51b7e

v0.2.1

  • enable compression for CompressionLayer, not etag. loco-rs#356
  • Fix nullable JSONB column schema definition. loco-rs#357

v0.2.0

  • Add: Loco now has Initializers (see the docs). Initializers help you integrate infra into your app in a seamless way, as well as share pieces of setup code between your projects
  • Add: an init_logger hook in src/app.rs for those who want to take ownership of their logging and tracing stack.
  • Add: Return a JSON schema when payload json could not serialize to a struct. loco-rs#343
  • Init logger in cli.rs. loco-rs#338
  • Add: return JSON schema in panic HTTP layer. loco-rs#336
  • Add: JSON field support in model generation. loco-rs#327 loco-rs#332
  • Add: float support in model generation. loco-rs#317
  • Fix: conflicting idx definition on M:M migration. loco-rs#311
  • Add: Breaking changes Supply AppContext to routes Hook. Migration steps in src/app.rs:
// src/app.rs: add app context to routes function
impl Hooks for App {
  ...
  fn routes(_ctx: &AppContext) -> AppRoutes;
  ...
}
  • Add: Breaking changes change parameter type from &str to &Environment in src/app.rs
// src/app.rs: change parameter type for `environment` from `&str` to `&Environment`
impl Hooks for App {
    ...
    async fn boot(mode: StartMode, environment: &Environment) -> Result<BootResult> {
        create_app::<Self>(mode, environment).await
    }
    ...
  • Added: setting cookies:
format::render()
    .cookies(&[
        cookie::Cookie::new("foo", "bar"),
        cookie::Cookie::new("baz", "qux"),
    ])?
    .etag("foobar")?
    .json(notes)

v0.1.9

middlewares:
  compression:
    enable: true
  • Create a new Database from the CLI. loco-rs#223
  • Validate if seaorm CLI is installed before running cargo loco db entities and show a better error to the user. loco-rs#212
  • Adding to saas and rest-api` starters a redis and DB in GitHub action workflow to allow users work with github action out of the box. loco-rs#215
  • Adding the app name and the environment to the DB name when creating a new starter. loco-rs#216
  • Fix generator when users adding a created_at or update_at fields. loco-rs#214
  • Add: format::render which allows a builder-like formatting, including setting etag and ad-hoc headers
  • Add: Etag middleware, enabled by default in starter projects. Once you set an Etag it will check for cache headers and return 304 if needed. To enable etag in your existing project:
#...
  middlewares:
    etag:
      enable: true

usage:

  format::render()
      .etag("foobar")?
      .json(Entity::find().all(&ctx.db).await?)

Authentication: Added API Token Authentication!

  • See loco-rs#217 Now when you generate a saas starter or rest api starter you will get additional authentication methods for free:

  • Added: authentication added -- api authentication where each user has an API token in the schema, and you can authenticate with Bearer against that user.

  • Added: authentication added -- JWTWithUser extractor, which is a convenience for resolving the authenticated JWT claims into a current user from database

migrating an existing codebase

Add the following to your generated src/models/user.rs:

#[async_trait]
impl Authenticable for super::_entities::users::Model {
    async fn find_by_api_key(db: &DatabaseConnection, api_key: &str) -> ModelResult<Self> {
        let user = users::Entity::find()
            .filter(users::Column::ApiKey.eq(api_key))
            .one(db)
            .await?;
        user.ok_or_else(|| ModelError::EntityNotFound)
    }

    async fn find_by_claims_key(db: &DatabaseConnection, claims_key: &str) -> ModelResult<Self> {
        super::_entities::users::Model::find_by_pid(db, claims_key).await
    }
}

Update imports in this file to include model::Authenticable:

use loco_rs::{
    auth, hash,
    model::{Authenticable, ModelError, ModelResult},
    validation,
    validator::Validate,
};

v0.1.8

  • Added: loco version for getting an operable version string containing logical crate version and git SHA if available: 0.3.0 (<git sha>)

To migrate to this behavior from earlier versions, it requires adding the following to your app.rs app hooks:

    fn app_version() -> String {
        format!(
            "{} ({})",
            env!("CARGO_PKG_VERSION"),
            option_env!("BUILD_SHA")
                .or(option_env!("GITHUB_SHA"))
                .unwrap_or("dev")
        )
    }

Reminder: loco --version will give you the current Loco framework which your app was built against and loco version gives you your app version.

  • Added: loco generate migration for adding ad-hoc migrations
  • Added: added support in model generator for many-to-many link table generation via loco generate model --link
  • Docs: added Migration section, added relations documentation 1:M, M:M
  • Adding .devcontainer to starter projects loco-rs#170
  • Braking changes: Adding Hooks::boot application. Migration steps:
    // Load boot::{create_app, BootResult, StartMode} from loco_rs lib
    // Load migration: use migration::Migrator; Only when using DB
    // Adding boot hook with the following code
    impl Hooks for App {
      ...
      async fn boot(mode: StartMode, environment: &str) -> Result<BootResult> {
        // With DB:
        create_app::<Self, Migrator>(mode, environment).await
        // Without DB:
        create_app::<Self>(mode, environment).await
      }
      ...
    }

v0.1.7

  • Added pretty backtraces loco-rs#41
  • adding tests for note requests loco-rs#156
  • Define the min rust version the loco can run loco-rs#164
  • Added cargo loco doctor cli command for validate and diagnose configurations. loco-rs#145
  • Added ability to specify settings: in config files, which are available in context
  • Adding compilation mode in the banner. loco-rs#127
  • Support shuttle deployment generator. loco-rs#124
  • Adding a static asset middleware which allows to serve static folder/data. Enable this section in config. loco-rs#134
     static:
        enable: true
        # ensure that both the folder.path and fallback file path are existence.
        must_exist: true
        folder: 
          uri: "/assets"
          path: "frontend/dist"        
        fallback: "frontend/dist/index.html" 
  • fix: loco generate request test template. loco-rs#133
  • Improve docker deployment generator. loco-rs#131

v0.1.6

  • refactor: local settings are now <env>.local.yaml and available for all environments, for example you can add a local test.local.yaml and development.local.yaml
  • refactor: removed config-rs and now doing config loading by ourselves.
  • fix: email template rendering will not escape URLs
  • Config with variables: It is now possible to use tera templates in config YAML files

Example of pulling a port from environment:

server:
  port: {{ get_env(name="NODE_PORT", default=3000) }}

It is possible to use any tera templating constructs such as loops, conditionals, etc. inside YAML configuration files.

  • Mailer: expose stub in non-test

  • Hooks::before_run with a default blank implementation. You can now code some custom loading of resources or other things before the app runs

  • an LLM inference example, text generation in Rust, using an API (examples/inference)

  • Loco starters version & create release script loco-rs#110

  • Configure Cors middleware loco-rs#114

  • Hooks::after_routes Invoke this function after the Loco routers have been constructed. This function enables you to configure custom Axum logics, such as layers, that are compatible with Axum. loco-rs#114

  • Adding docker deployment generator loco-rs#119

DOCS:

  • Remove duplicated docs in auth section
  • FAQ docs: loco-rs#116

ENHANCEMENTS:

0.1.5

NEW FEATURES

ENHANCEMENTS: