Skip to content

Commit

Permalink
Merge branch 'master' into update-updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot authored Nov 9, 2024
2 parents 270f388 + 7966e66 commit fc82f3f
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 50 deletions.
59 changes: 35 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ 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", "cache_inmem", "bg_redis", "bg_pg"]
default = [
"auth_jwt",
"cli",
"with-db",
"cache_inmem",
"bg_redis",
"bg_pg",
"bg_sqlt",
]
auth_jwt = ["dep:jsonwebtoken"]
cli = ["dep:clap"]
testing = ["dep:axum-test"]
Expand All @@ -37,6 +45,7 @@ storage_gcp = ["object_store/gcp"]
cache_inmem = ["dep:moka"]
bg_redis = ["dep:rusty-sidekiq", "dep:bb8"]
bg_pg = ["dep:sqlx", "dep:ulid"]
bg_sqlt = ["dep:sqlx", "dep:ulid"]

[dependencies]
loco-gen = { version = "0.12.0", path = "./loco-gen" }
Expand All @@ -48,10 +57,10 @@ colored = "2"


sea-orm = { version = "1.1.0", features = [
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
"runtime-tokio-rustls",
"macros",
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
"runtime-tokio-rustls",
"macros",
], optional = true }

tokio = { version = "1.33.0", default-features = false }
Expand All @@ -75,10 +84,10 @@ fs-err = "2.11.0"
tera = "1.19.1"
heck = "0.4.0"
lettre = { version = "0.11.4", default-features = false, features = [
"builder",
"hostname",
"smtp-transport",
"tokio1-rustls-tls",
"builder",
"hostname",
"smtp-transport",
"tokio1-rustls-tls",
] }
include_dir = "0.7.3"
thiserror = { workspace = true }
Expand Down Expand Up @@ -125,9 +134,11 @@ moka = { version = "0.12.7", features = ["sync"], optional = true }
tokio-cron-scheduler = { version = "0.11.0", features = ["signal"] }
english-to-cron = { version = "0.1.2" }

# bg_sqlt: sqlite workers
# bg_pg: postgres workers
sqlx = { version = "0.8.2", default-features = false, features = [
"postgres",
"postgres",
"sqlite",
], optional = true }
ulid = { version = "1", optional = true }

Expand All @@ -147,26 +158,26 @@ async-trait = { version = "0.1.74" }
axum = { version = "0.7.5", features = ["macros"] }
tower = "0.4"
tower-http = { version = "0.6.1", features = [
"trace",
"catch-panic",
"timeout",
"add-extension",
"cors",
"fs",
"set-header",
"compression-full",
"trace",
"catch-panic",
"timeout",
"add-extension",
"cors",
"fs",
"set-header",
"compression-full",
] }

[dependencies.sea-orm-migration]
optional = true
version = "1.0.0"
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.
# e.g.
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
# 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.
# e.g.
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
]

[package.metadata.docs.rs]
Expand Down
14 changes: 7 additions & 7 deletions docs-site/content/docs/extras/pluggability.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ logger:

The most important knobs here are:

* `level` - your standard logging levels. Typically `debug` or `trace` in development. In production choose what you are used to.
* `pretty_backtrace` - provides clear, concise path to the line of code causing the error. use `true` in development and turn off in production. In cases where you are debugging things in production and need some extra hand, you can turn it on and then off when you're done.
* `level` - your standard logging levels. Typically `debug` or `trace` in development. In production, choose what you are used to.
* `pretty_backtrace` - provides a clear, concise path to the line of code causing the error. Use `true` in development and turn it off in production. In cases where you are debugging things in production and need some extra hand, you can turn it on and then off when you're done.

### Controller logging

Expand Down Expand Up @@ -92,7 +92,7 @@ Usually you can expect the following from errors:
Notes:

* An _error chain_ was experimented with, but provides little value in practice.
* Errors that an end user sees are a completely different thing. We strive to provide **minimal internal details** about an error for an end user when we know a user can't do anything about an error (e.g. "database offline error"), mostly it will be a generic "Inernal Server Error" on purpose -- for security reasons.
* Errors that an end user sees are a completely different thing. We strive to provide **minimal internal details** about an error for an end user when we know a user can't do anything about an error (e.g. "database offline error"), mostly it will be a generic "Internal Server Error" on purpose -- for security reasons.

