Skip to content

Commit

Permalink
Merge branch 'master' into ilike-dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
yinho999 authored May 28, 2024
2 parents f04eaf5 + f6a21ea commit 4e76805
Show file tree
Hide file tree
Showing 54 changed files with 1,993 additions and 1,041 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: docs

on:
push:
branches:
- master
pull_request:

env:
RUST_TOOLCHAIN: stable
TOOLCHAIN_PROFILE: minimal

jobs:
check:
name: Check
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout the code
uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: ${{ env.TOOLCHAIN_PROFILE }}
toolchain: ${{ env.RUST_TOOLCHAIN }}
override: true
components: rustfmt
- run: cargo install snipdoc
- run: snipdoc check


18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# Changelog

## vNext
* refactor auth middleware for supporting bearer, cookie and query. [https://github.com/loco-rs/loco/pull/560](https://github.com/loco-rs/loco/pull/560)
* SeaORM upgraded: `rc1` -> `rc4`. [https://github.com/loco-rs/loco/pull/585](https://github.com/loco-rs/loco/pull/585)
* Adding Cache to app content. [https://github.com/loco-rs/loco/pull/570](https://github.com/loco-rs/loco/pull/570)
* Apply a layer to a specific handler using `layer` method. [https://github.com/loco-rs/loco/pull/554](https://github.com/loco-rs/loco/pull/554)
* Add the debug macro to the templates to improve the errors. [https://github.com/loco-rs/loco/pull/547](https://github.com/loco-rs/loco/pull/547)
* Opentelemetry initializer. [https://github.com/loco-rs/loco/pull/531](https://github.com/loco-rs/loco/pull/531)
* **Braking changes** Refactored DSL and Pagination. [https://github.com/loco-rs/loco/pull/566](https://github.com/loco-rs/loco/pull/566)
* Refactor auth middleware for supporting bearer, cookie and query [https://github.com/loco-rs/loco/pull/560](https://github.com/loco-rs/loco/pull/560)
* Add redirect response [https://github.com/loco-rs/loco/pull/563](https://github.com/loco-rs/loco/pull/563)
* **Breaking changes** Adding a custom claims `Option<serde_json::Value>` to the `UserClaims` struct (type changed). [https://github.com/loco-rs/loco/pull/578](https://github.com/loco-rs/loco/pull/578)
* **Breaking changes** Refactored DSL and Pagination: namespace changes. [https://github.com/loco-rs/loco/pull/566](https://github.com/loco-rs/loco/pull/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](https://github.com/loco-rs/loco/blob/master/examples/demo/src/views/notes.rs#L29).
* Refactor auth middleware for supporting bearer, cookie and query [https://github.com/loco-rs/loco/pull/560](https://github.com/loco-rs/loco/pull/560)
* Add redirect response [https://github.com/loco-rs/loco/pull/563](https://github.com/loco-rs/loco/pull/563)
* **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`. [https://github.com/loco-rs/loco/pull/590](https://github.com/loco-rs/loco/pull/590)
```yaml
# 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](https://github.com/loco-rs/loco/pull/570/files#diff-5534e8826fb82e5c7f2587d270a51b48009341e79889d1504e6b63b2f0b652bdR83). [https://github.com/loco-rs/loco/pull/570](https://github.com/loco-rs/loco/pull/570)

## v0.4.0

Expand Down
16 changes: 13 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ In case of cli changes we snapshot the binary commands. in case of changes run t
LOCO_CI_MODE=true TRYCMD=overwrite cargo test
```

## Running Docs website
The documentation website based on [zola](https://www.getzola.org/), and you can see the docs [here](./docs-site/).
then cd to `docs-site` and run `zola serve`
## Docs

The documentation consists of two main components:

+ The [loco.rs website](https://loco.rs) with its source code available [here](./docs-site/).
+ RustDocs.

To reduce duplication in documentation and examples, we use [snipdoc](https://github.com/kaplanelad/snipdoc). As part of our CI process, we ensure that the documentation remains consistent.

Updating the Documentation
+ Download [snipdoc](https://github.com/kaplanelad/snipdoc).
+ Create the snippet in the [yaml file](./snipdoc.yml) or inline the code.
+ Run `snipdoc run`.


## Open A Pull Request
Expand Down
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rust-version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["auth_jwt", "cli", "with-db"]
default = ["auth_jwt", "cli", "with-db", "cache_inmem"]
auth_jwt = ["dep:jsonwebtoken"]
cli = ["dep:clap"]
testing = ["dep:axum-test"]
Expand All @@ -33,6 +33,8 @@ all_storage = ["storage_aws_s3", "storage_azure", "storage_gcp"]
storage_aws_s3 = ["object_store/aws"]
storage_azure = ["object_store/azure"]
storage_gcp = ["object_store/gcp"]
# Cache feature
cache_inmem = ["dep:moka"]

[dependencies]

Expand All @@ -44,7 +46,7 @@ clap = { version = "4.4.7", features = ["derive"], optional = true }
colored = "2"


sea-orm = { version = "1.0.0-rc.1", features = [
sea-orm = { version = "1.0.0-rc.4", features = [
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
"runtime-tokio-rustls",
Expand Down Expand Up @@ -119,6 +121,9 @@ socketioxide = { version = "0.10.0", features = ["state"], optional = true }
# File Upload
object_store = { version = "0.9.0", default-features = false }

# cache
moka = { version = "0.12.7", features = ["sync"], optional = true }

[workspace.dependencies]
async-trait = { version = "0.1.74" }
axum = { version = "0.7.1", features = ["macros"] }
Expand All @@ -136,7 +141,7 @@ tower-http = { version = "0.5.0", features = [

[dependencies.sea-orm-migration]
optional = true
version = "1.0.0-rc.1"
version = "1.0.0-rc.4"
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
Expand Down
123 changes: 61 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,102 @@
<div align="center">

![Loco.rs](https://github.com/loco-rs/loco/assets/83390/992d215a-3cd3-42ee-a1c7-de9fd25a5bac)
[![Current Crates.io Version](https://img.shields.io/crates/v/loco-rs.svg)](https://crates.io/crates/loco-rs)
[![Discord channel](https://img.shields.io/badge/discord-Join-us)](https://discord.gg/fTvyBzwKS8)
<img src="https://github.com/loco-rs/loco/assets/83390/992d215a-3cd3-42ee-a1c7-de9fd25a5bac"/>

# Welcome to Loco!
<h1>Loco</h1>

<a href="https://loco.rs">https://loco.rs</a>
<h3>
<!-- <snip id="description" inject_from="yaml"> -->
🚂 Loco is Rust on Rails.
<!--</snip> -->
</h3>

[![crate](https://img.shields.io/crates/v/loco-rs.svg)](https://crates.io/crates/loco-rs)
[![docs](https://docs.rs/loco-rs/badge.svg)](https://docs.rs/loco-rs)
[![Discord channel](https://img.shields.io/badge/discord-Join-us)](https://discord.gg/fTvyBzwKS8)

Loco is "Rust on Rails".
</div>

Loco is strongly inspired by Rails. If you know Rails and Rust, you'll feel at home. If you only know Rails and new to Rust, you'll find Loco refreshing. We do not assume you know Rails.
# Loco

#### Loco is strongly inspired by Rails. If you know Rails and Rust, you'll feel at home. If you only know Rails and new to Rust, you'll find Loco refreshing. We do not assume you know Rails.

## Quick Start

## Quick Start
<!-- <snip id="quick-installation-command" inject_from="yaml"> -->
```sh
$ cargo install loco-cli
cargo install loco-cli
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->

Now you can create your new app (choose "SaaS app").
Now you can create your new app (choose "`SaaS` app").

<!-- <snip id="loco-cli-new-from-template" inject_from="yaml"> -->
```sh
$ loco new
❯ App name? [myapp]:
SaaS app (with DB and user auth)
Stateless service (minimal, no db)
loco new
❯ App name? · myapp
✔ ❯ What would you like to build? · SaaS app (with DB and user auth)

🚂 Loco app generated successfully in:
myapp
```
<!-- </snip> -->

To configure a database , please run a local postgres database with <code>loco:loco</code> and a db named <code>[insert app]_development</code>.

To configure a database , please run a local postgres database with loco:loco and a db named [insert app]_development.
<!-- <snip id="postgres-run-docker-command" inject_from="yaml"> -->
```sh
docker run -d -p 5432:5432 \
-e POSTGRES_USER=loco \
-e POSTGRES_DB=myapp_development \
-e POSTGRES_PASSWORD="loco" \
postgres:15.3-alpine
```
$ docker run -d -p 5432:5432 -e POSTGRES_USER=loco -e POSTGRES_DB=myapp_development -e POSTGRES_PASSWORD="loco" postgres:15.3-alpine
```
<!-- </snip> -->


Now `cd` into your `myapp` and start your app:
A more advanced set of `docker-compose.yml` and `Dockerfiles` that include Redis and the `mailtutan` mailer are available for [each starter on GitHub](https://github.com/loco-rs/loco/blob/master/starters/saas/.devcontainer/docker-compose.yml).

```
$ cd myapp
$ cargo loco start
Finished dev [unoptimized + debuginfo] target(s) in 21.63s
Running `target/debug/myapp start`
:
:
:
Now `cd` into your `myapp` and start your app:

controller/app_routes.rs:203: [Middleware] Adding log trace id
<!-- <snip id="starting-the-server-command-with-output" inject_from="yaml"> -->
```sh
$ cargo loco start

▄ ▀
▀ ▄
▀ ▄
▄ ▀ ▄ ▄ ▄▀
▄ ▀▄▄
▄ ▀ ▀ ▀▄▀█▄
▀█▄
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▀▀█
██████ █████ ███ █████ ███ █████ ███ ▀█
██████ █████ ███ █████ ▀▀▀ █████ ███ ▄█▄
██████ █████ ███ █████ █████ ███ ████▄
██████ █████ ███ █████ ▄▄▄ █████ ███ █████
██████ █████ ███ ████ ███ █████ ███ ████▀
▀▀▀██▄ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ██▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
started on port 3000
██████ █████ ███ █████ ███ █████ ███ ▀█
██████ █████ ███ █████ ▀▀▀ █████ ███ ▄█▄
██████ █████ ███ █████ █████ ███ ████▄
██████ █████ ███ █████ ▄▄▄ █████ ███ █████
██████ █████ ███ ████ ███ █████ ███ ████▀
▀▀▀██▄ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ██▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
https://loco.rs

listening on port 3000
```
<!-- </snip> -->

## Project Status

Loco is feature complete, but features are still being added rapidly.

### What can you build?

- Stateless APIs
- Complete SaaS products with user authentication
- Purpose-built services such as ML inference endpoints
- Full stack projects with separate frontend project integrated with Loco
- Hobby projects full-stack with backend and HTML frontend

### What's being done now?

- View [issues](https://github.com/loco-rs/loco/issues) for what we plan next and what we work on (you're welcome to submit PRs!)
- View [CHANGELOG](https://github.com/loco-rs/loco/blob/master/CHANGELOG.md) for what we already added
+ Stateless APIs
+ Complete `SaaS` products with user authentication
+ Purpose-built services such as ML inference endpoints
+ Full stack projects with separate frontend project integrated with Loco
+ Hobby projects full-stack with backend and HTML frontend

## Powered by Loco

* [SpectralOps](https://spectralops.io) - various services powered by Loco framework
* [Nativish](https://nativi.sh) - app backend powered by Loco framework

[open an issue to add yourself here](https://github.com/loco-rs/loco/issues)

+ [SpectralOps](https://spectralops.io) - various services powered by Loco
framework
+ [Nativish](https://nativi.sh) - app backend powered by Loco framework

## Contributors ✨

Thanks goes to these wonderful people:

<a href="https://github.com/loco-rs/loco/graphs/contributors">
<img src="https://contrib.rocks/image?repo=loco-rs/loco" />
</a>
</a>
1 change: 0 additions & 1 deletion docs-site/content/blog/frontend-website.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ server:
```
Now, run the Loco server again and you should see frontend app serving via Loco
```sh
$ cargo loco start
```
Expand Down
26 changes: 17 additions & 9 deletions docs-site/content/docs/getting-started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ flair =[]

Create your starter app:

```rust
$ cargo install loco-cli
$ loco new
< follow the guide >
<!-- <snip id="loco-cli-new-from-template" inject_from="yaml"> -->
```sh
❯ loco new
✔ ❯ App name? · myapp
✔ ❯ What would you like to build? · SaaS app (with DB and user auth)

🚂 Loco app generated successfully in:
myapp
```
<!-- </snip> -->

Now `cd` into your app, set up a convenience `rr` alias and try out the various commands:

<!-- <snip id="help-command" inject_from="yaml"> -->
```sh
cargo loco --help
```
$ cd myapp
$ cargo loco --help
```
<!-- </snip> -->

You can now drive your development through the CLI:

Expand All @@ -49,9 +55,11 @@ $ cargo test

To run you app, run:

<!-- <snip id="starting-the-server-command" inject_from="yaml"> -->
```sh
cargo loco start
```
$ cargo loco start
```
<!-- </snip> -->

## Background workers

Expand Down
26 changes: 11 additions & 15 deletions docs-site/content/docs/getting-started/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,23 @@ config/
```

To run the application using the 'qa' environment, execute the following command:

```
$ LOCO_ENV=qa cargo loco start
<!-- <snip id="starting-the-server-command-with-environment-env-var" inject_from="yaml"> -->
```sh
LOCO_ENV=qa cargo loco start
```
<!-- </snip> -->

## Settings

The configuration files contain knobs to set up your Loco app. You can also have your custom settings, with the `settings:` section.


```yaml
# in config/development.yaml
# add the `settings:` section
settings:
The configuration files contain knobs to set up your Loco app. You can also have your custom settings, with the `settings:` section. in `config/development.yaml` add the `settings:` section
<!-- <snip id="configuration-settings" inject_from="code" template="```yaml \n {snippet} \n ```"> -->
```yaml
settings:
allow_list:
- google.com
- apple.com

logger:
# ...
```
- apple.com
```
<!-- </snip> -->
These setting will appear in `ctx.config.settings` as `serde_json::Value`. You can create your strongly typed settings by adding a struct:

Expand Down
Loading

0 comments on commit 4e76805

Please sign in to comment.