From a9ac222cf5eae88797b7bc01641d8659ce383f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ma=C4=87kowski?= Date: Sat, 11 Jan 2025 00:36:55 +0100 Subject: [PATCH] chore: rename project to cot (#95) --- Cargo.lock | 202 +++++++++--------- Cargo.toml | 14 +- LICENSE-MIT | 2 +- README.md | 28 +-- compose.yml | 12 +- {flareon-cli => cot-cli}/Cargo.toml | 6 +- {flareon-cli => cot-cli}/src/lib.rs | 0 {flareon-cli => cot-cli}/src/main.rs | 0 .../src/migration_generator.rs | 60 +++--- {flareon-cli => cot-cli}/src/utils.rs | 0 .../tests/migration_generator.rs | 6 +- .../tests/migration_generator/create_model.rs | 2 +- .../tests/migration_generator/foreign_key.rs | 2 +- .../migration_generator/foreign_key_cycle.rs | 2 +- .../foreign_key_two_migrations/step_1.rs | 2 +- .../foreign_key_two_migrations/step_2.rs | 2 +- {flareon-codegen => cot-codegen}/Cargo.toml | 2 +- {flareon-codegen => cot-codegen}/src/expr.rs | 2 +- {flareon-codegen => cot-codegen}/src/lib.rs | 2 +- {flareon-codegen => cot-codegen}/src/model.rs | 5 +- .../src/symbol_resolver.rs | 8 +- {flareon-macros => cot-macros}/Cargo.toml | 6 +- {flareon-macros => cot-macros}/src/dbtest.rs | 6 +- {flareon-macros => cot-macros}/src/form.rs | 12 +- {flareon-macros => cot-macros}/src/lib.rs | 28 +-- {flareon-macros => cot-macros}/src/main_fn.rs | 13 +- {flareon-macros => cot-macros}/src/model.rs | 8 +- {flareon-macros => cot-macros}/src/query.rs | 10 +- .../tests/compile_tests.rs | 0 cot-macros/tests/ui/attr_main.rs | 6 + cot-macros/tests/ui/attr_main_args.rs | 4 + .../tests/ui/attr_main_args.stderr | 4 +- .../tests/ui/attr_model.rs | 2 +- .../tests/ui/attr_model_enum.rs | 2 +- .../tests/ui/attr_model_enum.stderr | 0 .../tests/ui/attr_model_generic.rs | 2 +- .../tests/ui/attr_model_generic.stderr | 0 .../ui/attr_model_migration_invalid_name.rs | 2 +- .../attr_model_migration_invalid_name.stderr | 0 .../tests/ui/attr_model_multiple_pks.rs | 2 +- .../tests/ui/attr_model_multiple_pks.stderr | 0 .../tests/ui/attr_model_no_pk.rs | 2 +- .../tests/ui/attr_model_no_pk.stderr | 0 .../tests/ui/attr_model_tuple.rs | 2 +- .../tests/ui/attr_model_tuple.stderr | 0 .../tests/ui/derive_form.rs | 4 +- .../tests/ui/func_query.rs | 2 +- .../tests/ui/func_query_double_field.rs | 2 +- .../tests/ui/func_query_double_field.stderr | 0 .../tests/ui/func_query_double_op.rs | 2 +- .../tests/ui/func_query_double_op.stderr | 0 .../tests/ui/func_query_invalid_field.rs | 2 +- .../tests/ui/func_query_invalid_field.stderr | 0 .../ui/func_query_method_call_on_db_field.rs | 2 +- .../func_query_method_call_on_db_field.stderr | 0 .../tests/ui/func_query_starting_op.rs | 2 +- .../tests/ui/func_query_starting_op.stderr | 0 {flareon => cot}/Cargo.toml | 4 +- {flareon => cot}/build.rs | 0 {flareon => cot}/src/admin.rs | 22 +- {flareon => cot}/src/auth.rs | 32 ++- {flareon => cot}/src/auth/db.rs | 32 +-- cot/src/auth/db/migrations.rs | 3 + cot/src/auth/db/migrations/m_0001_initial.rs | 53 +++++ {flareon => cot}/src/config.rs | 4 +- {flareon => cot}/src/db.rs | 18 +- {flareon => cot}/src/db/fields.rs | 2 +- {flareon => cot}/src/db/impl_mysql.rs | 0 {flareon => cot}/src/db/impl_postgres.rs | 0 {flareon => cot}/src/db/impl_sqlite.rs | 0 {flareon => cot}/src/db/migrations.rs | 38 ++-- {flareon => cot}/src/db/migrations/sorter.rs | 4 +- {flareon => cot}/src/db/query.rs | 34 +-- {flareon => cot}/src/db/relations.rs | 2 +- {flareon => cot}/src/db/sea_query_db.rs | 0 {flareon => cot}/src/error.rs | 12 +- {flareon => cot}/src/error/backtrace.rs | 6 +- {flareon => cot}/src/error_page.rs | 50 ++--- {flareon => cot}/src/forms.rs | 8 +- {flareon => cot}/src/forms/fields.rs | 0 {flareon => cot}/src/headers.rs | 0 {flareon => cot}/src/lib.rs | 167 +++++++-------- {flareon => cot}/src/middleware.rs | 2 +- {flareon => cot}/src/private.rs | 2 +- {flareon => cot}/src/request.rs | 16 +- {flareon => cot}/src/response.rs | 12 +- {flareon => cot}/src/router.rs | 24 +-- {flareon => cot}/src/router/path.rs | 0 {flareon => cot}/src/static_files.rs | 16 +- {flareon => cot}/src/test.rs | 24 +-- {flareon => cot}/src/utils.rs | 0 {flareon => cot}/src/utils/graph.rs | 0 {flareon => cot}/static/admin/admin.css | 0 {flareon => cot}/templates/admin/base.html | 2 +- {flareon => cot}/templates/admin/login.html | 0 {flareon => cot}/templates/admin/model.html | 0 .../templates/admin/model_list.html | 2 +- {flareon => cot}/templates/error.css | 0 {flareon => cot}/templates/error.html | 6 +- {flareon => cot}/templates/fail.html | 8 +- {flareon => cot}/tests/auth.rs | 8 +- {flareon => cot}/tests/db.rs | 26 +-- {flareon => cot}/tests/flareon_project.rs | 20 +- {flareon => cot}/tests/forms.rs | 4 +- {flareon => cot}/tests/router.rs | 20 +- examples/admin/Cargo.toml | 4 +- examples/admin/src/main.rs | 36 ++-- examples/admin/templates/name.html | 2 +- examples/hello-world/Cargo.toml | 4 +- examples/hello-world/src/main.rs | 22 +- examples/json/Cargo.toml | 4 +- examples/json/src/main.rs | 20 +- examples/sessions/Cargo.toml | 4 +- examples/sessions/src/main.rs | 28 +-- examples/sessions/templates/name.html | 2 +- examples/todo-list/Cargo.toml | 4 +- examples/todo-list/src/main.rs | 30 +-- examples/todo-list/src/migrations.rs | 2 +- .../src/migrations/m_0001_initial.rs | 26 +-- examples/todo-list/templates/index.html | 4 +- flareon-macros/tests/ui/attr_main.rs | 6 - flareon-macros/tests/ui/attr_main_args.rs | 4 - flareon/src/auth/db/migrations.rs | 4 - .../src/auth/db/migrations/m_0001_initial.rs | 53 ----- 124 files changed, 704 insertions(+), 724 deletions(-) rename {flareon-cli => cot-cli}/Cargo.toml (86%) rename {flareon-cli => cot-cli}/src/lib.rs (100%) rename {flareon-cli => cot-cli}/src/main.rs (100%) rename {flareon-cli => cot-cli}/src/migration_generator.rs (95%) rename {flareon-cli => cot-cli}/src/utils.rs (100%) rename {flareon-cli => cot-cli}/tests/migration_generator.rs (97%) rename {flareon-cli => cot-cli}/tests/migration_generator/create_model.rs (81%) rename {flareon-cli => cot-cli}/tests/migration_generator/foreign_key.rs (75%) rename {flareon-cli => cot-cli}/tests/migration_generator/foreign_key_cycle.rs (79%) rename {flareon-cli => cot-cli}/tests/migration_generator/foreign_key_two_migrations/step_1.rs (58%) rename {flareon-cli => cot-cli}/tests/migration_generator/foreign_key_two_migrations/step_2.rs (75%) rename {flareon-codegen => cot-codegen}/Cargo.toml (95%) rename {flareon-codegen => cot-codegen}/src/expr.rs (99%) rename {flareon-codegen => cot-codegen}/src/lib.rs (70%) rename {flareon-codegen => cot-codegen}/src/model.rs (98%) rename {flareon-codegen => cot-codegen}/src/symbol_resolver.rs (97%) rename {flareon-macros => cot-macros}/Cargo.toml (87%) rename {flareon-macros => cot-macros}/src/dbtest.rs (84%) rename {flareon-macros => cot-macros}/src/form.rs (97%) rename {flareon-macros => cot-macros}/src/lib.rs (87%) rename {flareon-macros => cot-macros}/src/main_fn.rs (66%) rename {flareon-macros => cot-macros}/src/model.rs (97%) rename {flareon-macros => cot-macros}/src/query.rs (95%) rename {flareon-macros => cot-macros}/tests/compile_tests.rs (100%) create mode 100644 cot-macros/tests/ui/attr_main.rs create mode 100644 cot-macros/tests/ui/attr_main_args.rs rename {flareon-macros => cot-macros}/tests/ui/attr_main_args.stderr (67%) rename {flareon-macros => cot-macros}/tests/ui/attr_model.rs (85%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_enum.rs (81%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_enum.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_generic.rs (76%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_generic.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_migration_invalid_name.rs (86%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_migration_invalid_name.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_multiple_pks.rs (82%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_multiple_pks.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_no_pk.rs (75%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_no_pk.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_tuple.rs (76%) rename {flareon-macros => cot-macros}/tests/ui/attr_model_tuple.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/derive_form.rs (84%) rename {flareon-macros => cot-macros}/tests/ui/func_query.rs (88%) rename {flareon-macros => cot-macros}/tests/ui/func_query_double_field.rs (86%) rename {flareon-macros => cot-macros}/tests/ui/func_query_double_field.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/func_query_double_op.rs (88%) rename {flareon-macros => cot-macros}/tests/ui/func_query_double_op.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/func_query_invalid_field.rs (86%) rename {flareon-macros => cot-macros}/tests/ui/func_query_invalid_field.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/func_query_method_call_on_db_field.rs (84%) rename {flareon-macros => cot-macros}/tests/ui/func_query_method_call_on_db_field.stderr (100%) rename {flareon-macros => cot-macros}/tests/ui/func_query_starting_op.rs (86%) rename {flareon-macros => cot-macros}/tests/ui/func_query_starting_op.stderr (100%) rename {flareon => cot}/Cargo.toml (98%) rename {flareon => cot}/build.rs (100%) rename {flareon => cot}/src/admin.rs (89%) rename {flareon => cot}/src/auth.rs (97%) rename {flareon => cot}/src/auth/db.rs (95%) create mode 100644 cot/src/auth/db/migrations.rs create mode 100644 cot/src/auth/db/migrations/m_0001_initial.rs rename {flareon => cot}/src/config.rs (98%) rename {flareon => cot}/src/db.rs (99%) rename {flareon => cot}/src/db/fields.rs (99%) rename {flareon => cot}/src/db/impl_mysql.rs (100%) rename {flareon => cot}/src/db/impl_postgres.rs (100%) rename {flareon => cot}/src/db/impl_sqlite.rs (100%) rename {flareon => cot}/src/db/migrations.rs (96%) rename {flareon => cot}/src/db/migrations/sorter.rs (99%) rename {flareon => cot}/src/db/query.rs (95%) rename {flareon => cot}/src/db/relations.rs (99%) rename {flareon => cot}/src/db/sea_query_db.rs (100%) rename {flareon => cot}/src/error.rs (92%) rename {flareon => cot}/src/error/backtrace.rs (96%) rename {flareon => cot}/src/error_page.rs (87%) rename {flareon => cot}/src/forms.rs (98%) rename {flareon => cot}/src/forms/fields.rs (100%) rename {flareon => cot}/src/headers.rs (100%) rename {flareon => cot}/src/lib.rs (83%) rename {flareon => cot}/src/middleware.rs (95%) rename {flareon => cot}/src/private.rs (80%) rename {flareon => cot}/src/request.rs (94%) rename {flareon => cot}/src/response.rs (94%) rename {flareon => cot}/src/router.rs (96%) rename {flareon => cot}/src/router/path.rs (100%) rename {flareon => cot}/src/static_files.rs (96%) rename {flareon => cot}/src/test.rs (93%) rename {flareon => cot}/src/utils.rs (100%) rename {flareon => cot}/src/utils/graph.rs (100%) rename {flareon => cot}/static/admin/admin.css (100%) rename {flareon => cot}/templates/admin/base.html (84%) rename {flareon => cot}/templates/admin/login.html (100%) rename {flareon => cot}/templates/admin/model.html (100%) rename {flareon => cot}/templates/admin/model_list.html (58%) rename {flareon => cot}/templates/error.css (100%) rename {flareon => cot}/templates/error.html (94%) rename {flareon => cot}/templates/fail.html (57%) rename {flareon => cot}/tests/auth.rs (89%) rename {flareon => cot}/tests/db.rs (97%) rename {flareon => cot}/tests/flareon_project.rs (69%) rename {flareon => cot}/tests/forms.rs (97%) rename {flareon => cot}/tests/router.rs (77%) delete mode 100644 flareon-macros/tests/ui/attr_main.rs delete mode 100644 flareon-macros/tests/ui/attr_main_args.rs delete mode 100644 flareon/src/auth/db/migrations.rs delete mode 100644 flareon/src/auth/db/migrations/m_0001_initial.rs diff --git a/Cargo.lock b/Cargo.lock index b7dc833..a6a6877 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -442,6 +442,102 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cot" +version = "0.1.0" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "backtrace", + "bytes", + "chrono", + "cot_macros", + "derive_builder", + "derive_more", + "fake", + "form_urlencoded", + "futures", + "futures-core", + "futures-util", + "hmac 0.13.0-pre.4", + "http", + "http-body", + "http-body-util", + "humansize", + "indexmap", + "mime_guess", + "mockall", + "password-auth", + "pin-project-lite", + "rinja", + "sea-query", + "sea-query-binder", + "serde", + "serde_json", + "sha2 0.11.0-pre.4", + "sqlx", + "subtle", + "sync_wrapper", + "thiserror 2.0.9", + "time", + "tokio", + "tower", + "tower-sessions", + "tracing", +] + +[[package]] +name = "cot-cli" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_toml", + "chrono", + "clap", + "clap-verbosity-flag", + "cot", + "cot_codegen", + "darling", + "glob", + "petgraph", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "tempfile", + "tracing", + "tracing-subscriber", + "trybuild", +] + +[[package]] +name = "cot_codegen" +version = "0.1.0" +dependencies = [ + "convert_case", + "darling", + "proc-macro2", + "quote", + "syn", + "tracing", +] + +[[package]] +name = "cot_macros" +version = "0.1.0" +dependencies = [ + "cot", + "cot_codegen", + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "rustversion", + "syn", + "trybuild", +] + [[package]] name = "cpufeatures" version = "0.2.16" @@ -732,21 +828,21 @@ dependencies = [ name = "example-admin" version = "0.1.0" dependencies = [ - "flareon", + "cot", ] [[package]] name = "example-hello-world" version = "0.1.0" dependencies = [ - "flareon", + "cot", ] [[package]] name = "example-json" version = "0.1.0" dependencies = [ - "flareon", + "cot", "serde", ] @@ -754,7 +850,7 @@ dependencies = [ name = "example-sessions" version = "0.1.0" dependencies = [ - "flareon", + "cot", "rinja", ] @@ -762,7 +858,7 @@ dependencies = [ name = "example-todo-list" version = "0.1.0" dependencies = [ - "flareon", + "cot", "rinja", ] @@ -790,102 +886,6 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" -[[package]] -name = "flareon" -version = "0.1.0" -dependencies = [ - "async-stream", - "async-trait", - "axum", - "backtrace", - "bytes", - "chrono", - "derive_builder", - "derive_more", - "fake", - "flareon_macros", - "form_urlencoded", - "futures", - "futures-core", - "futures-util", - "hmac 0.13.0-pre.4", - "http", - "http-body", - "http-body-util", - "humansize", - "indexmap", - "mime_guess", - "mockall", - "password-auth", - "pin-project-lite", - "rinja", - "sea-query", - "sea-query-binder", - "serde", - "serde_json", - "sha2 0.11.0-pre.4", - "sqlx", - "subtle", - "sync_wrapper", - "thiserror 2.0.9", - "time", - "tokio", - "tower", - "tower-sessions", - "tracing", -] - -[[package]] -name = "flareon-cli" -version = "0.1.0" -dependencies = [ - "anyhow", - "cargo_toml", - "chrono", - "clap", - "clap-verbosity-flag", - "darling", - "flareon", - "flareon_codegen", - "glob", - "petgraph", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "tempfile", - "tracing", - "tracing-subscriber", - "trybuild", -] - -[[package]] -name = "flareon_codegen" -version = "0.1.0" -dependencies = [ - "convert_case", - "darling", - "proc-macro2", - "quote", - "syn", - "tracing", -] - -[[package]] -name = "flareon_macros" -version = "0.1.0" -dependencies = [ - "darling", - "flareon", - "flareon_codegen", - "proc-macro-crate", - "proc-macro2", - "quote", - "rustversion", - "syn", - "trybuild", -] - [[package]] name = "flume" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index ba1f795..a6061a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [workspace] members = [ - "flareon", - "flareon-cli", - "flareon-codegen", - "flareon-macros", + "cot", + "cot-cli", + "cot-codegen", + "cot-macros", # Examples "examples/hello-world", "examples/todo-list", @@ -37,9 +37,9 @@ darling = "0.20" derive_builder = "0.20" derive_more = "1" fake = "3.1" -flareon = { path = "flareon" } -flareon_codegen = { path = "flareon-codegen" } -flareon_macros = { path = "flareon-macros" } +cot = { path = "cot" } +cot_codegen = { path = "cot-codegen" } +cot_macros = { path = "cot-macros" } form_urlencoded = "1" futures = { version = "0.3", default-features = false } futures-core = { version = "0.3", default-features = false } diff --git a/LICENSE-MIT b/LICENSE-MIT index 8df6740..d90e3e6 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Flareon Authors +Copyright (c) 2024 Cot Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4597aed..527cdf2 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,31 @@
-

Flareon

+

Cot

-[![Rust Build Status](https://github.com/flareon-rs/flareon/workflows/Rust%20CI/badge.svg)](https://github.com/flareon-rs/flareon/actions/workflows/rust.yml) -[![crates.io](https://img.shields.io/crates/v/flareon.svg)](https://crates.io/crates/flareon) -[![Documentation](https://docs.rs/flareon/badge.svg)](https://docs.rs/flareon) -[![codecov](https://codecov.io/gh/flareon-rs/flareon/branch/master/graph/badge.svg)](https://codecov.io/gh/flareon-rs/flareon) +[![Rust Build Status](https://github.com/cot-rs/cot/workflows/Rust%20CI/badge.svg)](https://github.com/cot-rs/cot/actions/workflows/rust.yml) +[![crates.io](https://img.shields.io/crates/v/cot.svg)](https://crates.io/crates/cot) +[![Documentation](https://docs.rs/cot/badge.svg)](https://docs.rs/cot) +[![codecov](https://codecov.io/gh/cot-rs/cot/branch/master/graph/badge.svg)](https://codecov.io/gh/cot-rs/cot)
-Flareon is an easy to use, modern, and fast web framework for Rust. It has been designed to be familiar if you've ever +Cot is an easy to use, modern, and fast web framework for Rust. It has been designed to be familiar if you've ever used [Django](https://www.djangoproject.com/), and easy to learn if you haven't. It's a batteries-included framework built on top of [axum](https://github.com/tokio-rs/axum). ## Features -* **Easy to use API** — in many ways modeled after Django, Flareon's API is designed to be easy to use and intuitive. +* **Easy to use API** — in many ways modeled after Django, Cot's API is designed to be easy to use and intuitive. Sensible defaults make it for easy rapid development, while the API is still empowering you when needed. The - documentation is a first-class citizen in Flareon, making it easy to find what you're looking for. -* **ORM integration** — Flareon comes with its own ORM, allowing you to interact with your database in a way that feels + documentation is a first-class citizen in Cot, making it easy to find what you're looking for. +* **ORM integration** — Cot comes with its own ORM, allowing you to interact with your database in a way that feels Rusty and intuitive. Rust types are the source of truth, and the ORM takes care of translating them to and from the database, as well as creating the migrations automatically. -* **Type safe** — wherever possible, Flareon uses Rust's type system to prevent common mistakes and bugs. Not only views +* **Type safe** — wherever possible, Cot uses Rust's type system to prevent common mistakes and bugs. Not only views are taking advantage of the Rust's type system, but also the ORM, the admin panel, and even the templates. All that to catch errors as early as possible. -* **Admin panel** — Flareon comes with an admin panel out of the box, allowing you to manage your app's data with ease. +* **Admin panel** — Cot comes with an admin panel out of the box, allowing you to manage your app's data with ease. Adding new models to the admin panel is stupidly simple, making it a great tool not only for rapid development and debugging, but with its customization options, also for production use. -* **Secure by default** — security should be opt-out, not opt-in. Flareon takes care of making your web apps secure by +* **Secure by default** — security should be opt-out, not opt-in. Cot takes care of making your web apps secure by default, defending it against common modern web vulnerabilities. You can focus on building your app, not securing it. ## Development @@ -48,10 +48,10 @@ docker compose down ## License -Flareon is licensed under either of the following, at your option: +Cot is licensed under either of the following, at your option: * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0) * MIT License ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT) -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Flareon by you shall be +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Cot by you shall be dual licensed under the MIT License and Apache License, Version 2.0, without any additional terms or conditions. diff --git a/compose.yml b/compose.yml index 0d10cf6..7f5fe82 100644 --- a/compose.yml +++ b/compose.yml @@ -1,20 +1,20 @@ services: mariadb: image: docker.io/mariadb:11 - container_name: flareon-mariadb + container_name: cot-mariadb environment: MARIADB_DATABASE: mysql - MARIADB_USER: flareon - MARIADB_PASSWORD: flareon + MARIADB_USER: cot + MARIADB_PASSWORD: cot MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1 ports: - "3306:3306" postgres: image: docker.io/postgres:17-alpine - container_name: flareon-postgres + container_name: cot-postgres environment: - POSTGRES_USER: flareon - POSTGRES_PASSWORD: flareon + POSTGRES_USER: cot + POSTGRES_PASSWORD: cot ports: - "5432:5432" diff --git a/flareon-cli/Cargo.toml b/cot-cli/Cargo.toml similarity index 86% rename from flareon-cli/Cargo.toml rename to cot-cli/Cargo.toml index 6b64b5e..0a41745 100644 --- a/flareon-cli/Cargo.toml +++ b/cot-cli/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "flareon-cli" +name = "cot-cli" version = "0.1.0" edition.workspace = true license.workspace = true @@ -15,8 +15,8 @@ chrono.workspace = true clap = { workspace = true, features = ["derive", "env"] } clap-verbosity-flag = { workspace = true, features = ["tracing"] } darling.workspace = true -flareon.workspace = true -flareon_codegen = { workspace = true, features = ["symbol-resolver"] } +cot.workspace = true +cot_codegen = { workspace = true, features = ["symbol-resolver"] } glob.workspace = true petgraph.workspace = true prettyplease.workspace = true diff --git a/flareon-cli/src/lib.rs b/cot-cli/src/lib.rs similarity index 100% rename from flareon-cli/src/lib.rs rename to cot-cli/src/lib.rs diff --git a/flareon-cli/src/main.rs b/cot-cli/src/main.rs similarity index 100% rename from flareon-cli/src/main.rs rename to cot-cli/src/main.rs diff --git a/flareon-cli/src/migration_generator.rs b/cot-cli/src/migration_generator.rs similarity index 95% rename from flareon-cli/src/migration_generator.rs rename to cot-cli/src/migration_generator.rs index 45b4397..ab132ed 100644 --- a/flareon-cli/src/migration_generator.rs +++ b/cot-cli/src/migration_generator.rs @@ -7,10 +7,10 @@ use std::path::{Path, PathBuf}; use anyhow::{bail, Context}; use cargo_toml::Manifest; +use cot::db::migrations::{DynMigration, MigrationEngine}; +use cot_codegen::model::{Field, Model, ModelArgs, ModelOpts, ModelType}; +use cot_codegen::symbol_resolver::SymbolResolver; use darling::FromMeta; -use flareon::db::migrations::{DynMigration, MigrationEngine}; -use flareon_codegen::model::{Field, Model, ModelArgs, ModelOpts, ModelType}; -use flareon_codegen::symbol_resolver::SymbolResolver; use petgraph::graph::DiGraph; use petgraph::visit::EdgeRef; use proc_macro2::TokenStream; @@ -426,13 +426,13 @@ impl MigrationGenerator { #[derive(Debug, Copy, Clone)] pub(super) struct Migration; - impl ::flareon::db::migrations::Migration for Migration { + impl ::cot::db::migrations::Migration for Migration { const APP_NAME: &'static str = #app_name; const MIGRATION_NAME: &'static str = #migration_name; - const DEPENDENCIES: &'static [::flareon::db::migrations::MigrationDependency] = &[ + const DEPENDENCIES: &'static [::cot::db::migrations::MigrationDependency] = &[ #(#dependencies,)* ]; - const OPERATIONS: &'static [::flareon::db::migrations::Operation] = &[ + const OPERATIONS: &'static [::cot::db::migrations::Operation] = &[ #(#operations,)* ]; } @@ -485,7 +485,7 @@ impl MigrationGenerator { let version = env!("CARGO_PKG_VERSION"); let date_time = chrono::offset::Utc::now().format("%Y-%m-%d %H:%M:%S%:z"); - let header = format!("//! Generated by flareon CLI {version} on {date_time}"); + let header = format!("//! Generated by cot CLI {version} on {date_time}"); format!("{header}\n\n{migration}\n{modified_models}") } @@ -506,7 +506,7 @@ impl MigrationGenerator { .push(syn::parse_quote! {#[derive(::core::fmt::Debug)]}); model_source .attrs - .push(syn::parse_quote! {#[::flareon::db::model(model_type = "migration")]}); + .push(syn::parse_quote! {#[::cot::db::model(model_type = "migration")]}); quote! { #model_source } @@ -801,7 +801,7 @@ impl GeneratedMigration { .into_iter() .map(petgraph::graph::NodeIndex::index) .collect::>(); - flareon::__private::apply_permutation(operations, &mut sorted); + cot::__private::apply_permutation(operations, &mut sorted); } /// Construct a graph that represents reverse dependencies between @@ -894,8 +894,8 @@ impl MigrationAsSource { fn is_model_attr(attr: &syn::Attribute) -> bool { let path = attr.path(); - let model_path: syn::Path = parse_quote!(flareon::db::model); - let model_path_prefixed: syn::Path = parse_quote!(::flareon::db::model); + let model_path: syn::Path = parse_quote!(cot::db::model); + let model_path_prefixed: syn::Path = parse_quote!(::cot::db::model); attr.style == syn::AttrStyle::Outer && (path.is_ident("model") || path == &model_path || path == &model_path_prefixed) @@ -910,7 +910,7 @@ impl Repr for Field { let column_name = &self.column_name; let ty = &self.ty; let mut tokens = quote! { - ::flareon::db::migrations::Field::new(::flareon::db::Identifier::new(#column_name), <#ty as ::flareon::db::DatabaseField>::TYPE) + ::cot::db::migrations::Field::new(::cot::db::Identifier::new(#column_name), <#ty as ::cot::db::DatabaseField>::TYPE) }; if self.auto_value { tokens = quote! { #tokens.auto() } @@ -923,14 +923,14 @@ impl Repr for Field { tokens = quote! { #tokens.foreign_key( - <#to_model as ::flareon::db::Model>::TABLE_NAME, - <#to_model as ::flareon::db::Model>::PRIMARY_KEY_NAME, - ::flareon::db::ForeignKeyOnDeletePolicy::Restrict, - ::flareon::db::ForeignKeyOnUpdatePolicy::Restrict, + <#to_model as ::cot::db::Model>::TABLE_NAME, + <#to_model as ::cot::db::Model>::PRIMARY_KEY_NAME, + ::cot::db::ForeignKeyOnDeletePolicy::Restrict, + ::cot::db::ForeignKeyOnUpdatePolicy::Restrict, ) } } - tokens = quote! { #tokens.set_null(<#ty as ::flareon::db::DatabaseField>::NULLABLE) }; + tokens = quote! { #tokens.set_null(<#ty as ::cot::db::DatabaseField>::NULLABLE) }; if self.unique { tokens = quote! { #tokens.unique() } } @@ -954,16 +954,16 @@ impl DynMigration for Migration { &self.name } - fn dependencies(&self) -> &[flareon::db::migrations::MigrationDependency] { + fn dependencies(&self) -> &[cot::db::migrations::MigrationDependency] { &[] } - fn operations(&self) -> &[flareon::db::migrations::Operation] { + fn operations(&self) -> &[cot::db::migrations::Operation] { &[] } } -/// A version of [`flareon::db::migrations::MigrationDependency`] that can be +/// A version of [`cot::db::migrations::MigrationDependency`] that can be /// created at runtime and is using codegen types. /// /// This is used to generate migration files. @@ -978,14 +978,14 @@ impl Repr for DynDependency { match self { Self::Migration { app, migration } => { quote! { - ::flareon::db::migrations::MigrationDependency::migration(#app, #migration) + ::cot::db::migrations::MigrationDependency::migration(#app, #migration) } } Self::Model { model_type } => { quote! { - ::flareon::db::migrations::MigrationDependency::model( - <#model_type as ::flareon::db::Model>::APP_NAME, - <#model_type as ::flareon::db::Model>::TABLE_NAME + ::cot::db::migrations::MigrationDependency::model( + <#model_type as ::cot::db::Model>::APP_NAME, + <#model_type as ::cot::db::Model>::TABLE_NAME ) } } @@ -993,7 +993,7 @@ impl Repr for DynDependency { } } -/// A version of [`flareon::db::migrations::Operation`] that can be created at +/// A version of [`cot::db::migrations::Operation`] that can be created at /// runtime and is using codegen types. /// /// This is used to generate migration files. @@ -1033,8 +1033,8 @@ impl Repr for DynOperation { } => { let fields = fields.iter().map(Repr::repr).collect::>(); quote! { - ::flareon::db::migrations::Operation::create_model() - .table_name(::flareon::db::Identifier::new(#table_name)) + ::cot::db::migrations::Operation::create_model() + .table_name(::cot::db::Identifier::new(#table_name)) .fields(&[ #(#fields,)* ]) @@ -1046,8 +1046,8 @@ impl Repr for DynOperation { } => { let field = field.repr(); quote! { - ::flareon::db::migrations::Operation::add_field() - .table_name(::flareon::db::Identifier::new(#table_name)) + ::cot::db::migrations::Operation::add_field() + .table_name(::cot::db::Identifier::new(#table_name)) .field(#field) .build() } @@ -1094,7 +1094,7 @@ impl Error for ParsingError {} #[cfg(test)] mod tests { - use flareon_codegen::model::ForeignKeySpec; + use cot_codegen::model::ForeignKeySpec; use super::*; diff --git a/flareon-cli/src/utils.rs b/cot-cli/src/utils.rs similarity index 100% rename from flareon-cli/src/utils.rs rename to cot-cli/src/utils.rs diff --git a/flareon-cli/tests/migration_generator.rs b/cot-cli/tests/migration_generator.rs similarity index 97% rename from flareon-cli/tests/migration_generator.rs rename to cot-cli/tests/migration_generator.rs index 85be342..6717718 100644 --- a/flareon-cli/tests/migration_generator.rs +++ b/cot-cli/tests/migration_generator.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use flareon_cli::migration_generator::{ +use cot_cli::migration_generator::{ DynDependency, DynOperation, MigrationAsSource, MigrationGenerator, MigrationGeneratorOptions, SourceFile, }; @@ -199,7 +199,7 @@ fn test_generator() -> MigrationGenerator { ) } -fn unwrap_create_model(op: &DynOperation) -> (&str, Vec) { +fn unwrap_create_model(op: &DynOperation) -> (&str, Vec) { if let DynOperation::CreateModel { table_name, fields, .. } = op @@ -210,7 +210,7 @@ fn unwrap_create_model(op: &DynOperation) -> (&str, Vec (&str, flareon_codegen::model::Field) { +fn unwrap_add_field(op: &DynOperation) -> (&str, cot_codegen::model::Field) { if let DynOperation::AddField { table_name, field, .. } = op diff --git a/flareon-cli/tests/migration_generator/create_model.rs b/cot-cli/tests/migration_generator/create_model.rs similarity index 81% rename from flareon-cli/tests/migration_generator/create_model.rs rename to cot-cli/tests/migration_generator/create_model.rs index 707503e..9604c21 100644 --- a/flareon-cli/tests/migration_generator/create_model.rs +++ b/cot-cli/tests/migration_generator/create_model.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, Auto, ForeignKey, LimitedString}; +use cot::db::{model, Auto, ForeignKey, LimitedString}; pub const FIELD_LEN: u32 = 64; diff --git a/flareon-cli/tests/migration_generator/foreign_key.rs b/cot-cli/tests/migration_generator/foreign_key.rs similarity index 75% rename from flareon-cli/tests/migration_generator/foreign_key.rs rename to cot-cli/tests/migration_generator/foreign_key.rs index c6c7def..e1ef7fa 100644 --- a/flareon-cli/tests/migration_generator/foreign_key.rs +++ b/cot-cli/tests/migration_generator/foreign_key.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, Auto, ForeignKey}; +use cot::db::{model, Auto, ForeignKey}; #[model] struct Child { diff --git a/flareon-cli/tests/migration_generator/foreign_key_cycle.rs b/cot-cli/tests/migration_generator/foreign_key_cycle.rs similarity index 79% rename from flareon-cli/tests/migration_generator/foreign_key_cycle.rs rename to cot-cli/tests/migration_generator/foreign_key_cycle.rs index e197ef3..f21c58c 100644 --- a/flareon-cli/tests/migration_generator/foreign_key_cycle.rs +++ b/cot-cli/tests/migration_generator/foreign_key_cycle.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, Auto, ForeignKey}; +use cot::db::{model, Auto, ForeignKey}; #[model] struct Child { diff --git a/flareon-cli/tests/migration_generator/foreign_key_two_migrations/step_1.rs b/cot-cli/tests/migration_generator/foreign_key_two_migrations/step_1.rs similarity index 58% rename from flareon-cli/tests/migration_generator/foreign_key_two_migrations/step_1.rs rename to cot-cli/tests/migration_generator/foreign_key_two_migrations/step_1.rs index ba5fa83..ff529e6 100644 --- a/flareon-cli/tests/migration_generator/foreign_key_two_migrations/step_1.rs +++ b/cot-cli/tests/migration_generator/foreign_key_two_migrations/step_1.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, Auto, ForeignKey}; +use cot::db::{model, Auto, ForeignKey}; #[model] struct Parent { diff --git a/flareon-cli/tests/migration_generator/foreign_key_two_migrations/step_2.rs b/cot-cli/tests/migration_generator/foreign_key_two_migrations/step_2.rs similarity index 75% rename from flareon-cli/tests/migration_generator/foreign_key_two_migrations/step_2.rs rename to cot-cli/tests/migration_generator/foreign_key_two_migrations/step_2.rs index c6c7def..e1ef7fa 100644 --- a/flareon-cli/tests/migration_generator/foreign_key_two_migrations/step_2.rs +++ b/cot-cli/tests/migration_generator/foreign_key_two_migrations/step_2.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, Auto, ForeignKey}; +use cot::db::{model, Auto, ForeignKey}; #[model] struct Child { diff --git a/flareon-codegen/Cargo.toml b/cot-codegen/Cargo.toml similarity index 95% rename from flareon-codegen/Cargo.toml rename to cot-codegen/Cargo.toml index 8833593..005c429 100644 --- a/flareon-codegen/Cargo.toml +++ b/cot-codegen/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "flareon_codegen" +name = "cot_codegen" version = "0.1.0" edition.workspace = true license.workspace = true diff --git a/flareon-codegen/src/expr.rs b/cot-codegen/src/expr.rs similarity index 99% rename from flareon-codegen/src/expr.rs rename to cot-codegen/src/expr.rs index b8f2846..edbd7cd 100644 --- a/flareon-codegen/src/expr.rs +++ b/cot-codegen/src/expr.rs @@ -241,7 +241,7 @@ type InfixBindingPriority = BindingPriority; /// # Examples /// /// ``` -/// use flareon_codegen::expr::Expr; +/// use cot_codegen::expr::Expr; /// use quote::quote; /// use syn::parse_quote; /// diff --git a/flareon-codegen/src/lib.rs b/cot-codegen/src/lib.rs similarity index 70% rename from flareon-codegen/src/lib.rs rename to cot-codegen/src/lib.rs index 6b9bcdd..535e355 100644 --- a/flareon-codegen/src/lib.rs +++ b/cot-codegen/src/lib.rs @@ -1,4 +1,4 @@ -extern crate self as flareon_codegen; +extern crate self as cot_codegen; pub mod expr; pub mod model; diff --git a/flareon-codegen/src/model.rs b/cot-codegen/src/model.rs similarity index 98% rename from flareon-codegen/src/model.rs rename to cot-codegen/src/model.rs index 6680056..c448427 100644 --- a/flareon-codegen/src/model.rs +++ b/cot-codegen/src/model.rs @@ -217,9 +217,8 @@ impl FieldOpts { #[cfg(feature = "symbol-resolver")] let (auto_value, foreign_key) = ( - self.find_type("flareon::db::Auto", symbol_resolver) - .is_some(), - self.find_type("flareon::db::ForeignKey", symbol_resolver) + self.find_type("cot::db::Auto", symbol_resolver).is_some(), + self.find_type("cot::db::ForeignKey", symbol_resolver) .map(ForeignKeySpec::try_from) .transpose()?, ); diff --git a/flareon-codegen/src/symbol_resolver.rs b/cot-codegen/src/symbol_resolver.rs similarity index 97% rename from flareon-codegen/src/symbol_resolver.rs rename to cot-codegen/src/symbol_resolver.rs index 1eaf5db..2bfc782 100644 --- a/flareon-codegen/src/symbol_resolver.rs +++ b/cot-codegen/src/symbol_resolver.rs @@ -146,7 +146,7 @@ impl SymbolResolver { /// For instance, for `use std::collections::HashMap;` the `VisibleSymbol ` /// would be: /// ``` -/// use flareon_codegen::symbol_resolver::{VisibleSymbol, VisibleSymbolKind}; +/// use cot_codegen::symbol_resolver::{VisibleSymbol, VisibleSymbolKind}; /// /// let _ = VisibleSymbol { /// alias: String::from("HashMap"), @@ -327,7 +327,7 @@ impl Display for ModulePath { #[cfg(test)] mod tests { - use flareon_codegen::symbol_resolver::VisibleSymbolKind; + use cot_codegen::symbol_resolver::VisibleSymbolKind; use quote::{quote, ToTokens}; use syn::parse_quote; @@ -448,7 +448,7 @@ const MY_CONSTANT: u8 = 42; let resolver = SymbolResolver::new(vec![ VisibleSymbol::new_use("MyType", "crate::models::MyType"), VisibleSymbol::new_use("HashMap", "std::collections::HashMap"), - VisibleSymbol::new_use("LimitedString", "flareon::db::LimitedString"), + VisibleSymbol::new_use("LimitedString", "cot::db::LimitedString"), VisibleSymbol::new( "MY_CONSTANT", "crate::constants::MY_CONSTANT", @@ -470,7 +470,7 @@ const MY_CONSTANT: u8 = 42; field_1: crate::models::MyType, field_2: std::collections::HashMap, field_3: Option, - field_4: flareon::db::LimitedString<{ crate::constants::MY_CONSTANT }>, + field_4: cot::db::LimitedString<{ crate::constants::MY_CONSTANT }>, } }; assert_eq!(actual.into_token_stream().to_string(), expected.to_string()); diff --git a/flareon-macros/Cargo.toml b/cot-macros/Cargo.toml similarity index 87% rename from flareon-macros/Cargo.toml rename to cot-macros/Cargo.toml index 7d1eb94..7ef334f 100644 --- a/flareon-macros/Cargo.toml +++ b/cot-macros/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "flareon_macros" +name = "cot_macros" version = "0.1.0" edition.workspace = true license.workspace = true @@ -17,13 +17,13 @@ workspace = true [dependencies] darling.workspace = true -flareon_codegen.workspace = true +cot_codegen.workspace = true proc-macro-crate.workspace = true proc-macro2 = { workspace = true, features = ["proc-macro"] } quote = { workspace = true, features = ["proc-macro"] } syn.workspace = true [dev-dependencies] -flareon.workspace = true +cot.workspace = true trybuild.workspace = true rustversion.workspace = true diff --git a/flareon-macros/src/dbtest.rs b/cot-macros/src/dbtest.rs similarity index 84% rename from flareon-macros/src/dbtest.rs rename to cot-macros/src/dbtest.rs index 679354a..01ef3c7 100644 --- a/flareon-macros/src/dbtest.rs +++ b/cot-macros/src/dbtest.rs @@ -19,7 +19,7 @@ pub(super) fn fn_to_dbtest(test_function_decl: ItemFn) -> syn::Result syn::Result syn::Result TokenStream { let opts = match FormOpts::from_derive_input(ast) { @@ -96,7 +96,7 @@ impl ToTokens for FormDeriveBuilder { impl FormDeriveBuilder { fn push_field(&mut self, field: &Field) { - let crate_ident = flareon_ident(); + let crate_ident = cot_ident(); let name = field.ident.as_ref().unwrap(); let ty = &field.ty; let opt = &field.opt; @@ -156,7 +156,7 @@ impl FormDeriveBuilder { } fn build_form_impl(&self) -> TokenStream { - let crate_ident = flareon_ident(); + let crate_ident = cot_ident(); let name = &self.name; let context_struct_name = &self.context_struct_name; let fields_as_from_context_vars = &self.fields_as_from_context_vars; @@ -189,7 +189,7 @@ impl FormDeriveBuilder { } fn build_form_context_impl(&self) -> TokenStream { - let crate_ident = flareon_ident(); + let crate_ident = cot_ident(); let context_struct_name = &self.context_struct_name; let context_struct_errors_name = &self.context_struct_errors_name; @@ -221,7 +221,7 @@ impl FormDeriveBuilder { fn fields( &self, ) -> impl ::core::iter::DoubleEndedIterator< - Item = &dyn ::flareon::forms::DynFormField, + Item = &dyn ::cot::forms::DynFormField, > + ::core::iter::ExactSizeIterator + '_ { [#( #fields_as_dyn_field_ref, )*].into_iter() } @@ -284,7 +284,7 @@ impl FormDeriveBuilder { } fn build_errors_struct(&self) -> TokenStream { - let crate_ident = flareon_ident(); + let crate_ident = cot_ident(); let context_struct_errors_name = &self.context_struct_errors_name; let fields_as_errors = &self.fields_as_errors; diff --git a/flareon-macros/src/lib.rs b/cot-macros/src/lib.rs similarity index 87% rename from flareon-macros/src/lib.rs rename to cot-macros/src/lib.rs index 338f6bb..e8e4c8d 100644 --- a/flareon-macros/src/lib.rs +++ b/cot-macros/src/lib.rs @@ -13,7 +13,7 @@ use syn::{parse_macro_input, ItemFn}; use crate::dbtest::fn_to_dbtest; use crate::form::impl_form_for_struct; -use crate::main_fn::fn_to_flareon_main; +use crate::main_fn::fn_to_cot_main; use crate::model::impl_model_for_struct; use crate::query::{query_to_tokens, Query}; @@ -46,7 +46,7 @@ pub fn derive_form(input: TokenStream) -> TokenStream { /// * `application` (default): The model represents an actual table in a /// normally running instance of the application. /// ``` -/// use flareon::db::model; +/// use cot::db::model; /// /// #[model(model_type = "application")] /// // This is equivalent to: @@ -72,7 +72,7 @@ pub fn derive_form(input: TokenStream) -> TokenStream { /// the state of the model at the time the migration runs. /// ``` /// // In a migration file -/// use flareon::db::model; +/// use cot::db::model; /// /// #[model(model_type = "migration")] /// struct _User { @@ -80,15 +80,15 @@ pub fn derive_form(input: TokenStream) -> TokenStream { /// username: String, /// } /// ``` -/// * `internal`: The model represents a table that is used internally by -/// Flareon (e.g. the `flareon__migrations` table, storing which migrations -/// have been applied). They are ignored by the migration generator and should -/// never be used outside Flareon code. +/// * `internal`: The model represents a table that is used internally by Cot +/// (e.g. the `cot__migrations` table, storing which migrations have been +/// applied). They are ignored by the migration generator and should never be +/// used outside Cot code. /// ``` -/// use flareon::db::model; +/// use cot::db::model; /// /// #[model(model_type = "internal")] -/// struct FlareonMigrations { +/// struct CotMigrations { /// id: i32, /// app: String, /// name: String, @@ -127,16 +127,16 @@ pub fn dbtest(_args: TokenStream, input: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn main(_args: TokenStream, input: TokenStream) -> TokenStream { let fn_input = parse_macro_input!(input as ItemFn); - fn_to_flareon_main(fn_input) + fn_to_cot_main(fn_input) .unwrap_or_else(syn::Error::into_compile_error) .into() } -pub(crate) fn flareon_ident() -> proc_macro2::TokenStream { - let flareon_crate = crate_name("flareon").expect("flareon is not present in `Cargo.toml`"); - match flareon_crate { +pub(crate) fn cot_ident() -> proc_macro2::TokenStream { + let cot_crate = crate_name("cot").expect("cot is not present in `Cargo.toml`"); + match cot_crate { proc_macro_crate::FoundCrate::Itself => { - quote! { ::flareon } + quote! { ::cot } } proc_macro_crate::FoundCrate::Name(name) => { let ident = syn::Ident::new(&name, proc_macro2::Span::call_site()); diff --git a/flareon-macros/src/main_fn.rs b/cot-macros/src/main_fn.rs similarity index 66% rename from flareon-macros/src/main_fn.rs rename to cot-macros/src/main_fn.rs index dee1695..3e0185f 100644 --- a/flareon-macros/src/main_fn.rs +++ b/cot-macros/src/main_fn.rs @@ -2,25 +2,24 @@ use proc_macro2::TokenStream; use quote::quote; use syn::ItemFn; -use crate::flareon_ident; +use crate::cot_ident; -pub(super) fn fn_to_flareon_main(main_function_decl: ItemFn) -> syn::Result { +pub(super) fn fn_to_cot_main(main_function_decl: ItemFn) -> syn::Result { let mut new_main_decl = main_function_decl.clone(); - new_main_decl.sig.ident = - syn::Ident::new("__flareon_main", main_function_decl.sig.ident.span()); + new_main_decl.sig.ident = syn::Ident::new("__cot_main", main_function_decl.sig.ident.span()); if !main_function_decl.sig.inputs.is_empty() { return Err(syn::Error::new_spanned( main_function_decl.sig.inputs, - "flareon::main function must have zero arguments", + "cot::main function must have zero arguments", )); } - let crate_name = flareon_ident(); + let crate_name = cot_ident(); let result = quote! { fn main() { let body = async { - let project: #crate_name::FlareonProject = __flareon_main().await.unwrap(); + let project: #crate_name::CotProject = __cot_main().await.unwrap(); #crate_name::run_cli(project).await.unwrap(); #new_main_decl diff --git a/flareon-macros/src/model.rs b/cot-macros/src/model.rs similarity index 97% rename from flareon-macros/src/model.rs rename to cot-macros/src/model.rs index 288868d..ca21eaf 100644 --- a/flareon-macros/src/model.rs +++ b/cot-macros/src/model.rs @@ -1,12 +1,12 @@ +use cot_codegen::model::{Field, Model, ModelArgs, ModelOpts}; use darling::ast::NestedMeta; use darling::FromMeta; -use flareon_codegen::model::{Field, Model, ModelArgs, ModelOpts}; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote, ToTokens, TokenStreamExt}; use syn::punctuated::Punctuated; use syn::Token; -use crate::flareon_ident; +use crate::cot_ident; #[must_use] pub(super) fn impl_model_for_struct( @@ -143,7 +143,7 @@ impl ModelBuilder { #[must_use] fn build_model_impl(&self) -> TokenStream { - let crate_ident = flareon_ident(); + let crate_ident = cot_ident(); let orm_ident = orm_ident(); let name = &self.name; @@ -236,6 +236,6 @@ impl ModelBuilder { #[must_use] fn orm_ident() -> TokenStream { - let crate_ident = flareon_ident(); + let crate_ident = cot_ident(); quote! { #crate_ident::db } } diff --git a/flareon-macros/src/query.rs b/cot-macros/src/query.rs similarity index 95% rename from flareon-macros/src/query.rs rename to cot-macros/src/query.rs index 5e0b455..df740ff 100644 --- a/flareon-macros/src/query.rs +++ b/cot-macros/src/query.rs @@ -1,10 +1,10 @@ -use flareon_codegen::expr::Expr; +use cot_codegen::expr::Expr; use proc_macro2::TokenStream; use quote::{format_ident, quote}; use syn::parse::{Parse, ParseStream}; use syn::Token; -use crate::flareon_ident; +use crate::cot_ident; #[derive(Debug)] pub struct Query { @@ -24,7 +24,7 @@ impl Parse for Query { } pub(super) fn query_to_tokens(query: Query) -> TokenStream { - let crate_name = flareon_ident(); + let crate_name = cot_ident(); let model_name = query.model_name; let expr = expr_to_tokens(&model_name, query.expr); @@ -38,7 +38,7 @@ pub(super) fn expr_to_tokens(model_name: &syn::Type, expr: Expr) -> TokenStream return tokens; } - let crate_name = flareon_ident(); + let crate_name = cot_ident(); match expr { Expr::FieldRef { field_name, .. } => { quote!(<#model_name as #crate_name::db::Model>::Fields::#field_name.as_expr()) @@ -96,7 +96,7 @@ fn handle_binary_comparison( bin_fn: &str, bin_trait: &str, ) -> TokenStream { - let crate_name = flareon_ident(); + let crate_name = cot_ident(); let bin_fn = format_ident!("{}", bin_fn); let bin_trait = format_ident!("{}", bin_trait); diff --git a/flareon-macros/tests/compile_tests.rs b/cot-macros/tests/compile_tests.rs similarity index 100% rename from flareon-macros/tests/compile_tests.rs rename to cot-macros/tests/compile_tests.rs diff --git a/cot-macros/tests/ui/attr_main.rs b/cot-macros/tests/ui/attr_main.rs new file mode 100644 index 0000000..1bade82 --- /dev/null +++ b/cot-macros/tests/ui/attr_main.rs @@ -0,0 +1,6 @@ +use cot::CotProject; + +#[cot::main] +async fn main() -> cot::Result { + std::process::exit(0); +} diff --git a/cot-macros/tests/ui/attr_main_args.rs b/cot-macros/tests/ui/attr_main_args.rs new file mode 100644 index 0000000..4a199d9 --- /dev/null +++ b/cot-macros/tests/ui/attr_main_args.rs @@ -0,0 +1,4 @@ +#[cot::main] +async fn main(arg: i32) -> cot::Result { + std::process::exit(0); +} diff --git a/flareon-macros/tests/ui/attr_main_args.stderr b/cot-macros/tests/ui/attr_main_args.stderr similarity index 67% rename from flareon-macros/tests/ui/attr_main_args.stderr rename to cot-macros/tests/ui/attr_main_args.stderr index f5cf275..6e579eb 100644 --- a/flareon-macros/tests/ui/attr_main_args.stderr +++ b/cot-macros/tests/ui/attr_main_args.stderr @@ -1,7 +1,7 @@ -error: flareon::main function must have zero arguments +error: cot::main function must have zero arguments --> tests/ui/attr_main_args.rs:2:15 | -2 | async fn main(arg: i32) -> flareon::Result { +2 | async fn main(arg: i32) -> cot::Result { | ^^^^^^^^ error[E0601]: `main` function not found in crate `$CRATE` diff --git a/flareon-macros/tests/ui/attr_model.rs b/cot-macros/tests/ui/attr_model.rs similarity index 85% rename from flareon-macros/tests/ui/attr_model.rs rename to cot-macros/tests/ui/attr_model.rs index 0b7f457..ab581c2 100644 --- a/flareon-macros/tests/ui/attr_model.rs +++ b/cot-macros/tests/ui/attr_model.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, Model}; +use cot::db::{model, Model}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/attr_model_enum.rs b/cot-macros/tests/ui/attr_model_enum.rs similarity index 81% rename from flareon-macros/tests/ui/attr_model_enum.rs rename to cot-macros/tests/ui/attr_model_enum.rs index 41f7d23..5bc84f2 100644 --- a/flareon-macros/tests/ui/attr_model_enum.rs +++ b/cot-macros/tests/ui/attr_model_enum.rs @@ -1,4 +1,4 @@ -use flareon::db::model; +use cot::db::model; #[model] enum MyModel { diff --git a/flareon-macros/tests/ui/attr_model_enum.stderr b/cot-macros/tests/ui/attr_model_enum.stderr similarity index 100% rename from flareon-macros/tests/ui/attr_model_enum.stderr rename to cot-macros/tests/ui/attr_model_enum.stderr diff --git a/flareon-macros/tests/ui/attr_model_generic.rs b/cot-macros/tests/ui/attr_model_generic.rs similarity index 76% rename from flareon-macros/tests/ui/attr_model_generic.rs rename to cot-macros/tests/ui/attr_model_generic.rs index 4cb57ed..0a50e22 100644 --- a/flareon-macros/tests/ui/attr_model_generic.rs +++ b/cot-macros/tests/ui/attr_model_generic.rs @@ -1,4 +1,4 @@ -use flareon::db::model; +use cot::db::model; #[model] struct MyModel { diff --git a/flareon-macros/tests/ui/attr_model_generic.stderr b/cot-macros/tests/ui/attr_model_generic.stderr similarity index 100% rename from flareon-macros/tests/ui/attr_model_generic.stderr rename to cot-macros/tests/ui/attr_model_generic.stderr diff --git a/flareon-macros/tests/ui/attr_model_migration_invalid_name.rs b/cot-macros/tests/ui/attr_model_migration_invalid_name.rs similarity index 86% rename from flareon-macros/tests/ui/attr_model_migration_invalid_name.rs rename to cot-macros/tests/ui/attr_model_migration_invalid_name.rs index f855a00..2bfb5e1 100644 --- a/flareon-macros/tests/ui/attr_model_migration_invalid_name.rs +++ b/cot-macros/tests/ui/attr_model_migration_invalid_name.rs @@ -1,4 +1,4 @@ -use flareon::db::model; +use cot::db::model; #[model(model_type = "migration")] struct MyModel { diff --git a/flareon-macros/tests/ui/attr_model_migration_invalid_name.stderr b/cot-macros/tests/ui/attr_model_migration_invalid_name.stderr similarity index 100% rename from flareon-macros/tests/ui/attr_model_migration_invalid_name.stderr rename to cot-macros/tests/ui/attr_model_migration_invalid_name.stderr diff --git a/flareon-macros/tests/ui/attr_model_multiple_pks.rs b/cot-macros/tests/ui/attr_model_multiple_pks.rs similarity index 82% rename from flareon-macros/tests/ui/attr_model_multiple_pks.rs rename to cot-macros/tests/ui/attr_model_multiple_pks.rs index 614ca7f..91cc1f3 100644 --- a/flareon-macros/tests/ui/attr_model_multiple_pks.rs +++ b/cot-macros/tests/ui/attr_model_multiple_pks.rs @@ -1,4 +1,4 @@ -use flareon::db::model; +use cot::db::model; #[model] struct MyModel { diff --git a/flareon-macros/tests/ui/attr_model_multiple_pks.stderr b/cot-macros/tests/ui/attr_model_multiple_pks.stderr similarity index 100% rename from flareon-macros/tests/ui/attr_model_multiple_pks.stderr rename to cot-macros/tests/ui/attr_model_multiple_pks.stderr diff --git a/flareon-macros/tests/ui/attr_model_no_pk.rs b/cot-macros/tests/ui/attr_model_no_pk.rs similarity index 75% rename from flareon-macros/tests/ui/attr_model_no_pk.rs rename to cot-macros/tests/ui/attr_model_no_pk.rs index 4c8114d..2f85ec8 100644 --- a/flareon-macros/tests/ui/attr_model_no_pk.rs +++ b/cot-macros/tests/ui/attr_model_no_pk.rs @@ -1,4 +1,4 @@ -use flareon::db::model; +use cot::db::model; #[model] struct MyModel { diff --git a/flareon-macros/tests/ui/attr_model_no_pk.stderr b/cot-macros/tests/ui/attr_model_no_pk.stderr similarity index 100% rename from flareon-macros/tests/ui/attr_model_no_pk.stderr rename to cot-macros/tests/ui/attr_model_no_pk.stderr diff --git a/flareon-macros/tests/ui/attr_model_tuple.rs b/cot-macros/tests/ui/attr_model_tuple.rs similarity index 76% rename from flareon-macros/tests/ui/attr_model_tuple.rs rename to cot-macros/tests/ui/attr_model_tuple.rs index 76bb170..a51b997 100644 --- a/flareon-macros/tests/ui/attr_model_tuple.rs +++ b/cot-macros/tests/ui/attr_model_tuple.rs @@ -1,4 +1,4 @@ -use flareon::db::model; +use cot::db::model; #[model] struct MyModel(i32, std::string::String, String, i32); diff --git a/flareon-macros/tests/ui/attr_model_tuple.stderr b/cot-macros/tests/ui/attr_model_tuple.stderr similarity index 100% rename from flareon-macros/tests/ui/attr_model_tuple.stderr rename to cot-macros/tests/ui/attr_model_tuple.stderr diff --git a/flareon-macros/tests/ui/derive_form.rs b/cot-macros/tests/ui/derive_form.rs similarity index 84% rename from flareon-macros/tests/ui/derive_form.rs rename to cot-macros/tests/ui/derive_form.rs index 8cd6f80..1732d94 100644 --- a/flareon-macros/tests/ui/derive_form.rs +++ b/cot-macros/tests/ui/derive_form.rs @@ -1,5 +1,5 @@ -use flareon::forms::Form; -use flareon::request::Request; +use cot::forms::Form; +use cot::request::Request; #[derive(Debug, Form)] struct MyForm { diff --git a/flareon-macros/tests/ui/func_query.rs b/cot-macros/tests/ui/func_query.rs similarity index 88% rename from flareon-macros/tests/ui/func_query.rs rename to cot-macros/tests/ui/func_query.rs index 49c62de..6d7b965 100644 --- a/flareon-macros/tests/ui/func_query.rs +++ b/cot-macros/tests/ui/func_query.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, query}; +use cot::db::{model, query}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/func_query_double_field.rs b/cot-macros/tests/ui/func_query_double_field.rs similarity index 86% rename from flareon-macros/tests/ui/func_query_double_field.rs rename to cot-macros/tests/ui/func_query_double_field.rs index 4070f85..68b1c35 100644 --- a/flareon-macros/tests/ui/func_query_double_field.rs +++ b/cot-macros/tests/ui/func_query_double_field.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, query}; +use cot::db::{model, query}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/func_query_double_field.stderr b/cot-macros/tests/ui/func_query_double_field.stderr similarity index 100% rename from flareon-macros/tests/ui/func_query_double_field.stderr rename to cot-macros/tests/ui/func_query_double_field.stderr diff --git a/flareon-macros/tests/ui/func_query_double_op.rs b/cot-macros/tests/ui/func_query_double_op.rs similarity index 88% rename from flareon-macros/tests/ui/func_query_double_op.rs rename to cot-macros/tests/ui/func_query_double_op.rs index 0b57ad7..33c3f61 100644 --- a/flareon-macros/tests/ui/func_query_double_op.rs +++ b/cot-macros/tests/ui/func_query_double_op.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, query}; +use cot::db::{model, query}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/func_query_double_op.stderr b/cot-macros/tests/ui/func_query_double_op.stderr similarity index 100% rename from flareon-macros/tests/ui/func_query_double_op.stderr rename to cot-macros/tests/ui/func_query_double_op.stderr diff --git a/flareon-macros/tests/ui/func_query_invalid_field.rs b/cot-macros/tests/ui/func_query_invalid_field.rs similarity index 86% rename from flareon-macros/tests/ui/func_query_invalid_field.rs rename to cot-macros/tests/ui/func_query_invalid_field.rs index 78ee74a..e16c3cc 100644 --- a/flareon-macros/tests/ui/func_query_invalid_field.rs +++ b/cot-macros/tests/ui/func_query_invalid_field.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, query}; +use cot::db::{model, query}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/func_query_invalid_field.stderr b/cot-macros/tests/ui/func_query_invalid_field.stderr similarity index 100% rename from flareon-macros/tests/ui/func_query_invalid_field.stderr rename to cot-macros/tests/ui/func_query_invalid_field.stderr diff --git a/flareon-macros/tests/ui/func_query_method_call_on_db_field.rs b/cot-macros/tests/ui/func_query_method_call_on_db_field.rs similarity index 84% rename from flareon-macros/tests/ui/func_query_method_call_on_db_field.rs rename to cot-macros/tests/ui/func_query_method_call_on_db_field.rs index 51dc7a7..b1ee18e 100644 --- a/flareon-macros/tests/ui/func_query_method_call_on_db_field.rs +++ b/cot-macros/tests/ui/func_query_method_call_on_db_field.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, query}; +use cot::db::{model, query}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/func_query_method_call_on_db_field.stderr b/cot-macros/tests/ui/func_query_method_call_on_db_field.stderr similarity index 100% rename from flareon-macros/tests/ui/func_query_method_call_on_db_field.stderr rename to cot-macros/tests/ui/func_query_method_call_on_db_field.stderr diff --git a/flareon-macros/tests/ui/func_query_starting_op.rs b/cot-macros/tests/ui/func_query_starting_op.rs similarity index 86% rename from flareon-macros/tests/ui/func_query_starting_op.rs rename to cot-macros/tests/ui/func_query_starting_op.rs index b6f8998..a120790 100644 --- a/flareon-macros/tests/ui/func_query_starting_op.rs +++ b/cot-macros/tests/ui/func_query_starting_op.rs @@ -1,4 +1,4 @@ -use flareon::db::{model, query}; +use cot::db::{model, query}; #[derive(Debug)] #[model] diff --git a/flareon-macros/tests/ui/func_query_starting_op.stderr b/cot-macros/tests/ui/func_query_starting_op.stderr similarity index 100% rename from flareon-macros/tests/ui/func_query_starting_op.stderr rename to cot-macros/tests/ui/func_query_starting_op.stderr diff --git a/flareon/Cargo.toml b/cot/Cargo.toml similarity index 98% rename from flareon/Cargo.toml rename to cot/Cargo.toml index 536f5fd..305939a 100644 --- a/flareon/Cargo.toml +++ b/cot/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "flareon" +name = "cot" version = "0.1.0" edition.workspace = true license.workspace = true @@ -17,7 +17,7 @@ chrono.workspace = true derive_builder.workspace = true derive_more = { workspace = true, features = ["debug", "deref", "display", "from"] } fake = { workspace = true, optional = true, features = ["derive", "chrono"] } -flareon_macros.workspace = true +cot_macros.workspace = true form_urlencoded.workspace = true futures-core.workspace = true futures-util.workspace = true diff --git a/flareon/build.rs b/cot/build.rs similarity index 100% rename from flareon/build.rs rename to cot/build.rs diff --git a/flareon/src/admin.rs b/cot/src/admin.rs similarity index 89% rename from flareon/src/admin.rs rename to cot/src/admin.rs index a388608..bcc9f4c 100644 --- a/flareon/src/admin.rs +++ b/cot/src/admin.rs @@ -18,7 +18,7 @@ use crate::forms::{ use crate::request::{Request, RequestExt}; use crate::response::{Response, ResponseExt}; use crate::router::Router; -use crate::{reverse, static_files, Body, FlareonApp, Render, StatusCode}; +use crate::{reverse, static_files, Body, CotApp, Render, StatusCode}; #[derive(Debug, Form)] struct LoginForm { @@ -49,7 +49,7 @@ struct ModelTemplate<'a> { objects: Vec>, } -async fn index(mut request: Request) -> flareon::Result { +async fn index(mut request: Request) -> cot::Result { if request.user().await?.is_authenticated() { let template = ModelListTemplate { request: &request, @@ -64,7 +64,7 @@ async fn index(mut request: Request) -> flareon::Result { } } -async fn login(mut request: Request) -> flareon::Result { +async fn login(mut request: Request) -> cot::Result { let login_form_context = if request.method() == http::Method::GET { LoginForm::build_context(&mut request).await? } else if request.method() == http::Method::POST { @@ -98,13 +98,13 @@ async fn login(mut request: Request) -> flareon::Result { )) } -async fn authenticate(request: &mut Request, login_form: LoginForm) -> flareon::Result { +async fn authenticate(request: &mut Request, login_form: LoginForm) -> cot::Result { #[cfg(feature = "db")] let user = request .authenticate(&crate::auth::db::DatabaseUserCredentials::new( login_form.username, // TODO unify auth::Password and forms::fields::Password - flareon::auth::Password::new(login_form.password.into_string()), + cot::auth::Password::new(login_form.password.into_string()), )) .await?; @@ -119,7 +119,7 @@ async fn authenticate(request: &mut Request, login_form: LoginForm) -> flareon:: } } -async fn view_model(mut request: Request) -> flareon::Result { +async fn view_model(mut request: Request) -> cot::Result { if request.user().await?.is_authenticated() { // TODO use a nice URL parser instead of unwrap let model_name = request.path_params().get("model_name").unwrap(); @@ -159,7 +159,7 @@ pub trait AdminModelManager: Send + Sync { fn url_name(&self) -> &str; - async fn get_objects(&self, request: &Request) -> flareon::Result>>; + async fn get_objects(&self, request: &Request) -> cot::Result>>; } #[derive(Debug)] @@ -192,7 +192,7 @@ impl AdminModelManager for DefaultAdminMo T::url_name() } - async fn get_objects(&self, request: &Request) -> flareon::Result>> { + async fn get_objects(&self, request: &Request) -> cot::Result>> { #[allow(trivial_casts)] // Upcast to the correct Box type T::get_objects(request).await.map(|objects| { objects @@ -205,7 +205,7 @@ impl AdminModelManager for DefaultAdminMo #[async_trait] pub trait AdminModel { - async fn get_objects(request: &Request) -> flareon::Result> + async fn get_objects(request: &Request) -> cot::Result> where Self: Sized; @@ -236,9 +236,9 @@ impl AdminApp { } } -impl FlareonApp for AdminApp { +impl CotApp for AdminApp { fn name(&self) -> &'static str { - "flareon_admin" + "cot_admin" } fn router(&self) -> Router { diff --git a/flareon/src/auth.rs b/cot/src/auth.rs similarity index 97% rename from flareon/src/auth.rs rename to cot/src/auth.rs index f67e6d1..12525d5 100644 --- a/flareon/src/auth.rs +++ b/cot/src/auth.rs @@ -1,6 +1,6 @@ -//! Authentication system for Flareon. +//! Authentication system for Cot. //! -//! This module provides the authentication system for Flareon. It includes +//! This module provides the authentication system for Cot. It includes //! traits for user objects and backends, as well as password hashing and //! verification. //! @@ -57,7 +57,7 @@ pub type Result = std::result::Result; /// A concrete instance of a `User` object is returned by a backend that /// implements the [`AuthBackend`] trait. The default backend is the /// [`DatabaseUserBackend`](db::DatabaseUserBackend), which stores user data in -/// the database using Flareon ORM. +/// the database using Cot ORM. #[cfg_attr(test, automock)] pub trait User { /// Returns the user's ID. @@ -274,7 +274,7 @@ impl PasswordHash { /// # Examples /// /// ``` - /// use flareon::auth::{Password, PasswordHash}; + /// use cot::auth::{Password, PasswordHash}; /// /// let hash = PasswordHash::from_password(&Password::new("password")); /// let stored_hash = hash.into_string(); @@ -302,7 +302,7 @@ impl PasswordHash { /// # Examples /// /// ``` - /// use flareon::auth::{Password, PasswordHash}; + /// use cot::auth::{Password, PasswordHash}; /// /// let hash = PasswordHash::from_password(&Password::new("password")); /// ``` @@ -327,7 +327,7 @@ impl PasswordHash { /// # Examples /// /// ``` - /// use flareon::auth::{Password, PasswordHash, PasswordVerificationResult}; + /// use cot::auth::{Password, PasswordHash, PasswordVerificationResult}; /// /// let password = Password::new("password"); /// let hash = PasswordHash::from_password(&password); @@ -411,15 +411,13 @@ impl DatabaseField for PasswordHash { #[cfg(feature = "db")] impl FromDbValue for PasswordHash { #[cfg(feature = "sqlite")] - fn from_sqlite(value: crate::db::impl_sqlite::SqliteValueRef) -> flareon::db::Result { - PasswordHash::new(value.get::()?).map_err(flareon::db::DatabaseError::value_decode) + fn from_sqlite(value: crate::db::impl_sqlite::SqliteValueRef) -> cot::db::Result { + PasswordHash::new(value.get::()?).map_err(cot::db::DatabaseError::value_decode) } #[cfg(feature = "postgres")] - fn from_postgres( - value: crate::db::impl_postgres::PostgresValueRef, - ) -> flareon::db::Result { - PasswordHash::new(value.get::()?).map_err(flareon::db::DatabaseError::value_decode) + fn from_postgres(value: crate::db::impl_postgres::PostgresValueRef) -> cot::db::Result { + PasswordHash::new(value.get::()?).map_err(cot::db::DatabaseError::value_decode) } #[cfg(feature = "mysql")] @@ -427,7 +425,7 @@ impl FromDbValue for PasswordHash { where Self: Sized, { - PasswordHash::new(value.get::()?).map_err(flareon::db::DatabaseError::value_decode) + PasswordHash::new(value.get::()?).map_err(cot::db::DatabaseError::value_decode) } } @@ -454,7 +452,7 @@ impl ToDbValue for PasswordHash { /// # Examples /// /// ``` -/// use flareon::auth::Password; +/// use cot::auth::Password; /// /// let password = Password::new("pass"); /// assert_eq!(&format!("{:?}", password), "Password(\"**********\")"); @@ -474,7 +472,7 @@ impl Password { /// # Examples /// /// ``` - /// use flareon::auth::Password; + /// use cot::auth::Password; /// /// let password = Password::new("password"); /// ``` @@ -582,8 +580,8 @@ pub trait AuthRequestExt: private::Sealed { async fn logout(&mut self) -> Result<()>; } -const USER_ID_SESSION_KEY: &str = "__flareon_auth_user_id"; -const SESSION_HASH_SESSION_KEY: &str = "__flareon_auth_session_hash"; +const USER_ID_SESSION_KEY: &str = "__cot_auth_user_id"; +const SESSION_HASH_SESSION_KEY: &str = "__cot_auth_session_hash"; type UserExtension = Arc; diff --git a/flareon/src/auth/db.rs b/cot/src/auth/db.rs similarity index 95% rename from flareon/src/auth/db.rs rename to cot/src/auth/db.rs index f791321..62fa5b4 100644 --- a/flareon/src/auth/db.rs +++ b/cot/src/auth/db.rs @@ -1,12 +1,12 @@ //! Database-backed user authentication backend. //! //! This module provides a user type and an authentication backend that stores -//! the user data in a database using the Flareon ORM. +//! the user data in a database using the Cot ORM. use std::any::Any; use async_trait::async_trait; -use flareon_macros::model; +use cot_macros::model; use hmac::{Hmac, KeyInit, Mac}; use sha2::Sha512; use thiserror::Error; @@ -20,7 +20,7 @@ use crate::config::SecretKey; use crate::db::migrations::DynMigration; use crate::db::{query, DatabaseBackend, LimitedString, Model}; use crate::request::{Request, RequestExt}; -use crate::FlareonApp; +use crate::CotApp; pub mod migrations; @@ -62,13 +62,13 @@ impl DatabaseUser { /// # Example /// /// ``` - /// use flareon::auth::db::DatabaseUser; - /// use flareon::auth::Password; - /// use flareon::request::{Request, RequestExt}; - /// use flareon::response::{Response, ResponseExt}; - /// use flareon::{Body, StatusCode}; + /// use cot::auth::db::DatabaseUser; + /// use cot::auth::Password; + /// use cot::request::{Request, RequestExt}; + /// use cot::response::{Response, ResponseExt}; + /// use cot::{Body, StatusCode}; /// - /// async fn view(request: &Request) -> flareon::Result { + /// async fn view(request: &Request) -> cot::Result { /// let user = DatabaseUser::create_user( /// request.db(), /// "testuser".to_string(), @@ -83,8 +83,8 @@ impl DatabaseUser { /// } /// /// # #[tokio::main] - /// # async fn main() -> flareon::Result<()> { - /// # use flareon::test::{TestDatabase, TestRequestBuilder}; + /// # async fn main() -> cot::Result<()> { + /// # use cot::test::{TestDatabase, TestRequestBuilder}; /// # let mut test_database = TestDatabase::new_sqlite().await?; /// # test_database.with_auth().run_migrations().await; /// # let request = TestRequestBuilder::get("/") @@ -272,7 +272,7 @@ impl DatabaseUserCredentials { /// The authentication backend for users stored in the database. /// -/// This is the default authentication backend for Flareon. It authenticates +/// This is the default authentication backend for Cot. It authenticates /// users stored in the database using the [`DatabaseUser`] model. /// /// This backend supports authenticating users using the @@ -292,8 +292,8 @@ impl DatabaseUserBackend { /// # Example /// /// ``` - /// use flareon::auth::db::DatabaseUserBackend; - /// use flareon::config::ProjectConfig; + /// use cot::auth::db::DatabaseUserBackend; + /// use cot::config::ProjectConfig; /// /// let backend = DatabaseUserBackend::new(); /// let config = ProjectConfig::builder().auth_backend(backend).build(); @@ -349,9 +349,9 @@ impl DatabaseUserApp { } } -impl FlareonApp for DatabaseUserApp { +impl CotApp for DatabaseUserApp { fn name(&self) -> &'static str { - "flareon_db_user" + "cot_db_user" } fn admin_model_managers(&self) -> Vec> { diff --git a/cot/src/auth/db/migrations.rs b/cot/src/auth/db/migrations.rs new file mode 100644 index 0000000..8207b8d --- /dev/null +++ b/cot/src/auth/db/migrations.rs @@ -0,0 +1,3 @@ +mod m_0001_initial; + +pub const MIGRATIONS: &[&dyn ::cot::db::migrations::DynMigration] = &[&m_0001_initial::Migration]; diff --git a/cot/src/auth/db/migrations/m_0001_initial.rs b/cot/src/auth/db/migrations/m_0001_initial.rs new file mode 100644 index 0000000..15fcd19 --- /dev/null +++ b/cot/src/auth/db/migrations/m_0001_initial.rs @@ -0,0 +1,53 @@ +//! Generated by cot CLI 0.1.0 on 2024-11-12 15:49:48+00:00 + +#[derive(Debug, Copy, Clone)] +pub(super) struct Migration; +impl ::cot::db::migrations::Migration for Migration { + const APP_NAME: &'static str = "cot_auth"; + const MIGRATION_NAME: &'static str = "m_0001_initial"; + const DEPENDENCIES: &'static [::cot::db::migrations::MigrationDependency] = &[]; + const OPERATIONS: &'static [::cot::db::migrations::Operation] = &[ + ::cot::db::migrations::Operation::create_model() + .table_name(::cot::db::Identifier::new("database_user")) + .fields( + &[ + ::cot::db::migrations::Field::new( + ::cot::db::Identifier::new("id"), + ::TYPE, + ) + .auto() + .primary_key() + .set_null(::NULLABLE), + ::cot::db::migrations::Field::new( + ::cot::db::Identifier::new("username"), + as ::cot::db::DatabaseField>::TYPE, + ) + .set_null( + as ::cot::db::DatabaseField>::NULLABLE, + ) + .unique(), + ::cot::db::migrations::Field::new( + ::cot::db::Identifier::new("password"), + ::TYPE, + ) + .set_null( + ::NULLABLE, + ), + ], + ) + .build(), + ]; +} + +#[derive(::core::fmt::Debug)] +#[::cot::db::model(model_type = "migration")] +struct _DatabaseUser { + id: i64, + #[model(unique)] + username: crate::db::LimitedString<{ crate::auth::db::MAX_USERNAME_LENGTH }>, + password: crate::auth::PasswordHash, +} diff --git a/flareon/src/config.rs b/cot/src/config.rs similarity index 98% rename from flareon/src/config.rs rename to cot/src/config.rs index 2f4e872..a41ff00 100644 --- a/flareon/src/config.rs +++ b/cot/src/config.rs @@ -8,7 +8,7 @@ //! The main struct in this module is [`ProjectConfig`], which contains all the //! configuration data for the project. After creating an instance using //! [`ProjectConfigBuilder`], it can be passed to the -//! [`FlareonProject`](crate::FlareonProject). +//! [`CotProject`](crate::CotProject). use std::sync::Arc; @@ -132,7 +132,7 @@ fn default_auth_backend() -> Arc { #[cfg(not(any(feature = "sqlite", feature = "postgres", feature = "mysql")))] { - Arc::new(flareon::auth::NoAuthBackend) + Arc::new(cot::auth::NoAuthBackend) } } diff --git a/flareon/src/db.rs b/cot/src/db.rs similarity index 99% rename from flareon/src/db.rs rename to cot/src/db.rs index bb52b71..8429ded 100644 --- a/flareon/src/db.rs +++ b/cot/src/db.rs @@ -19,8 +19,8 @@ use std::fmt::Write; use std::hash::Hash; use async_trait::async_trait; +pub use cot_macros::{model, query}; use derive_more::{Debug, Deref, Display}; -pub use flareon_macros::{model, query}; #[cfg(test)] use mockall::automock; use query::Query; @@ -89,7 +89,7 @@ pub type Result = std::result::Result; /// the implementation of the `Fields` helper struct. /// /// ```rust -/// use flareon::db::model; +/// use cot::db::model; /// /// #[model] /// struct MyModel { @@ -458,7 +458,7 @@ impl Database { /// # Examples /// /// ``` - /// use flareon::db::Database; + /// use cot::db::Database; /// /// #[tokio::main] /// async fn main() { @@ -512,7 +512,7 @@ impl Database { /// # Examples /// /// ``` - /// use flareon::db::Database; + /// use cot::db::Database; /// /// #[tokio::main] /// async fn main() { @@ -918,10 +918,10 @@ pub struct RowsNum(pub u64); /// # Examples /// /// ``` -/// use flareon::db::{model, Auto, Model}; -/// # use flareon::db::migrations::{Field, Operation}; -/// # use flareon::db::{Database, Identifier, DatabaseField}; -/// # use flareon::Result; +/// use cot::db::{model, Auto, Model}; +/// # use cot::db::migrations::{Field, Operation}; +/// # use cot::db::{Database, Identifier, DatabaseField}; +/// # use cot::Result; /// /// #[model] /// struct MyModel { @@ -1001,7 +1001,7 @@ impl From for Auto { /// # Examples /// /// ``` -/// use flareon::db::LimitedString; +/// use cot::db::LimitedString; /// /// let limited_string = LimitedString::<5>::new("test").unwrap(); /// assert_eq!(limited_string, "test"); diff --git a/flareon/src/db/fields.rs b/cot/src/db/fields.rs similarity index 99% rename from flareon/src/db/fields.rs rename to cot/src/db/fields.rs index cc845f5..9e782d4 100644 --- a/flareon/src/db/fields.rs +++ b/cot/src/db/fields.rs @@ -1,6 +1,6 @@ //! `DatabaseField` implementations for common types. -use flareon::db::DatabaseField; +use cot::db::DatabaseField; #[cfg(feature = "mysql")] use crate::db::impl_mysql::MySqlValueRef; diff --git a/flareon/src/db/impl_mysql.rs b/cot/src/db/impl_mysql.rs similarity index 100% rename from flareon/src/db/impl_mysql.rs rename to cot/src/db/impl_mysql.rs diff --git a/flareon/src/db/impl_postgres.rs b/cot/src/db/impl_postgres.rs similarity index 100% rename from flareon/src/db/impl_postgres.rs rename to cot/src/db/impl_postgres.rs diff --git a/flareon/src/db/impl_sqlite.rs b/cot/src/db/impl_sqlite.rs similarity index 100% rename from flareon/src/db/impl_sqlite.rs rename to cot/src/db/impl_sqlite.rs diff --git a/flareon/src/db/migrations.rs b/cot/src/db/migrations.rs similarity index 96% rename from flareon/src/db/migrations.rs rename to cot/src/db/migrations.rs index f307dfd..9722f7d 100644 --- a/flareon/src/db/migrations.rs +++ b/cot/src/db/migrations.rs @@ -3,7 +3,7 @@ mod sorter; use std::fmt; use std::fmt::{Debug, Formatter}; -use flareon::db::relations::ForeignKeyOnUpdatePolicy; +use cot::db::relations::ForeignKeyOnUpdatePolicy; use sea_query::{ColumnDef, StringLen}; use thiserror::Error; use tracing::info; @@ -53,7 +53,7 @@ impl MigrationEngine { /// Runs the migrations. If a migration is already applied, it will be /// skipped. /// - /// This method will also create the `flareon__migrations` table if it does + /// This method will also create the `cot__migrations` table if it does /// not exist that is used to keep track of which migrations have been /// applied. /// @@ -66,11 +66,9 @@ impl MigrationEngine { /// # Examples /// /// ``` - /// use flareon::db::migrations::{ - /// Field, Migration, MigrationDependency, MigrationEngine, Operation, - /// }; - /// use flareon::db::{Database, DatabaseField, Identifier}; - /// use flareon::Result; + /// use cot::db::migrations::{Field, Migration, MigrationDependency, MigrationEngine, Operation}; + /// use cot::db::{Database, DatabaseField, Identifier}; + /// use cot::Result; /// /// struct MyMigration; /// @@ -161,9 +159,9 @@ impl MigrationEngine { /// # Examples /// /// ``` -/// use flareon::db::migrations::{Field, Migration, MigrationEngine, Operation}; -/// use flareon::db::{Database, DatabaseField, Identifier}; -/// use flareon::Result; +/// use cot::db::migrations::{Field, Migration, MigrationEngine, Operation}; +/// use cot::db::{Database, DatabaseField, Identifier}; +/// use cot::Result; /// /// # #[tokio::main] /// # async fn main() -> Result<()> { @@ -214,9 +212,9 @@ impl Operation { /// # Examples /// /// ``` - /// use flareon::db::migrations::{Field, Migration, MigrationEngine, Operation}; - /// use flareon::db::{Database, DatabaseField, Identifier}; - /// use flareon::Result; + /// use cot::db::migrations::{Field, Migration, MigrationEngine, Operation}; + /// use cot::db::{Database, DatabaseField, Identifier}; + /// use cot::Result; /// /// # #[tokio::main] /// # async fn main() -> Result<()> { @@ -283,9 +281,9 @@ impl Operation { /// # Examples /// /// ``` - /// use flareon::db::migrations::{Field, Migration, MigrationEngine, Operation}; - /// use flareon::db::{Database, DatabaseField, Identifier}; - /// use flareon::Result; + /// use cot::db::migrations::{Field, Migration, MigrationEngine, Operation}; + /// use cot::db::{Database, DatabaseField, Identifier}; + /// use cot::Result; /// /// # #[tokio::main] /// # async fn main() -> Result<()> { @@ -743,7 +741,7 @@ impl MigrationDependency { } #[derive(Debug)] -#[model(table_name = "flareon__migrations", model_type = "internal")] +#[model(table_name = "cot__migrations", model_type = "internal")] struct AppliedMigration { id: i32, app: String, @@ -752,7 +750,7 @@ struct AppliedMigration { } const CREATE_APPLIED_MIGRATIONS_MIGRATION: Operation = Operation::create_model() - .table_name(Identifier::new("flareon__migrations")) + .table_name(Identifier::new("cot__migrations")) .fields(&[ Field::new(Identifier::new("id"), ::TYPE) .primary_key() @@ -769,7 +767,7 @@ const CREATE_APPLIED_MIGRATIONS_MIGRATION: Operation = Operation::create_model() #[cfg(test)] mod tests { - use flareon::test::TestDatabase; + use cot::test::TestDatabase; use sea_query::ColumnSpec; use super::*; @@ -792,7 +790,7 @@ mod tests { .build()]; } - #[flareon_macros::dbtest] + #[cot_macros::dbtest] async fn test_migration_engine_run(test_db: &mut TestDatabase) { let engine = MigrationEngine::new([TestMigration]).unwrap(); diff --git a/flareon/src/db/migrations/sorter.rs b/cot/src/db/migrations/sorter.rs similarity index 99% rename from flareon/src/db/migrations/sorter.rs rename to cot/src/db/migrations/sorter.rs index b3f7ace..f32c2e9 100644 --- a/flareon/src/db/migrations/sorter.rs +++ b/cot/src/db/migrations/sorter.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use flareon::db::migrations::MigrationDependency; +use cot::db::migrations::MigrationDependency; use thiserror::Error; use crate::db::migrations::{DynMigration, MigrationDependencyInner, OperationInner}; @@ -10,7 +10,7 @@ use crate::utils::graph::{apply_permutation, Graph}; #[non_exhaustive] pub enum MigrationSorterError { #[error("Cycle detected in migrations")] - CycleDetected(#[from] flareon::utils::graph::CycleDetected), + CycleDetected(#[from] cot::utils::graph::CycleDetected), #[error("Dependency not found: {}", format_migration_dependency(.0))] InvalidDependency(MigrationDependency), #[error("Migration defined twice: {app_name}::{migration_name}")] diff --git a/flareon/src/db/query.rs b/cot/src/db/query.rs similarity index 95% rename from flareon/src/db/query.rs rename to cot/src/db/query.rs index 0bd5849..5b9a659 100644 --- a/flareon/src/db/query.rs +++ b/cot/src/db/query.rs @@ -14,8 +14,8 @@ use crate::db::{ /// /// # Example /// ``` -/// use flareon::db::model; -/// use flareon::db::query::Query; +/// use cot::db::model; +/// use cot::db::query::Query; /// /// #[model] /// struct User { @@ -43,8 +43,8 @@ impl Query { /// /// # Example /// ``` - /// use flareon::db::model; - /// use flareon::db::query::Query; + /// use cot::db::model; + /// use cot::db::query::Query; /// /// #[model] /// struct User { @@ -67,8 +67,8 @@ impl Query { /// /// # Example /// ``` - /// use flareon::db::model; - /// use flareon::db::query::{Expr, Query}; + /// use cot::db::model; + /// use cot::db::query::{Expr, Query}; /// /// #[model] /// struct User { @@ -152,7 +152,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::field("name"); /// ``` @@ -167,7 +167,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::value(30); /// ``` @@ -184,7 +184,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::and( /// Expr::eq(Expr::field("name"), Expr::value("John")), @@ -201,7 +201,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::or( /// Expr::eq(Expr::field("name"), Expr::value("John")), @@ -218,7 +218,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::eq(Expr::field("name"), Expr::value("John")); /// ``` @@ -232,7 +232,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::ne(Expr::field("name"), Expr::value("John")); /// ``` @@ -246,7 +246,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::add(Expr::field("age"), Expr::value(10)); /// ``` @@ -261,7 +261,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::sub(Expr::field("age"), Expr::value(10)); /// ``` @@ -276,7 +276,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::mul(Expr::field("amount"), Expr::value(5)); /// ``` @@ -291,7 +291,7 @@ impl Expr { /// # Example /// /// ``` - /// use flareon::db::query::Expr; + /// use cot::db::query::Expr; /// /// let expr = Expr::div(Expr::field("amount"), Expr::value(5)); /// ``` @@ -451,7 +451,7 @@ impl IntoField> for &T { #[cfg(test)] mod tests { - use flareon_macros::model; + use cot_macros::model; use super::*; use crate::db::{MockDatabaseBackend, RowsNum}; diff --git a/flareon/src/db/relations.rs b/cot/src/db/relations.rs similarity index 99% rename from flareon/src/db/relations.rs rename to cot/src/db/relations.rs index e166b39..5695c9d 100644 --- a/flareon/src/db/relations.rs +++ b/cot/src/db/relations.rs @@ -1,4 +1,4 @@ -use flareon::db::DatabaseError; +use cot::db::DatabaseError; use crate::db::{DatabaseBackend, Model, Result}; diff --git a/flareon/src/db/sea_query_db.rs b/cot/src/db/sea_query_db.rs similarity index 100% rename from flareon/src/db/sea_query_db.rs rename to cot/src/db/sea_query_db.rs diff --git a/flareon/src/error.rs b/cot/src/error.rs similarity index 92% rename from flareon/src/error.rs rename to cot/src/error.rs index a47d862..69e3a8c 100644 --- a/flareon/src/error.rs +++ b/cot/src/error.rs @@ -5,16 +5,16 @@ use std::fmt::Display; use derive_more::Debug; use thiserror::Error; -// Need to rename Backtrace to FlareonBacktrace, because otherwise it triggers special behavior +// Need to rename Backtrace to CotBacktrace, because otherwise it triggers special behavior // in thiserror library -use crate::error::backtrace::{Backtrace as FlareonBacktrace, __flareon_create_backtrace}; +use crate::error::backtrace::{Backtrace as CotBacktrace, __cot_create_backtrace}; -/// An error that can occur while using Flareon. +/// An error that can occur while using Cot. #[derive(Debug)] pub struct Error { inner: ErrorRepr, #[debug(skip)] - backtrace: FlareonBacktrace, + backtrace: CotBacktrace, } impl Error { @@ -22,12 +22,12 @@ impl Error { pub(crate) fn new(inner: ErrorRepr) -> Self { Self { inner, - backtrace: __flareon_create_backtrace(), + backtrace: __cot_create_backtrace(), } } #[must_use] - pub(crate) fn backtrace(&self) -> &FlareonBacktrace { + pub(crate) fn backtrace(&self) -> &CotBacktrace { &self.backtrace } } diff --git a/flareon/src/error/backtrace.rs b/cot/src/error/backtrace.rs similarity index 96% rename from flareon/src/error/backtrace.rs rename to cot/src/error/backtrace.rs index 69af9f4..9bc27cf 100644 --- a/flareon/src/error/backtrace.rs +++ b/cot/src/error/backtrace.rs @@ -1,14 +1,14 @@ // inline(never) is added to make sure there is a separate frame for this // function so that it can be used to find the start of the backtrace. #[inline(never)] -pub(crate) fn __flareon_create_backtrace() -> Backtrace { +pub(crate) fn __cot_create_backtrace() -> Backtrace { let mut backtrace = Vec::new(); let mut start = false; backtrace::trace(|frame| { let frame = StackFrame::from(frame); if start { backtrace.push(frame); - } else if frame.symbol_name().contains("__flareon_create_backtrace") { + } else if frame.symbol_name().contains("__cot_create_backtrace") { // TODO does this work with strip = true? (probably not, in that case we should // return all frames instead) start = true; @@ -106,7 +106,7 @@ mod tests { #[test] fn test_create_backtrace() { - let backtrace = __flareon_create_backtrace(); + let backtrace = __cot_create_backtrace(); assert!( !backtrace.frames().is_empty(), "Backtrace should have frames" diff --git a/flareon/src/error_page.rs b/cot/src/error_page.rs similarity index 87% rename from flareon/src/error_page.rs rename to cot/src/error_page.rs index 1aa4eb1..d41dd7c 100644 --- a/flareon/src/error_page.rs +++ b/cot/src/error_page.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use rinja::Template; use tracing::error; -use crate::error::backtrace::{Backtrace, __flareon_create_backtrace}; +use crate::error::backtrace::{Backtrace, __cot_create_backtrace}; use crate::error::{Error, ErrorRepr}; use crate::router::Router; use crate::{Result, StatusCode}; @@ -22,12 +22,12 @@ pub(crate) enum ErrorPageTrigger { } #[derive(Debug)] -pub(super) struct FlareonDiagnostics { +pub(super) struct CotDiagnostics { router: Arc, request_parts: Option, } -impl FlareonDiagnostics { +impl CotDiagnostics { #[must_use] pub(super) fn new(router: Arc, request_parts: Option) -> Self { Self { @@ -93,7 +93,7 @@ impl ErrorPageTemplateBuilder { } } - fn diagnostics(&mut self, diagnostics: FlareonDiagnostics) -> &mut Self { + fn diagnostics(&mut self, diagnostics: CotDiagnostics) -> &mut Self { self.route_data.clear(); Self::build_route_data(&mut self.route_data, &diagnostics.router, "", ""); self.request_data = diagnostics @@ -140,7 +140,7 @@ impl ErrorPageTemplateBuilder { let data = ErrorData { description: error.to_string(), debug_str: format!("{error:#?}"), - is_flareon_error: error.is::(), + is_cot_error: error.is::(), }; vec.push(data); @@ -204,7 +204,7 @@ enum Kind { struct ErrorData { description: String, debug_str: String, - is_flareon_error: bool, + is_cot_error: bool, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -224,14 +224,14 @@ struct RequestData { } #[must_use] -pub(super) fn handle_not_found(diagnostics: FlareonDiagnostics) -> axum::response::Response { +pub(super) fn handle_not_found(diagnostics: CotDiagnostics) -> axum::response::Response { build_response(build_not_found_response(diagnostics), StatusCode::NOT_FOUND) } #[must_use] pub(super) fn handle_response_panic( panic_payload: Box, - diagnostics: FlareonDiagnostics, + diagnostics: CotDiagnostics, ) -> axum::response::Response { build_response( build_panic_response(panic_payload, diagnostics), @@ -242,7 +242,7 @@ pub(super) fn handle_response_panic( #[must_use] pub(super) fn handle_response_error( error: Error, - diagnostics: FlareonDiagnostics, + diagnostics: CotDiagnostics, ) -> axum::response::Response { build_response( build_error_response(error, diagnostics), @@ -259,15 +259,15 @@ fn build_response( Ok(error_str) => axum::response::Response::builder() .status(status_code) .body(axum::body::Body::new(error_str)) - .unwrap_or_else(|_| build_flareon_failure_page()), + .unwrap_or_else(|_| build_cot_failure_page()), Err(error) => { error!("Failed to render error page: {}", error); - build_flareon_failure_page() + build_cot_failure_page() } } } -fn build_not_found_response(diagnostics: FlareonDiagnostics) -> Result { +fn build_not_found_response(diagnostics: CotDiagnostics) -> Result { ErrorPageTemplateBuilder::not_found() .diagnostics(diagnostics) .render() @@ -275,14 +275,14 @@ fn build_not_found_response(diagnostics: FlareonDiagnostics) -> Result { fn build_panic_response( panic_payload: Box, - diagnostics: FlareonDiagnostics, + diagnostics: CotDiagnostics, ) -> Result { ErrorPageTemplateBuilder::panic(panic_payload) .diagnostics(diagnostics) .render() } -fn build_error_response(error: Error, diagnostics: FlareonDiagnostics) -> Result { +fn build_error_response(error: Error, diagnostics: CotDiagnostics) -> Result { ErrorPageTemplateBuilder::error(error) .diagnostics(diagnostics) .render() @@ -292,16 +292,16 @@ const FAILURE_PAGE: &[u8] = include_bytes!("../templates/fail.html"); /// A last-resort error page. /// -/// This page is displayed when an error occurs that prevents Flareon from -/// rendering a proper error page. This page is very simple and should only be -/// displayed in the event of a catastrophic failure, likely caused by a bug in -/// Flareon itself. +/// This page is displayed when an error occurs that prevents Cot from rendering +/// a proper error page. This page is very simple and should only be displayed +/// in the event of a catastrophic failure, likely caused by a bug in Cot +/// itself. #[must_use] -fn build_flareon_failure_page() -> axum::response::Response { +fn build_cot_failure_page() -> axum::response::Response { axum::response::Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(axum::body::Body::from(FAILURE_PAGE)) - .expect("Building the Flareon failure page should not fail") + .expect("Building the Cot failure page should not fail") } thread_local! { @@ -314,7 +314,7 @@ pub(super) fn error_page_panic_hook(info: &PanicHookInfo<'_>) { let location = info.location().map(|location| format!("{location}")); PANIC_LOCATION.replace(location); - PANIC_BACKTRACE.replace(Some(__flareon_create_backtrace())); + PANIC_BACKTRACE.replace(Some(__cot_create_backtrace())); } #[cfg(test)] @@ -325,12 +325,12 @@ mod tests { use crate::router::{Route, Router}; use crate::test::TestRequestBuilder; - fn create_diagnostics() -> FlareonDiagnostics { + fn create_diagnostics() -> CotDiagnostics { let router = Arc::new(Router::with_urls(vec![])); let request = TestRequestBuilder::get("/").build(); let (parts, _body) = request.into_parts(); - FlareonDiagnostics::new(router, Some(parts)) + CotDiagnostics::new(router, Some(parts)) } #[test] @@ -393,8 +393,8 @@ mod tests { } #[test] - fn test_build_flareon_failure_page() { - let response = build_flareon_failure_page(); + fn test_build_cot_failure_page() { + let response = build_cot_failure_page(); assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR); } } diff --git a/flareon/src/forms.rs b/cot/src/forms.rs similarity index 98% rename from flareon/src/forms.rs rename to cot/src/forms.rs index 4db8be7..5daa238 100644 --- a/flareon/src/forms.rs +++ b/cot/src/forms.rs @@ -6,12 +6,12 @@ //! //! # `Form` derive macro //! -//! The easiest way to work with forms in Flareon is to use the +//! The easiest way to work with forms in Cot is to use the //! [`Form`](derive@Form) derive macro. Just define a structure that will hold //! all the form data you need, and derive the [`Form`] trait for it. //! //! ``` -//! use flareon::forms::Form; +//! use cot::forms::Form; //! //! #[derive(Form)] //! struct MyForm { @@ -26,7 +26,7 @@ use std::borrow::Cow; use std::fmt::Debug; use async_trait::async_trait; -pub use flareon_macros::Form; +pub use cot_macros::Form; use thiserror::Error; use crate::request::{Request, RequestExt}; @@ -144,7 +144,7 @@ pub enum FormErrorTarget<'a> { /// type. /// /// ```rust -/// use flareon::forms::Form; +/// use cot::forms::Form; /// /// #[derive(Form)] /// struct MyForm { diff --git a/flareon/src/forms/fields.rs b/cot/src/forms/fields.rs similarity index 100% rename from flareon/src/forms/fields.rs rename to cot/src/forms/fields.rs diff --git a/flareon/src/headers.rs b/cot/src/headers.rs similarity index 100% rename from flareon/src/headers.rs rename to cot/src/headers.rs diff --git a/flareon/src/lib.rs b/cot/src/lib.rs similarity index 83% rename from flareon/src/lib.rs rename to cot/src/lib.rs index 7060813..e04b2e7 100644 --- a/flareon/src/lib.rs +++ b/cot/src/lib.rs @@ -1,4 +1,4 @@ -//! Flareon is an easy to use, modern, and fast web framework for Rust. It has +//! Cot is an easy to use, modern, and fast web framework for Rust. It has //! been designed to be familiar if you've ever used //! [Django](https://www.djangoproject.com/), and easy to learn if you haven't. //! It's a batteries-included framework built on top of @@ -6,27 +6,26 @@ //! //! ## Features //! -//! * **Easy to use API** — in many ways modeled after Django, Flareon's API is +//! * **Easy to use API** — in many ways modeled after Django, Cot's API is //! designed to be easy to use and intuitive. Sensible defaults make it for //! easy rapid development, while the API is still empowering you when needed. -//! The documentation is a first-class citizen in Flareon, making it easy to -//! find what you're looking for. -//! * **ORM integration** — Flareon comes with its own ORM, allowing you to -//! interact with your database in a way that feels Rusty and intuitive. Rust -//! types are the source of truth, and the ORM takes care of translating them -//! to and from the database, as well as creating the migrations -//! automatically. -//! * **Type safe** — wherever possible, Flareon uses Rust's type system to -//! prevent common mistakes and bugs. Not only views are taking advantage of -//! the Rust's type system, but also the ORM, the admin panel, and even the +//! The documentation is a first-class citizen in Cot, making it easy to find +//! what you're looking for. +//! * **ORM integration** — Cot comes with its own ORM, allowing you to interact +//! with your database in a way that feels Rusty and intuitive. Rust types are +//! the source of truth, and the ORM takes care of translating them to and +//! from the database, as well as creating the migrations automatically. +//! * **Type safe** — wherever possible, Cot uses Rust's type system to prevent +//! common mistakes and bugs. Not only views are taking advantage of the +//! Rust's type system, but also the ORM, the admin panel, and even the //! templates. All that to catch errors as early as possible. -//! * **Admin panel** — Flareon comes with an admin panel out of the box, -//! allowing you to manage your app's data with ease. Adding new models to the -//! admin panel is stupidly simple, making it a great tool not only for rapid +//! * **Admin panel** — Cot comes with an admin panel out of the box, allowing +//! you to manage your app's data with ease. Adding new models to the admin +//! panel is stupidly simple, making it a great tool not only for rapid //! development and debugging, but with its customization options, also for //! production use. -//! * **Secure by default** — security should be opt-out, not opt-in. Flareon -//! takes care of making your web apps secure by default, defending it against +//! * **Secure by default** — security should be opt-out, not opt-in. Cot takes +//! care of making your web apps secure by default, defending it against //! common modern web vulnerabilities. You can focus on building your app, not //! securing it. @@ -43,7 +42,7 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -extern crate self as flareon; +extern crate self as cot; #[cfg(feature = "db")] pub mod db; @@ -76,9 +75,9 @@ use std::task::{Context, Poll}; use async_trait::async_trait; use axum::handler::HandlerWithoutStateExt; use bytes::Bytes; +pub use cot_macros::main; use derive_more::{Debug, Deref, Display, From}; pub use error::Error; -pub use flareon_macros::main; use futures_core::Stream; use futures_util::FutureExt; use http::request::Parts; @@ -99,11 +98,11 @@ use crate::db::migrations::{DynMigration, MigrationEngine}; #[cfg(feature = "db")] use crate::db::Database; use crate::error::ErrorRepr; -use crate::error_page::{ErrorPageTrigger, FlareonDiagnostics}; +use crate::error_page::{CotDiagnostics, ErrorPageTrigger}; use crate::response::Response; use crate::router::RouterService; -/// A type alias for a result that can return a `flareon::Error`. +/// A type alias for a result that can return a `cot::Error`. pub type Result = std::result::Result; /// A type alias for an HTTP status code. @@ -114,7 +113,7 @@ pub type Method = http::Method; /// A function that takes a request and returns a response. /// -/// This is the main building block of a Flareon app. You shouldn't +/// This is the main building block of a Cot app. You shouldn't /// usually need to implement this directly, as it is already /// implemented for closures and functions that take a [`Request`] /// and return a [`Result`]. @@ -134,9 +133,9 @@ where } } -/// A building block for a Flareon project. +/// A building block for a Cot project. /// -/// A Flareon app is a part (ideally, reusable) of a Flareon project that is +/// A Cot app is a part (ideally, reusable) of a Cot project that is /// responsible for its own set of functionalities. Examples of apps could be: /// * admin panel /// * user authentication @@ -149,7 +148,7 @@ where /// mounted on the project's router, its own set of middleware, database /// migrations (which can depend on other apps), etc. #[async_trait] -pub trait FlareonApp: Send + Sync { +pub trait CotApp: Send + Sync { fn name(&self) -> &str; #[allow(unused_variables)] @@ -184,7 +183,7 @@ pub trait FlareonApp: Send + Sync { /// # Examples /// /// ``` -/// use flareon::Body; +/// use cot::Body; /// /// let body = Body::fixed("Hello, world!"); /// let body = Body::streaming(futures::stream::once(async { Ok("Hello, world!".into()) })); @@ -221,7 +220,7 @@ impl Body { /// # Examples /// /// ``` - /// use flareon::Body; + /// use cot::Body; /// /// let body = Body::empty(); /// ``` @@ -235,7 +234,7 @@ impl Body { /// # Examples /// /// ``` - /// use flareon::Body; + /// use cot::Body; /// /// let body = Body::fixed("Hello, world!"); /// ``` @@ -250,7 +249,7 @@ impl Body { /// /// ``` /// use async_stream::stream; - /// use flareon::Body; + /// use cot::Body; /// /// let stream = stream! { /// yield Ok("Hello, ".into()); @@ -343,20 +342,20 @@ impl http_body::Body for Body { pub type BoxedHandler = BoxCloneService; -/// A Flareon project, ready to be run. +/// A Cot project, ready to be run. #[derive(Debug)] -pub struct FlareonProject { +pub struct CotProject { context: AppContext, handler: BoxedHandler, } -/// A part of [`FlareonProject`] that contains the shared context and configs +/// A part of [`CotProject`] that contains the shared context and configs /// for all apps. #[derive(Debug)] pub struct AppContext { config: Arc, #[debug("...")] - apps: Vec>, + apps: Vec>, router: Arc, #[cfg(feature = "db")] database: Option>, @@ -366,7 +365,7 @@ impl AppContext { #[must_use] pub(crate) fn new( config: Arc, - apps: Vec>, + apps: Vec>, router: Arc, #[cfg(feature = "db")] database: Option>, ) -> Self { @@ -385,7 +384,7 @@ impl AppContext { } #[must_use] - pub fn apps(&self) -> &[Box] { + pub fn apps(&self) -> &[Box] { &self.apps } @@ -404,7 +403,7 @@ impl AppContext { #[cfg(feature = "db")] pub fn database(&self) -> &Database { self.try_database().expect( - "Database missing. Did you forget to add the database when configuring FlareonProject?", + "Database missing. Did you forget to add the database when configuring CotProject?", ) } } @@ -413,15 +412,15 @@ impl AppContext { #[derive(Debug, Copy, Clone)] pub struct Uninitialized; -/// The builder for the [`FlareonProject`]. +/// The builder for the [`CotProject`]. #[derive(Debug)] -pub struct FlareonProjectBuilder { +pub struct CotProjectBuilder { context: AppContext, urls: Vec, handler: S, } -impl FlareonProjectBuilder { +impl CotProjectBuilder { #[must_use] pub fn new() -> Self { Self { @@ -443,7 +442,7 @@ impl FlareonProjectBuilder { self } - pub fn register_app_with_views( + pub fn register_app_with_views( mut self, app: T, url_prefix: &str, @@ -453,7 +452,7 @@ impl FlareonProjectBuilder { self } - pub fn register_app(mut self, app: T) -> Self { + pub fn register_app(mut self, app: T) -> Self { self.context.apps.push(Box::new(app)); self } @@ -462,15 +461,12 @@ impl FlareonProjectBuilder { pub fn middleware>( self, middleware: M, - ) -> FlareonProjectBuilder { + ) -> CotProjectBuilder { self.into_builder_with_service().middleware(middleware) } #[must_use] - pub fn middleware_with_context( - self, - get_middleware: F, - ) -> FlareonProjectBuilder + pub fn middleware_with_context(self, get_middleware: F) -> CotProjectBuilder where M: tower::Layer, F: FnOnce(&AppContext) -> M, @@ -479,17 +475,17 @@ impl FlareonProjectBuilder { .middleware_with_context(get_middleware) } - /// Builds the Flareon project instance. - pub async fn build(self) -> Result { + /// Builds the Cot project instance. + pub async fn build(self) -> Result { self.into_builder_with_service().build().await } #[must_use] - fn into_builder_with_service(mut self) -> FlareonProjectBuilder { + fn into_builder_with_service(mut self) -> CotProjectBuilder { let router = Arc::new(Router::with_urls(self.urls)); self.context.router = Arc::clone(&router); - FlareonProjectBuilder { + CotProjectBuilder { context: self.context, urls: vec![], handler: RouterService::new(router), @@ -497,17 +493,14 @@ impl FlareonProjectBuilder { } } -impl FlareonProjectBuilder +impl CotProjectBuilder where S: Service + Send + Sync + Clone + 'static, S::Future: Send, { #[must_use] - pub fn middleware>( - self, - middleware: M, - ) -> FlareonProjectBuilder { - FlareonProjectBuilder { + pub fn middleware>(self, middleware: M) -> CotProjectBuilder { + CotProjectBuilder { context: self.context, urls: vec![], handler: middleware.layer(self.handler), @@ -515,10 +508,7 @@ where } #[must_use] - pub fn middleware_with_context( - self, - get_middleware: F, - ) -> FlareonProjectBuilder + pub fn middleware_with_context(self, get_middleware: F) -> CotProjectBuilder where M: tower::Layer, F: FnOnce(&AppContext) -> M, @@ -527,15 +517,15 @@ where self.middleware(middleware) } - /// Builds the Flareon project instance. - pub async fn build(mut self) -> Result { + /// Builds the Cot project instance. + pub async fn build(mut self) -> Result { #[cfg(feature = "db")] { let database = Self::init_database(self.context.config.database_config()).await?; self.context.database = Some(database); } - Ok(FlareonProject { + Ok(CotProject { context: self.context, handler: BoxedHandler::new(self.handler), }) @@ -548,16 +538,16 @@ where } } -impl Default for FlareonProjectBuilder { +impl Default for CotProjectBuilder { fn default() -> Self { Self::new() } } -impl FlareonProject { +impl CotProject { #[must_use] - pub fn builder() -> FlareonProjectBuilder { - FlareonProjectBuilder::default() + pub fn builder() -> CotProjectBuilder { + CotProjectBuilder::default() } #[must_use] @@ -566,15 +556,15 @@ impl FlareonProject { } } -/// Runs the Flareon project on the given address. +/// Runs the Cot project on the given address. /// -/// This function takes a Flareon project and an address string and runs the +/// This function takes a Cot project and an address string and runs the /// project on the given address. /// /// # Errors /// /// This function returns an error if the server fails to start. -pub async fn run(project: FlareonProject, address_str: &str) -> Result<()> { +pub async fn run(project: CotProject, address_str: &str) -> Result<()> { let listener = tokio::net::TcpListener::bind(address_str) .await .map_err(|e| ErrorRepr::StartServer { source: e })?; @@ -582,9 +572,9 @@ pub async fn run(project: FlareonProject, address_str: &str) -> Result<()> { run_at(project, listener).await } -/// Runs the Flareon project on the given listener. +/// Runs the Cot project on the given listener. /// -/// This function takes a Flareon project and a [`tokio::net::TcpListener`] and +/// This function takes a Cot project and a [`tokio::net::TcpListener`] and /// runs the project on the given listener. /// /// If you need more control over the server listening socket, such as modifying @@ -595,7 +585,7 @@ pub async fn run(project: FlareonProject, address_str: &str) -> Result<()> { /// # Errors /// /// This function returns an error if the server fails to start. -pub async fn run_at(project: FlareonProject, listener: tokio::net::TcpListener) -> Result<()> { +pub async fn run_at(project: CotProject, listener: tokio::net::TcpListener) -> Result<()> { let (mut context, mut project_handler) = project.into_context(); #[cfg(feature = "db")] @@ -621,7 +611,7 @@ pub async fn run_at(project: FlareonProject, listener: tokio::net::TcpListener) let context_cleanup = context.clone(); let handler = |axum_request: axum::extract::Request| async move { - let request = request_axum_to_flareon(axum_request, Arc::clone(&context)); + let request = request_axum_to_cot(axum_request, Arc::clone(&context)); let (request_parts, request) = request_parts_for_diagnostics(request); let catch_unwind_response = AssertUnwindSafe(pass_to_axum(request, &mut project_handler)) @@ -640,7 +630,7 @@ pub async fn run_at(project: FlareonProject, listener: tokio::net::TcpListener) }; if show_error_page { - let diagnostics = FlareonDiagnostics::new(Arc::clone(&context.router), request_parts); + let diagnostics = CotDiagnostics::new(Arc::clone(&context.router), request_parts); match catch_unwind_response { Ok(response) => match response { @@ -685,7 +675,7 @@ pub async fn run_at(project: FlareonProject, listener: tokio::net::TcpListener) Ok(()) } -pub async fn run_cli(project: FlareonProject) -> Result<()> { +pub async fn run_cli(project: CotProject) -> Result<()> { // TODO: we want to have a (extensible) CLI interface soon, but for simplicity // we just run the server now run(project, "127.0.0.1:8080").await?; @@ -703,10 +693,7 @@ fn request_parts_for_diagnostics(request: Request) -> (Option, Request) { } } -fn request_axum_to_flareon( - axum_request: axum::extract::Request, - context: Arc, -) -> Request { +fn request_axum_to_cot(axum_request: axum::extract::Request, context: Arc) -> Request { let mut request = axum_request.map(Body::axum); prepare_request(&mut request, context); request @@ -758,17 +745,17 @@ mod tests { use super::*; - struct MockFlareonApp; + struct MockCotApp; - impl FlareonApp for MockFlareonApp { + impl CotApp for MockCotApp { fn name(&self) -> &'static str { "mock" } } #[tokio::test] - async fn flareon_app_default_impl() { - let app = MockFlareonApp {}; + async fn cot_app_default_impl() { + let app = MockCotApp {}; assert_eq!(app.name(), "mock"); assert_eq!(app.router().routes().len(), 0); assert_eq!(app.migrations().len(), 0); @@ -776,9 +763,9 @@ mod tests { #[tokio::test] #[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2` - async fn flareon_project_builder() { - let project = FlareonProject::builder() - .register_app_with_views(MockFlareonApp {}, "/app") + async fn cot_project_builder() { + let project = CotProject::builder() + .register_app_with_views(MockCotApp {}, "/app") .build() .await .unwrap(); @@ -788,9 +775,9 @@ mod tests { #[tokio::test] #[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2` - async fn flareon_project_router() { - let project = FlareonProject::builder() - .register_app_with_views(MockFlareonApp {}, "/app") + async fn cot_project_router() { + let project = CotProject::builder() + .register_app_with_views(MockCotApp {}, "/app") .build() .await .unwrap(); diff --git a/flareon/src/middleware.rs b/cot/src/middleware.rs similarity index 95% rename from flareon/src/middleware.rs rename to cot/src/middleware.rs index 78984bd..1054324 100644 --- a/flareon/src/middleware.rs +++ b/cot/src/middleware.rs @@ -32,4 +32,4 @@ impl tower::Layer for SessionMiddleware { } } -// TODO: add Flareon ORM-based session store +// TODO: add Cot ORM-based session store diff --git a/flareon/src/private.rs b/cot/src/private.rs similarity index 80% rename from flareon/src/private.rs rename to cot/src/private.rs index e02a578..b2b8780 100644 --- a/flareon/src/private.rs +++ b/cot/src/private.rs @@ -1,4 +1,4 @@ -//! Re-exports of some of the Flareon dependencies that are used in the macros +//! Re-exports of some of the Cot dependencies that are used in the macros //! and the CLI. //! //! This is to avoid the need to add them as dependencies to the crate that uses diff --git a/flareon/src/request.rs b/cot/src/request.rs similarity index 94% rename from flareon/src/request.rs rename to cot/src/request.rs index 98e97b1..0311b65 100644 --- a/flareon/src/request.rs +++ b/cot/src/request.rs @@ -1,6 +1,6 @@ //! HTTP request type and helper methods. //! -//! Flareon uses the [`Request`](http::Request) type from the [`http`] crate +//! Cot uses the [`Request`](http::Request) type from the [`http`] crate //! to represent incoming HTTP requests. However, it also provides a //! [`RequestExt`] trait that contain various helper methods for working with //! HTTP requests. These methods are used to access the application context, @@ -9,7 +9,7 @@ //! able to use these functions: //! //! ``` -//! use flareon::request::RequestExt; +//! use cot::request::RequestExt; //! ``` use std::borrow::Cow; @@ -18,7 +18,7 @@ use std::sync::Arc; use async_trait::async_trait; use bytes::Bytes; #[cfg(feature = "json")] -use flareon::headers::JSON_CONTENT_TYPE; +use cot::headers::JSON_CONTENT_TYPE; use indexmap::IndexMap; use tower_sessions::Session; @@ -42,7 +42,7 @@ mod private { /// # Sealed /// /// This trait is sealed since it doesn't make sense to be implemented for types -/// outside the context of Flareon. +/// outside the context of Cot. #[async_trait] pub trait RequestExt: private::Sealed { #[must_use] @@ -98,8 +98,8 @@ pub trait RequestExt: private::Sealed { /// # Example /// /// ``` - /// use flareon::request::{Request, RequestExt}; - /// use flareon::response::{Response, ResponseExt}; + /// use cot::request::{Request, RequestExt}; + /// use cot::response::{Response, ResponseExt}; /// use serde::{Deserialize, Serialize}; /// /// #[derive(Serialize, Deserialize)] @@ -107,9 +107,9 @@ pub trait RequestExt: private::Sealed { /// hello: String, /// } /// - /// async fn my_handler(mut request: Request) -> flareon::Result { + /// async fn my_handler(mut request: Request) -> cot::Result { /// let data: MyData = request.json().await?; - /// Ok(Response::new_json(flareon::StatusCode::OK, &data)?) + /// Ok(Response::new_json(cot::StatusCode::OK, &data)?) /// } /// ``` #[cfg(feature = "json")] diff --git a/flareon/src/response.rs b/cot/src/response.rs similarity index 94% rename from flareon/src/response.rs rename to cot/src/response.rs index 64da482..f1de7a8 100644 --- a/flareon/src/response.rs +++ b/cot/src/response.rs @@ -1,6 +1,6 @@ //! HTTP response type and helper methods. //! -//! Flareon uses the [`Response`](http::Response) type from the [`http`] crate +//! Cot uses the [`Response`](http::Response) type from the [`http`] crate //! to represent outgoing HTTP responses. However, it also provides a //! [`ResponseExt`] trait that contain various helper methods for working with //! HTTP responses. These methods are used to create new responses with HTML @@ -9,7 +9,7 @@ //! use these functions: //! //! ``` -//! use flareon::response::ResponseExt; +//! use cot::response::ResponseExt; //! ``` use crate::headers::HTML_CONTENT_TYPE; @@ -32,7 +32,7 @@ mod private { /// # Sealed /// /// This trait is sealed since it doesn't make sense to be implemented for types -/// outside the context of Flareon. +/// outside the context of Cot. pub trait ResponseExt: Sized + private::Sealed { #[must_use] fn builder() -> http::response::Builder; @@ -54,8 +54,8 @@ pub trait ResponseExt: Sized + private::Sealed { /// # Examples /// /// ``` - /// use flareon::response::{Response, ResponseExt}; - /// use flareon::{Body, StatusCode}; + /// use cot::response::{Response, ResponseExt}; + /// use cot::{Body, StatusCode}; /// use serde::Serialize; /// /// #[derive(Serialize)] @@ -67,7 +67,7 @@ pub trait ResponseExt: Sized + private::Sealed { /// hello: String::from("world"), /// }; /// let response = Response::new_json(StatusCode::OK, &data)?; - /// # Ok::<(), flareon::Error>(()) + /// # Ok::<(), cot::Error>(()) /// ``` #[cfg(feature = "json")] fn new_json(status: StatusCode, data: &T) -> crate::Result; diff --git a/flareon/src/router.rs b/cot/src/router.rs similarity index 96% rename from flareon/src/router.rs rename to cot/src/router.rs index ec9137c..a3599b2 100644 --- a/flareon/src/router.rs +++ b/cot/src/router.rs @@ -9,8 +9,8 @@ use std::task::{Context, Poll}; use axum::http::StatusCode; use bytes::Bytes; +use cot::request::PathParams; use derive_more::Debug; -use flareon::request::PathParams; use tracing::debug; use crate::error::ErrorRepr; @@ -107,7 +107,7 @@ impl Router { /// Handle a request. /// - /// This method is called by the [`FlareonApp`](crate::FlareonApp) to handle + /// This method is called by the [`CotApp`](crate::CotApp) to handle /// a request. /// /// # Errors @@ -316,12 +316,12 @@ impl Debug for RouteInner { /// # Examples /// /// ``` -/// use flareon::request::Request; -/// use flareon::response::{Response, ResponseExt}; -/// use flareon::router::{Route, Router}; -/// use flareon::{reverse_str, Body, StatusCode}; +/// use cot::request::Request; +/// use cot::response::{Response, ResponseExt}; +/// use cot::router::{Route, Router}; +/// use cot::{reverse_str, Body, StatusCode}; /// -/// async fn home(request: Request) -> flareon::Result { +/// async fn home(request: Request) -> cot::Result { /// Ok(Response::new_html( /// StatusCode::OK, /// Body::fixed(format!( @@ -352,12 +352,12 @@ macro_rules! reverse_str { /// # Examples /// /// ``` -/// use flareon::request::Request; -/// use flareon::response::Response; -/// use flareon::reverse; -/// use flareon::router::{Route, Router}; +/// use cot::request::Request; +/// use cot::response::Response; +/// use cot::reverse; +/// use cot::router::{Route, Router}; /// -/// async fn infinite_loop(request: Request) -> flareon::Result { +/// async fn infinite_loop(request: Request) -> cot::Result { /// Ok(reverse!(request, "home")) /// } /// diff --git a/flareon/src/router/path.rs b/cot/src/router/path.rs similarity index 100% rename from flareon/src/router/path.rs rename to cot/src/router/path.rs diff --git a/flareon/src/static_files.rs b/cot/src/static_files.rs similarity index 96% rename from flareon/src/static_files.rs rename to cot/src/static_files.rs index 77d1451..03d379e 100644 --- a/flareon/src/static_files.rs +++ b/cot/src/static_files.rs @@ -25,13 +25,13 @@ use crate::{AppContext, Body}; /// project root, where the `Cargo.toml` file is). /// /// This is mainly useful with the -/// [`FlareonApp::static_files`](crate::FlareonApp::static_files) trait method. +/// [`CotApp::static_files`](crate::CotApp::static_files) trait method. /// /// # Example /// /// ``` /// use bytes::Bytes; -/// use flareon::{static_files, FlareonApp}; +/// use cot::{static_files, CotApp}; /// /// pub struct ExampleApp; /// @@ -42,7 +42,7 @@ use crate::{AppContext, Body}; /// // └── admin /// // └── admin.css /// -/// impl FlareonApp for ExampleApp { +/// impl CotApp for ExampleApp { /// fn name(&self) -> &str { /// "test_app" /// } @@ -126,7 +126,7 @@ impl File { /// Middleware for serving static files. /// /// This middleware serves static files defined by the applications by using -/// the [`FlareonApp::static_files`](crate::FlareonApp::static_files) trait +/// the [`CotApp::static_files`](crate::CotApp::static_files) trait /// method. The middleware serves files from the `/static/` path. /// /// If a request is made to a path starting with `/static/`, the middleware @@ -254,7 +254,7 @@ mod tests { use tower::{Layer, ServiceExt}; use super::*; - use crate::{FlareonApp, FlareonProject}; + use crate::{CotApp, CotProject}; #[test] #[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2` @@ -342,7 +342,7 @@ mod tests { #[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2` async fn static_files_middleware_from_app_context() { struct App1; - impl FlareonApp for App1 { + impl CotApp for App1 { fn name(&self) -> &'static str { "app1" } @@ -353,7 +353,7 @@ mod tests { } struct App2; - impl FlareonApp for App2 { + impl CotApp for App2 { fn name(&self) -> &'static str { "app2" } @@ -363,7 +363,7 @@ mod tests { } } - let project = FlareonProject::builder() + let project = CotProject::builder() .register_app(App1) .register_app(App2) .build() diff --git a/flareon/src/test.rs b/cot/src/test.rs similarity index 93% rename from flareon/src/test.rs rename to cot/src/test.rs index db5498a..8affb1e 100644 --- a/flareon/src/test.rs +++ b/cot/src/test.rs @@ -1,4 +1,4 @@ -//! Test utilities for Flareon projects. +//! Test utilities for Cot projects. use std::future::poll_fn; use std::sync::Arc; @@ -19,11 +19,11 @@ use crate::db::Database; use crate::request::{Request, RequestExt}; use crate::response::Response; use crate::router::Router; -use crate::{prepare_request, AppContext, Body, BoxedHandler, FlareonProject, Result}; +use crate::{prepare_request, AppContext, Body, BoxedHandler, CotProject, Result}; -/// A test client for making requests to a Flareon project. +/// A test client for making requests to a Cot project. /// -/// Useful for End-to-End testing Flareon projects. +/// Useful for End-to-End testing Cot projects. #[derive(Debug)] pub struct Client { context: Arc, @@ -32,7 +32,7 @@ pub struct Client { impl Client { #[must_use] - pub fn new(project: FlareonProject) -> Self { + pub fn new(project: CotProject) -> Self { let (context, handler) = project.into_context(); Self { context: Arc::new(context), @@ -229,9 +229,9 @@ impl TestDatabase { /// Note that it shouldn't include the database name — the function will /// create a new database for the test by connecting to the `postgres` /// database. If no URL is provided, it defaults to - /// `postgresql://flareon:flareon@localhost`. + /// `postgresql://cot:cot@localhost`. /// - /// The database is created with the name `test_flareon__{test_name}`. + /// The database is created with the name `test_cot__{test_name}`. /// Make sure that `test_name` is unique for each test so that the databases /// don't conflict with each other. /// @@ -239,10 +239,10 @@ impl TestDatabase { /// means that the database will not be dropped if the test panics. pub async fn new_postgres(test_name: &str) -> Result { let db_url = std::env::var("POSTGRES_URL") - .unwrap_or_else(|_| "postgresql://flareon:flareon@localhost".to_string()); + .unwrap_or_else(|_| "postgresql://cot:cot@localhost".to_string()); let database = Database::new(format!("{db_url}/postgres")).await?; - let test_database_name = format!("test_flareon__{test_name}"); + let test_database_name = format!("test_cot__{test_name}"); database .raw(&format!("DROP DATABASE IF EXISTS {test_database_name}")) .await?; @@ -270,7 +270,7 @@ impl TestDatabase { /// database. If no URL is provided, it defaults to /// `mysql://root:@localhost`. /// - /// The database is created with the name `test_flareon__{test_name}`. + /// The database is created with the name `test_cot__{test_name}`. /// Make sure that `test_name` is unique for each test so that the databases /// don't conflict with each other. /// @@ -281,7 +281,7 @@ impl TestDatabase { std::env::var("MYSQL_URL").unwrap_or_else(|_| "mysql://root:@localhost".to_string()); let database = Database::new(format!("{db_url}/mysql")).await?; - let test_database_name = format!("test_flareon__{test_name}"); + let test_database_name = format!("test_cot__{test_name}"); database .raw(&format!("DROP DATABASE IF EXISTS {test_database_name}")) .await?; @@ -312,7 +312,7 @@ impl TestDatabase { #[cfg(feature = "db")] pub fn with_auth(&mut self) -> &mut Self { - self.add_migrations(flareon::auth::db::migrations::MIGRATIONS.to_vec()); + self.add_migrations(cot::auth::db::migrations::MIGRATIONS.to_vec()); self } diff --git a/flareon/src/utils.rs b/cot/src/utils.rs similarity index 100% rename from flareon/src/utils.rs rename to cot/src/utils.rs diff --git a/flareon/src/utils/graph.rs b/cot/src/utils/graph.rs similarity index 100% rename from flareon/src/utils/graph.rs rename to cot/src/utils/graph.rs diff --git a/flareon/static/admin/admin.css b/cot/static/admin/admin.css similarity index 100% rename from flareon/static/admin/admin.css rename to cot/static/admin/admin.css diff --git a/flareon/templates/admin/base.html b/cot/templates/admin/base.html similarity index 84% rename from flareon/templates/admin/base.html rename to cot/templates/admin/base.html index 9e9261d..09748db 100644 --- a/flareon/templates/admin/base.html +++ b/cot/templates/admin/base.html @@ -4,7 +4,7 @@ - {% block title %}{% endblock %} | Flareon Admin + {% block title %}{% endblock %} | Cot Admin diff --git a/flareon/templates/admin/login.html b/cot/templates/admin/login.html similarity index 100% rename from flareon/templates/admin/login.html rename to cot/templates/admin/login.html diff --git a/flareon/templates/admin/model.html b/cot/templates/admin/model.html similarity index 100% rename from flareon/templates/admin/model.html rename to cot/templates/admin/model.html diff --git a/flareon/templates/admin/model_list.html b/cot/templates/admin/model_list.html similarity index 58% rename from flareon/templates/admin/model_list.html rename to cot/templates/admin/model_list.html index bb48d43..3e40c92 100644 --- a/flareon/templates/admin/model_list.html +++ b/cot/templates/admin/model_list.html @@ -5,6 +5,6 @@ {% block content %} {% let request = request %} {% for model in model_managers %} - model.url_name()) }}">{{ model.name() }} + model.url_name()) }}">{{ model.name() }} {% endfor %} {% endblock %} diff --git a/flareon/templates/error.css b/cot/templates/error.css similarity index 100% rename from flareon/templates/error.css rename to cot/templates/error.css diff --git a/flareon/templates/error.html b/cot/templates/error.html similarity index 94% rename from flareon/templates/error.html rename to cot/templates/error.html index f298c50..96b18de 100644 --- a/flareon/templates/error.html +++ b/cot/templates/error.html @@ -4,14 +4,14 @@ - Flareon failure + Cot failure -

{% match kind %}{% when Kind::NotFound %}Not found{% else %}Flareon failure{% endmatch %}

+

{% match kind %}{% when Kind::NotFound %}Not found{% else %}Cot failure{% endmatch %}

{% match kind %}{% when Kind::NotFound %}The URL requested could not be found.{% when Kind::Panic %}The request handler has panicked.{% else %}An error occurred while handling a request.{% endmatch %}

{% match kind %} @@ -40,7 +40,7 @@

Error chain

{{ loop.index0 }} {{ error.description }} - {% if error.is_flareon_error %}flareon::Error{% endif %} + {% if error.is_cot_error %}cot::Error{% endif %}
{{ error.debug_str }}
diff --git a/flareon/templates/fail.html b/cot/templates/fail.html similarity index 57% rename from flareon/templates/fail.html rename to cot/templates/fail.html index b86155e..754658d 100644 --- a/flareon/templates/fail.html +++ b/cot/templates/fail.html @@ -3,14 +3,14 @@ - Flareon failure + Cot failure -

Flareon failure

-

An error occurred when trying to build Flareon error page.

+

Cot failure

+

An error occurred when trying to build Cot error page.

If you are a user, please report this to the website administrator. If you are a website administrator, this is - likely a Flareon bug. Please report it on the Flareon bug + likely a Cot bug. Please report it on the Cot bug tracker.

diff --git a/flareon/tests/auth.rs b/cot/tests/auth.rs similarity index 89% rename from flareon/tests/auth.rs rename to cot/tests/auth.rs index 9b968c9..ef82836 100644 --- a/flareon/tests/auth.rs +++ b/cot/tests/auth.rs @@ -1,8 +1,8 @@ -use flareon::auth::db::{DatabaseUser, DatabaseUserCredentials}; -use flareon::auth::{AuthRequestExt, Password}; -use flareon::test::{TestDatabase, TestRequestBuilder}; +use cot::auth::db::{DatabaseUser, DatabaseUserCredentials}; +use cot::auth::{AuthRequestExt, Password}; +use cot::test::{TestDatabase, TestRequestBuilder}; -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn database_user(test_db: &mut TestDatabase) { test_db.with_auth().run_migrations().await; let mut request_builder = TestRequestBuilder::get("/"); diff --git a/flareon/tests/db.rs b/cot/tests/db.rs similarity index 97% rename from flareon/tests/db.rs rename to cot/tests/db.rs index 7ce9785..d6161fb 100644 --- a/flareon/tests/db.rs +++ b/cot/tests/db.rs @@ -1,18 +1,18 @@ #![cfg(feature = "fake")] #![cfg_attr(miri, ignore)] -use fake::rand::rngs::StdRng; -use fake::rand::SeedableRng; -use fake::{Dummy, Fake, Faker}; -use flareon::db::migrations::{Field, Operation}; -use flareon::db::query::ExprEq; -use flareon::db::{ +use cot::db::migrations::{Field, Operation}; +use cot::db::query::ExprEq; +use cot::db::{ model, query, Auto, Database, DatabaseError, DatabaseField, ForeignKey, ForeignKeyOnDeletePolicy, ForeignKeyOnUpdatePolicy, Identifier, LimitedString, Model, }; -use flareon::test::TestDatabase; +use cot::test::TestDatabase; +use fake::rand::rngs::StdRng; +use fake::rand::SeedableRng; +use fake::{Dummy, Fake, Faker}; -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn model_crud(test_db: &mut TestDatabase) { migrate_test_model(&*test_db).await; @@ -36,7 +36,7 @@ async fn model_crud(test_db: &mut TestDatabase) { assert_eq!(TestModel::objects().all(&**test_db).await.unwrap(), vec![]); } -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn model_macro_filtering(test_db: &mut TestDatabase) { migrate_test_model(&*test_db).await; @@ -162,7 +162,7 @@ const CREATE_ALL_FIELDS_MODEL: Operation = Operation::create_model() ]) .build(); -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn all_fields_model(db: &mut TestDatabase) { migrate_all_fields_model(&db).await; @@ -200,7 +200,7 @@ fn normalize_datetimes(data: &mut Vec) { } } -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn foreign_keys(db: &mut TestDatabase) { #[derive(Debug, Clone, PartialEq)] #[model] @@ -284,7 +284,7 @@ async fn foreign_keys(db: &mut TestDatabase) { // no error should be thrown } -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn foreign_keys_option(db: &mut TestDatabase) { #[derive(Debug, Clone, PartialEq)] #[model] @@ -366,7 +366,7 @@ async fn foreign_keys_option(db: &mut TestDatabase) { assert_eq!(child.parent, None); } -#[flareon_macros::dbtest] +#[cot_macros::dbtest] async fn foreign_keys_cascade(db: &mut TestDatabase) { #[derive(Debug, Clone, PartialEq)] #[model] diff --git a/flareon/tests/flareon_project.rs b/cot/tests/flareon_project.rs similarity index 69% rename from flareon/tests/flareon_project.rs rename to cot/tests/flareon_project.rs index 967b369..65c3895 100644 --- a/flareon/tests/flareon_project.rs +++ b/cot/tests/flareon_project.rs @@ -1,18 +1,18 @@ -use flareon::request::Request; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::test::Client; -use flareon::{Body, FlareonApp, FlareonProject, StatusCode}; +use cot::request::Request; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::test::Client; +use cot::{Body, CotApp, CotProject, StatusCode}; -async fn hello(_request: Request) -> flareon::Result { +async fn hello(_request: Request) -> cot::Result { Ok(Response::new_html(StatusCode::OK, Body::fixed("OK"))) } #[tokio::test] #[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2` -async fn flareon_project_router_sub_path() { +async fn cot_project_router_sub_path() { struct App1; - impl FlareonApp for App1 { + impl CotApp for App1 { fn name(&self) -> &'static str { "app1" } @@ -23,7 +23,7 @@ async fn flareon_project_router_sub_path() { } struct App2; - impl FlareonApp for App2 { + impl CotApp for App2 { fn name(&self) -> &'static str { "app2" } @@ -33,7 +33,7 @@ async fn flareon_project_router_sub_path() { } } - let project = FlareonProject::builder() + let project = CotProject::builder() .register_app_with_views(App1, "/") .register_app_with_views(App2, "/app") .build() diff --git a/flareon/tests/forms.rs b/cot/tests/forms.rs similarity index 97% rename from flareon/tests/forms.rs rename to cot/tests/forms.rs index 84a3b6e..b281428 100644 --- a/flareon/tests/forms.rs +++ b/cot/tests/forms.rs @@ -1,7 +1,7 @@ -use flareon::forms::{ +use cot::forms::{ Form, FormContext, FormErrorTarget, FormField, FormFieldValidationError, FormResult, }; -use flareon::test::TestRequestBuilder; +use cot::test::TestRequestBuilder; #[derive(Debug, Form)] struct MyForm { diff --git a/flareon/tests/router.rs b/cot/tests/router.rs similarity index 77% rename from flareon/tests/router.rs rename to cot/tests/router.rs index 18e48ba..58c10ed 100644 --- a/flareon/tests/router.rs +++ b/cot/tests/router.rs @@ -1,18 +1,18 @@ use bytes::Bytes; -use flareon::request::{Request, RequestExt}; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::test::Client; -use flareon::{Body, FlareonApp, FlareonProject, StatusCode}; +use cot::request::{Request, RequestExt}; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::test::Client; +use cot::{Body, CotApp, CotProject, StatusCode}; -async fn index(_request: Request) -> flareon::Result { +async fn index(_request: Request) -> cot::Result { Ok(Response::new_html( StatusCode::OK, Body::fixed("Hello world!"), )) } -async fn parameterized(request: Request) -> flareon::Result { +async fn parameterized(request: Request) -> cot::Result { let name = request.path_params().get("name").unwrap().to_owned(); Ok(Response::new_html(StatusCode::OK, Body::fixed(name))) @@ -45,9 +45,9 @@ async fn path_params() { } #[must_use] -async fn project() -> FlareonProject { +async fn project() -> CotProject { struct RouterApp; - impl FlareonApp for RouterApp { + impl CotApp for RouterApp { fn name(&self) -> &'static str { "router-app" } @@ -60,7 +60,7 @@ async fn project() -> FlareonProject { } } - FlareonProject::builder() + CotProject::builder() .register_app_with_views(RouterApp, "") .build() .await diff --git a/examples/admin/Cargo.toml b/examples/admin/Cargo.toml index 2f627c5..071b240 100644 --- a/examples/admin/Cargo.toml +++ b/examples/admin/Cargo.toml @@ -2,8 +2,8 @@ name = "example-admin" version = "0.1.0" publish = false -description = "Admin panel - Flareon example." +description = "Admin panel - Cot example." edition = "2021" [dependencies] -flareon = { path = "../../flareon" } +cot = { path = "../../cot" } diff --git a/examples/admin/src/main.rs b/examples/admin/src/main.rs index 4c84ade..f8a2b3e 100644 --- a/examples/admin/src/main.rs +++ b/examples/admin/src/main.rs @@ -1,27 +1,27 @@ -use flareon::__private::async_trait; -use flareon::admin::AdminApp; -use flareon::auth::db::{DatabaseUser, DatabaseUserApp}; -use flareon::config::{DatabaseConfig, ProjectConfig}; -use flareon::middleware::SessionMiddleware; -use flareon::request::Request; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::static_files::StaticFilesMiddleware; -use flareon::{AppContext, Body, FlareonApp, FlareonProject, StatusCode}; - -async fn hello(_request: Request) -> flareon::Result { +use cot::__private::async_trait; +use cot::admin::AdminApp; +use cot::auth::db::{DatabaseUser, DatabaseUserApp}; +use cot::config::{DatabaseConfig, ProjectConfig}; +use cot::middleware::SessionMiddleware; +use cot::request::Request; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::static_files::StaticFilesMiddleware; +use cot::{AppContext, Body, CotApp, CotProject, StatusCode}; + +async fn hello(_request: Request) -> cot::Result { Ok(Response::new_html(StatusCode::OK, Body::fixed("xd"))) } struct HelloApp; #[async_trait] -impl FlareonApp for HelloApp { +impl CotApp for HelloApp { fn name(&self) -> &'static str { env!("CARGO_PKG_NAME") } - async fn init(&self, context: &mut AppContext) -> flareon::Result<()> { + async fn init(&self, context: &mut AppContext) -> cot::Result<()> { // TODO use transaction let user = DatabaseUser::get_by_username(context.database(), "admin").await?; if user.is_none() { @@ -36,9 +36,9 @@ impl FlareonApp for HelloApp { } } -#[flareon::main] -async fn main() -> flareon::Result { - let flareon_project = FlareonProject::builder() +#[cot::main] +async fn main() -> cot::Result { + let cot_project = CotProject::builder() .config( ProjectConfig::builder() .database_config( @@ -57,5 +57,5 @@ async fn main() -> flareon::Result { .build() .await?; - Ok(flareon_project) + Ok(cot_project) } diff --git a/examples/admin/templates/name.html b/examples/admin/templates/name.html index 1c3f6f0..150e9fe 100644 --- a/examples/admin/templates/name.html +++ b/examples/admin/templates/name.html @@ -9,7 +9,7 @@

Hello!

-
+
diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world/Cargo.toml index 42c46ba..691506e 100644 --- a/examples/hello-world/Cargo.toml +++ b/examples/hello-world/Cargo.toml @@ -2,8 +2,8 @@ name = "example-hello-world" version = "0.1.0" publish = false -description = "Hello World - Flareon example." +description = "Hello World - Cot example." edition = "2021" [dependencies] -flareon = { path = "../../flareon" } +cot = { path = "../../cot" } diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs index 1d766af..dad35b1 100644 --- a/examples/hello-world/src/main.rs +++ b/examples/hello-world/src/main.rs @@ -1,18 +1,18 @@ -use flareon::request::Request; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::{Body, FlareonApp, FlareonProject, StatusCode}; +use cot::request::Request; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::{Body, CotApp, CotProject, StatusCode}; -async fn return_hello(_request: Request) -> flareon::Result { +async fn return_hello(_request: Request) -> cot::Result { Ok(Response::new_html( StatusCode::OK, - Body::fixed("

Hello Flareon!

".as_bytes().to_vec()), + Body::fixed("

Hello Cot!

".as_bytes().to_vec()), )) } struct HelloApp; -impl FlareonApp for HelloApp { +impl CotApp for HelloApp { fn name(&self) -> &'static str { env!("CARGO_PKG_NAME") } @@ -22,12 +22,12 @@ impl FlareonApp for HelloApp { } } -#[flareon::main] -async fn main() -> flareon::Result { - let flareon_project = FlareonProject::builder() +#[cot::main] +async fn main() -> cot::Result { + let cot_project = CotProject::builder() .register_app_with_views(HelloApp, "") .build() .await?; - Ok(flareon_project) + Ok(cot_project) } diff --git a/examples/json/Cargo.toml b/examples/json/Cargo.toml index c025e73..9293b5b 100644 --- a/examples/json/Cargo.toml +++ b/examples/json/Cargo.toml @@ -2,9 +2,9 @@ name = "example-json" version = "0.1.0" publish = false -description = "JSON - Flareon example." +description = "JSON - Cot example." edition = "2021" [dependencies] -flareon = { path = "../../flareon" } +cot = { path = "../../cot" } serde = "1" diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index d547c54..792b477 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -1,7 +1,7 @@ -use flareon::request::{Request, RequestExt}; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::{FlareonApp, FlareonProject, StatusCode}; +use cot::request::{Request, RequestExt}; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::{CotApp, CotProject, StatusCode}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize)] @@ -15,7 +15,7 @@ struct AddResponse { result: i32, } -async fn add(mut request: Request) -> flareon::Result { +async fn add(mut request: Request) -> cot::Result { let add_request: AddRequest = request.json().await?; let response = AddResponse { result: add_request.a + add_request.b, @@ -26,7 +26,7 @@ async fn add(mut request: Request) -> flareon::Result { struct AddApp; -impl FlareonApp for AddApp { +impl CotApp for AddApp { fn name(&self) -> &'static str { env!("CARGO_PKG_NAME") } @@ -39,12 +39,12 @@ impl FlareonApp for AddApp { // Test with: // curl --header "Content-Type: application/json" --request POST --data '{"a": 123, "b": 456}' 'http://127.0.0.1:8080/' -#[flareon::main] -async fn main() -> flareon::Result { - let flareon_project = FlareonProject::builder() +#[cot::main] +async fn main() -> cot::Result { + let cot_project = CotProject::builder() .register_app_with_views(AddApp, "") .build() .await?; - Ok(flareon_project) + Ok(cot_project) } diff --git a/examples/sessions/Cargo.toml b/examples/sessions/Cargo.toml index e67f3de..5899747 100644 --- a/examples/sessions/Cargo.toml +++ b/examples/sessions/Cargo.toml @@ -2,9 +2,9 @@ name = "example-sessions" version = "0.1.0" publish = false -description = "Sessions - Flareon example." +description = "Sessions - Cot example." edition = "2021" [dependencies] -flareon = { path = "../../flareon" } +cot = { path = "../../cot" } rinja = "0.3.5" diff --git a/examples/sessions/src/main.rs b/examples/sessions/src/main.rs index 35a6330..312c1f0 100644 --- a/examples/sessions/src/main.rs +++ b/examples/sessions/src/main.rs @@ -1,9 +1,9 @@ -use flareon::forms::Form; -use flareon::middleware::SessionMiddleware; -use flareon::request::{Request, RequestExt}; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::{reverse, Body, FlareonApp, FlareonProject, StatusCode}; +use cot::forms::Form; +use cot::middleware::SessionMiddleware; +use cot::request::{Request, RequestExt}; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::{reverse, Body, CotApp, CotProject, StatusCode}; use rinja::Template; #[derive(Debug, Template)] @@ -25,7 +25,7 @@ struct NameForm { name: String, } -async fn hello(request: Request) -> flareon::Result { +async fn hello(request: Request) -> cot::Result { let name: String = request .session() .get("user_name") @@ -47,8 +47,8 @@ async fn hello(request: Request) -> flareon::Result { )) } -async fn name(mut request: Request) -> flareon::Result { - if request.method() == flareon::Method::POST { +async fn name(mut request: Request) -> cot::Result { + if request.method() == cot::Method::POST { let name_form = NameForm::from_request(&mut request).await?.unwrap(); request .session_mut() @@ -69,7 +69,7 @@ async fn name(mut request: Request) -> flareon::Result { struct HelloApp; -impl FlareonApp for HelloApp { +impl CotApp for HelloApp { fn name(&self) -> &'static str { env!("CARGO_PKG_NAME") } @@ -82,13 +82,13 @@ impl FlareonApp for HelloApp { } } -#[flareon::main] -async fn main() -> flareon::Result { - let flareon_project = FlareonProject::builder() +#[cot::main] +async fn main() -> cot::Result { + let cot_project = CotProject::builder() .register_app_with_views(HelloApp, "") .middleware(SessionMiddleware::new()) .build() .await?; - Ok(flareon_project) + Ok(cot_project) } diff --git a/examples/sessions/templates/name.html b/examples/sessions/templates/name.html index 1c3f6f0..150e9fe 100644 --- a/examples/sessions/templates/name.html +++ b/examples/sessions/templates/name.html @@ -9,7 +9,7 @@

Hello!

-
+
diff --git a/examples/todo-list/Cargo.toml b/examples/todo-list/Cargo.toml index 3ecc3b3..d68e3ff 100644 --- a/examples/todo-list/Cargo.toml +++ b/examples/todo-list/Cargo.toml @@ -2,9 +2,9 @@ name = "example-todo-list" version = "0.1.0" publish = false -description = "TODO List - Flareon example." +description = "TODO List - Cot example." edition = "2021" [dependencies] -flareon = { path = "../../flareon" } +cot = { path = "../../cot" } rinja = "0.3.5" diff --git a/examples/todo-list/src/main.rs b/examples/todo-list/src/main.rs index fba964b..5ca9e4f 100644 --- a/examples/todo-list/src/main.rs +++ b/examples/todo-list/src/main.rs @@ -1,13 +1,13 @@ mod migrations; -use flareon::config::{DatabaseConfig, ProjectConfig}; -use flareon::db::migrations::DynMigration; -use flareon::db::{model, query, Model}; -use flareon::forms::Form; -use flareon::request::{Request, RequestExt}; -use flareon::response::{Response, ResponseExt}; -use flareon::router::{Route, Router}; -use flareon::{reverse, Body, FlareonApp, FlareonProject, StatusCode}; +use cot::config::{DatabaseConfig, ProjectConfig}; +use cot::db::migrations::DynMigration; +use cot::db::{model, query, Model}; +use cot::forms::Form; +use cot::request::{Request, RequestExt}; +use cot::response::{Response, ResponseExt}; +use cot::router::{Route, Router}; +use cot::{reverse, Body, CotApp, CotProject, StatusCode}; use rinja::Template; #[derive(Debug, Clone)] @@ -24,7 +24,7 @@ struct IndexTemplate<'a> { todo_items: Vec, } -async fn index(request: Request) -> flareon::Result { +async fn index(request: Request) -> cot::Result { let todo_items = TodoItem::objects().all(request.db()).await?; let index_template = IndexTemplate { request: &request, @@ -41,7 +41,7 @@ struct TodoForm { title: String, } -async fn add_todo(mut request: Request) -> flareon::Result { +async fn add_todo(mut request: Request) -> cot::Result { let todo_form = TodoForm::from_request(&mut request).await?.unwrap(); { @@ -56,7 +56,7 @@ async fn add_todo(mut request: Request) -> flareon::Result { Ok(reverse!(request, "index")) } -async fn remove_todo(request: Request) -> flareon::Result { +async fn remove_todo(request: Request) -> cot::Result { let todo_id = request .path_params() .get("todo_id") @@ -74,7 +74,7 @@ async fn remove_todo(request: Request) -> flareon::Result { struct TodoApp; -impl FlareonApp for TodoApp { +impl CotApp for TodoApp { fn name(&self) -> &'static str { "todo-app" } @@ -98,9 +98,9 @@ impl FlareonApp for TodoApp { } } -#[flareon::main] -async fn main() -> flareon::Result { - let todo_project = FlareonProject::builder() +#[cot::main] +async fn main() -> cot::Result { + let todo_project = CotProject::builder() .config( ProjectConfig::builder() .database_config( diff --git a/examples/todo-list/src/migrations.rs b/examples/todo-list/src/migrations.rs index 6684fda..76244eb 100644 --- a/examples/todo-list/src/migrations.rs +++ b/examples/todo-list/src/migrations.rs @@ -1,4 +1,4 @@ mod m_0001_initial; -pub(crate) const MIGRATIONS: &[&dyn ::flareon::db::migrations::DynMigration] = +pub(crate) const MIGRATIONS: &[&dyn ::cot::db::migrations::DynMigration] = &[&m_0001_initial::Migration]; diff --git a/examples/todo-list/src/migrations/m_0001_initial.rs b/examples/todo-list/src/migrations/m_0001_initial.rs index 7ae4043..d5f6fa7 100644 --- a/examples/todo-list/src/migrations/m_0001_initial.rs +++ b/examples/todo-list/src/migrations/m_0001_initial.rs @@ -1,31 +1,31 @@ -//! Generated by flareon CLI 0.1.0 on 2024-08-28 13:39:05+00:00 +//! Generated by cot CLI 0.1.0 on 2024-08-28 13:39:05+00:00 #[derive(Clone)] pub(super) struct Migration; -impl ::flareon::db::migrations::Migration for Migration { +impl ::cot::db::migrations::Migration for Migration { const APP_NAME: &'static str = "example-todo-list"; const MIGRATION_NAME: &'static str = "m_0001_initial"; - const DEPENDENCIES: &'static [::flareon::db::migrations::MigrationDependency] = &[]; - const OPERATIONS: &'static [::flareon::db::migrations::Operation] = - &[::flareon::db::migrations::Operation::create_model() - .table_name(::flareon::db::Identifier::new("todo_item")) + const DEPENDENCIES: &'static [::cot::db::migrations::MigrationDependency] = &[]; + const OPERATIONS: &'static [::cot::db::migrations::Operation] = + &[::cot::db::migrations::Operation::create_model() + .table_name(::cot::db::Identifier::new("todo_item")) .fields(&[ - ::flareon::db::migrations::Field::new( - ::flareon::db::Identifier::new("id"), - ::TYPE, + ::cot::db::migrations::Field::new( + ::cot::db::Identifier::new("id"), + ::TYPE, ) .auto() .primary_key(), - ::flareon::db::migrations::Field::new( - ::flareon::db::Identifier::new("title"), - ::TYPE, + ::cot::db::migrations::Field::new( + ::cot::db::Identifier::new("title"), + ::TYPE, ), ]) .build()]; } #[derive(::core::fmt::Debug)] -#[::flareon::db::model(model_type = "migration")] +#[::cot::db::model(model_type = "migration")] struct _TodoItem { id: i32, title: String, diff --git a/examples/todo-list/templates/index.html b/examples/todo-list/templates/index.html index f179d26..4bb8ada 100644 --- a/examples/todo-list/templates/index.html +++ b/examples/todo-list/templates/index.html @@ -9,7 +9,7 @@

TODO List

-
+
@@ -17,7 +17,7 @@

TODO List

{% for todo in todo_items %}
  • {% let todo_id = todo.id %} -
    todo_id) }}" method="post"> + todo_id) }}" method="post"> {{ todo.title }}
    diff --git a/flareon-macros/tests/ui/attr_main.rs b/flareon-macros/tests/ui/attr_main.rs deleted file mode 100644 index 0b028c4..0000000 --- a/flareon-macros/tests/ui/attr_main.rs +++ /dev/null @@ -1,6 +0,0 @@ -use flareon::FlareonProject; - -#[flareon::main] -async fn main() -> flareon::Result { - std::process::exit(0); -} diff --git a/flareon-macros/tests/ui/attr_main_args.rs b/flareon-macros/tests/ui/attr_main_args.rs deleted file mode 100644 index e69d3ab..0000000 --- a/flareon-macros/tests/ui/attr_main_args.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[flareon::main] -async fn main(arg: i32) -> flareon::Result { - std::process::exit(0); -} diff --git a/flareon/src/auth/db/migrations.rs b/flareon/src/auth/db/migrations.rs deleted file mode 100644 index 2e5d022..0000000 --- a/flareon/src/auth/db/migrations.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod m_0001_initial; - -pub const MIGRATIONS: &[&dyn ::flareon::db::migrations::DynMigration] = - &[&m_0001_initial::Migration]; diff --git a/flareon/src/auth/db/migrations/m_0001_initial.rs b/flareon/src/auth/db/migrations/m_0001_initial.rs deleted file mode 100644 index 821822d..0000000 --- a/flareon/src/auth/db/migrations/m_0001_initial.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Generated by flareon CLI 0.1.0 on 2024-11-12 15:49:48+00:00 - -#[derive(Debug, Copy, Clone)] -pub(super) struct Migration; -impl ::flareon::db::migrations::Migration for Migration { - const APP_NAME: &'static str = "flareon_auth"; - const MIGRATION_NAME: &'static str = "m_0001_initial"; - const DEPENDENCIES: &'static [::flareon::db::migrations::MigrationDependency] = &[]; - const OPERATIONS: &'static [::flareon::db::migrations::Operation] = &[ - ::flareon::db::migrations::Operation::create_model() - .table_name(::flareon::db::Identifier::new("database_user")) - .fields( - &[ - ::flareon::db::migrations::Field::new( - ::flareon::db::Identifier::new("id"), - ::TYPE, - ) - .auto() - .primary_key() - .set_null(::NULLABLE), - ::flareon::db::migrations::Field::new( - ::flareon::db::Identifier::new("username"), - as ::flareon::db::DatabaseField>::TYPE, - ) - .set_null( - as ::flareon::db::DatabaseField>::NULLABLE, - ) - .unique(), - ::flareon::db::migrations::Field::new( - ::flareon::db::Identifier::new("password"), - ::TYPE, - ) - .set_null( - ::NULLABLE, - ), - ], - ) - .build(), - ]; -} - -#[derive(::core::fmt::Debug)] -#[::flareon::db::model(model_type = "migration")] -struct _DatabaseUser { - id: i64, - #[model(unique)] - username: crate::db::LimitedString<{ crate::auth::db::MAX_USERNAME_LENGTH }>, - password: crate::auth::PasswordHash, -}