### Producing errors

Expand Down Expand Up @@ -255,12 +255,12 @@ add [layers](https://docs.rs/tower/latest/tower/trait.Layer.html)
and [services](https://docs.rs/tower/latest/tower/trait.Service.html) as middleware to your routes and handlers.

Middleware is a way to add pre- and post-processing to your requests. This can be used for logging, authentication, rate
limiting, route specific processing, and more.
limiting, route-specific processing, and more.


### Source Code

`Loco`'s implementation of route middleware / layer is similar
`Loco`'s implementation of route middleware/layer is similar
to `axum`'s [`Router::layer`](https://github.com/tokio-rs/axum/blob/main/axum/src/routing/mod.rs#L275). You can
find the source code for middleware in
the [`src/controllers/routes`](https://github.com/loco-rs/loco/blob/master/src/controller/routes.rs) directory.
Expand Down Expand Up @@ -439,7 +439,7 @@ path. Then we are calling the inner service with the request.
In the Tower framework, before a service can be used to handle a request, it must be
checked for readiness
using the
poll_ready method. This method returns `Poll::Ready(Ok(()))` when the service is ready to process a request. If a
`poll_ready` method. This method returns `Poll::Ready(Ok(()))` when the service is ready to process a request. If a
service is not ready, it may return `Poll::Pending`, indicating that the caller should wait before sending a request.
This mechanism ensures that the service has the necessary resources or state to process the request efficiently and
correctly.
Expand All @@ -462,7 +462,7 @@ verified as ready. Here’s how it works:
- Replace the original with the clone: Use `std::mem::replace` to swap the original service with the clone. This
operation ensures that the service handler continues to hold a service instance.
- Use the original service to handle the request: Since the original service was already checked for readiness (via
poll_ready), it's safe to use it to handle the incoming request. The clone, now in the handler, will be the one
`poll_ready`), it's safe to use it to handle the incoming request. The clone, now in the handler, will be the one
checked for readiness next time.

This method ensures that each service instance used to handle requests is always the one that has been explicitly
Expand Down
6 changes: 3 additions & 3 deletions docs-site/content/docs/getting-started/tour/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ We have a base SaaS app with user authentication generated for us. Let's make it

<div class="infobox">

You can choose between generating an `api`, `html` or `htmx` scaffold using the required `-k` flag.
You can choose between generating an `api`, `html` or `htmx` scaffold using the respective `-api`, `--html`, and `--htmx` flags.
</div>

```sh
Expand Down Expand Up @@ -142,9 +142,9 @@ listening on port 5150

<div class="infobox">

Depending on which `-k` option you chose, the steps for creating a scaffolded resource will change. With the `api` flag or the `htmx` flag you can use the below example. But with the `html` flag, it is recommended you do the post creation steps in your browser.
Depending on which scaffold template option you chose (`-api`, `--html`, `--htmx`), the steps for creating a scaffolded resource will change. With the `--api` flag or the `--htmx` flag you can use the below example. But with the `--html` flag, it is recommended you do the post creation steps in your browser.

If you want to use `curl` to test the `html` scaffold, you will need to send your requests with the Content-Type `application/x-www-form-urlencoded` and the body as `title=Your+Title&content=Your+Content` by default. This can be changed to allow `application/json` as a `Content-Type` in the code if desired.
If you want to use `curl` to test the `--html` scaffold, you will need to send your requests with the Content-Type `application/x-www-form-urlencoded` and the body as `title=Your+Title&content=Your+Content` by default. This can be changed to allow `application/json` as a `Content-Type` in the code if desired.

</div>

Expand Down
6 changes: 6 additions & 0 deletions docs-site/content/docs/resources/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Try [cargo watch](https://crates.io/crates/cargo-watch):
$ cargo-watch -x check -s 'cargo loco start'
```

Or [bacon](https://github.com/Canop/bacon)

```
$ bacon run
```

</details>
<br/>
<details>
Expand Down
17 changes: 6 additions & 11 deletions docs-site/static/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -618,33 +618,28 @@ a.active {

@media (min-width: 640px) {
.container {
max-width: 640px;
max-width: calc(640px - 1rem);
}
}

@media (min-width: 768px) {
.container {
max-width: 768px;
max-width: calc(768px - 2rem);
}
}

@media (min-width: 1024px) {
.container {
max-width: 1024px;
max-width: calc(1024px - 6rem);
}
}

@media (min-width: 1280px) {
.container {
max-width: 1280px;
max-width: calc(1280px - 8rem);
}
}

@media (min-width: 1536px) {
.container {
max-width: 1536px;
}
}

.prose {
color: var(--tw-prose-body);
Expand Down Expand Up @@ -1005,7 +1000,7 @@ a.active {
--tw-prose-body: var(--foreground);
--tw-prose-headings: var(--foreground);
--tw-prose-lead: #4b5563;
--tw-prose-links: #111827;
--tw-prose-links: var(--foreground);
--tw-prose-bold: #111827;
--tw-prose-counters: #6b7280;
--tw-prose-bullets: #d1d5db;
Expand All @@ -1015,7 +1010,7 @@ a.active {
--tw-prose-captions: #6b7280;
--tw-prose-kbd: #111827;
--tw-prose-kbd-shadows: 17 24 39;
--tw-prose-code: #111827;
--tw-prose-code: var(--foreground);
--tw-prose-pre-code: #e5e7eb;
--tw-prose-pre-bg: #1f2937;
--tw-prose-th-borders: #d1d5db;
Expand Down
2 changes: 1 addition & 1 deletion docs-site/templates/docs/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% block content %}
<div role="document">
<div class="bg-redrust text-background dark:bg-zinc-900">
<div class="container xl:max-w-[80rem] xl:mx-auto">
<div class="container">
<aside class="w-full">
{{ macros_sidebar::docs_sidebar(current_section=current_section) }}
</aside>
Expand Down
2 changes: 1 addition & 1 deletion docs-site/templates/macros/header.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% macro header(current_section) %}
<header
class=" sticky top-0 z-50 w-full border-border/40 backdrop-blur bg-background">
<div class="container relative flex h-14 md:grid md:grid-cols-[240px_minmax(0,1fr)] xl:max-w-[80rem] xl:mx-auto">
<div class="container relative flex h-14 md:grid md:grid-cols-[240px_minmax(0,1fr)]">
<div class="mr-4 hidden sm:flex">
<a class="flex mr-4 items-center space-x-2" href="/">
<img src="/icon.svg" width="30px" />
Expand Down
2 changes: 1 addition & 1 deletion loco-gen/src/templates/model.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% set module_name = "m" ~ mig_ts ~ "_" ~ plural_snake -%}
{% set model = name | plural | pascal_case -%}
to: "migration/src/{{module_name}}.rs"
skip_glob: "migration/src/*_{{plural_snake}}.rs"
skip_glob: "migration/src/m????????_??????_{{plural_snake}}.rs"
message: "Migration for `{{name}}` added! You can now apply it with `$ cargo loco db migrate`."
injections:
- into: "migration/src/lib.rs"
Expand Down
3 changes: 2 additions & 1 deletion loco-gen/src/templates/scaffold/htmx/view_edit.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Edit {{name}}: {% raw %}{{ item.id }}{% endraw %}
{% raw %}{% block content %}{% endraw %}
<h1>Edit {{name}}: {% raw %}{{ item.id }}{% endraw %}</h1>
<div class="mb-10">
<form hx-post="/{{name | plural}}/{% raw %}{{ item.id }}{% endraw %}" hx-ext="submitjson" hx-target="#success-message">
<form hx-put="/{{name | plural}}/{% raw %}{{ item.id }}{% endraw %}" hx-ext="submitjson" hx-target="#success-message">
<div class="mb-5">
{% for column in columns -%}
<div>
Expand Down Expand Up @@ -46,6 +46,7 @@ Edit {{name}}: {% raw %}{{ item.id }}{% endraw %}
{% endif -%}
</div>
{% endfor -%}
</div>
<div>
<div class="mt-5">
<button class=" text-xs py-3 px-6 rounded-lg bg-gray-900 text-white" type="submit">Submit</button>
Expand Down
Loading

0 comments on commit fc82f3f

Please sign in to comment.