174 Commits

Author SHA1 Message Date
Bob Farrell
c26d563898 Zig 0.15 compatibility
Various dependencies updated after changes to `std.zig.Ast` and
`std.LinkedList` and other things.
2025-04-09 20:08:38 +01:00
Bob Farrell
2cb1b4e959 Adjust test, fix memory leak in hashPassword, deinit repo on test app deinit 2025-03-23 13:28:09 +00:00
blurrycat
544b33e279 Fix anonymous struct literal in log_thread spawn 2025-03-06 19:59:01 +01:00
dongsu8142
501c6184a5
Merge branch 'jetzig-framework:main' into middleware-fix 2025-03-03 12:20:07 +09:00
Bob Farrell
099a2a5349 Use Zig compiler
Default to not using LLVM for application compilation. This gives more
than 2x performance improvement for compilation stage.
2025-03-01 14:33:17 +00:00
dongsu8142
719bd300a7 Fix compression middleware 2025-02-26 22:24:01 +09:00
Ben Jordan
0a4690e001
Switched HX-Target header to HX-Request
Using a target like `hx-target="next div"` will not generate an HX-Target header if the target element does not have an ID. Judging by the comments it used to be HX-Request.
2025-02-17 19:29:42 -05:00
Bob Farrell
87c7adb50f Fix email recipients
Prevent breaking out of "To" recipient resolving when `name` is null -
this is a valid value as we only need the `email` field to deliver an
email successfully.
2025-02-15 17:52:30 +00:00
Bob Farrell
ecd66db3dc Fixes for misc. Zig nightly changes
* Removal of std.ArrayList.popOrNull
* Removal of std.mem.page_size
2025-02-13 18:23:04 +00:00
Bob Farrell
a5430ff380 Zig 0.14 test runner config changes
Update dependencies to match new Zig build config API for test runners,
misc. fixes needed after upgrading dependencies.
2025-02-02 11:31:40 +00:00
Bob Farrell
a99999af52 Misc. Zig updates
Changes to latest Zig nightly build required several minor fixes across
multiple dependencies.
2025-01-25 12:22:19 +00:00
Bob Farrell
350f9512e6 Latest Zig changes accommodation (missed one) 2024-12-22 12:57:52 +00:00
Bob Farrell
76f14a89a1 Zig build fixes for latest Zig nightly build 2024-12-22 12:34:11 +00:00
Bob Farrell
35adaf3009 Valkey backend for JetKV 2024-12-06 21:31:02 +00:00
Bob Farrell
9cf6705c88 Per-request database connection
Use JetQuery's new `Repo.bindConnect()` to get a new Repo bound to a
connection for each request. This significantly simplifies connection
management and offloads all the connection pool
management/reconnecting/etc. to pg.zig where it belongs.

Improve development mode SQL syntax highlighting - highlight `SELECT`,
`UPDATE`, `DELETE`, `INSERT` in different bolded colors for clarity.
2024-11-30 12:48:18 +00:00
Bob Farrell
1fa6db77df Make database repo available in background jobs 2024-11-27 20:43:35 +00:00
Bob Farrell
6bd0273e2d Fix default production cookie value 2024-11-24 21:14:28 +00:00
Bob Farrell
f44a6b33c5 Routing updates
Implement `/foo/1/edit` route/view.

Allow setting HTTP verb by passing e.g. `/_PATCH` as the last segment of
a URL - this allows browsers to submit a `POST` request with a
pseudo-HTTP verb encoded in the URL which Jetzig can translate, i.e.
allowing forms to submit a `PATCH`.
2024-11-24 20:46:56 +00:00
Bob Farrell
9684181c64 Fix middleware render detection 2024-11-23 19:31:37 +00:00
Bob Farrell
1565ae3b73 Debug console
Use `jetzig server` or `zig build -Ddebug_console=true run` to launch a
development server with the debug console enabled.

When an error is encountered a formatted stack trace is dumped to the
browser along with the current response data. Both outputs are
syntax-highlighted using Prism JS.
2024-11-23 18:07:19 +00:00
Bob Farrell
8095bbcb76 Implement request.renderTemplate
Clean up request state.
2024-11-23 13:42:14 +00:00
Bob Farrell
6e6f1bec1b Closes #108: Anti-CSRF middleware
Add to middleware in app's `src/main.zig`:

```zig
pub const jetzig_options = struct {
    pub const middleware: []const type = &.{
        jetzig.middleware.AntiCsrfMiddleware,
    };
};
```

CSRF token available in Zmpl templates:

```
{{context.authenticityToken()}}
```
or render a hidden form element:
```
{{context.authenticityFormElement()}}
```

The following HTML requests are rejected (403 Forbidden) if the
submitted query param does not match the value stored in the encrypted
session (added automatically when the token is generated for a template
value):

* POST
* PUT
* PATCH
* DELETE

JSON requests are not impacted - users should either disable JSON
endpoints or implement a different authentication method to protect
them.
2024-11-23 12:49:49 +00:00
Bob Farrell
92dce21244 Database CLI improvements
Eradication of `data` arg to requests. We no longer need to pass this
value around as we have a) type inference, b) nested object insertion
via `put` and `append`.

Fix `joinPath` numeric type coercion

Detect empty string params and treat them as blank with expectParams()

Fix error logging/stack trace printing.

Update Zmpl - includes debug tokens + error tracing to source template
in debug builds.
2024-11-19 21:39:01 +00:00
Bob Farrell
78b6938530 Fix custom routes
Fix CLI view generator
2024-11-17 19:32:46 +00:00
Bob Farrell
b95506caf9 Params helpers
Implement `request.expectParams()` to coerce params to a given struct.
`request.paramsInfo()` provides information about each param (present,
blank, failed + original values and errors where applicable).
2024-11-17 19:07:27 +00:00
Bob Farrell
e3ab49fa5a Refactor Route
Move all route types into a single union and remove leftover junk.

Deprecate view functions that receive a `*jetzig.Data` argument (we will
stay backward-compatible until we have a valid reason to drop support
for legacy view functions - the extra code overhead is pretty minimal).
2024-11-17 15:08:54 +00:00
Bob Farrell
49c5c2db26 Update dependencies
Add assertion to verify compatible jetcommon versions between
dependencies.
2024-11-17 12:34:49 +00:00
Bob Farrell
f3b56e14ea Fix admin database schema detection
Fix missing optional database name type when reading from config
2024-11-17 10:50:03 +00:00
Bob Farrell
e12b69985b Fix database CLI environment variables config
Use the same environment setup as the main Jetzig app when running
database CLI commands.
2024-11-16 17:16:29 +00:00
Bob Farrell
2cff123de7 Fix database launch message
When an environment variable configures the database name we connect to,
we need to wrap the field access in a comptime check even if the
`orelse` block never runs.
2024-11-16 16:04:16 +00:00
Bob Farrell
9ebf0d40e6 Fix initial Schema creation
Update JetQuery - `optional` replaces `not_null` and defaults to `false`,
i.e. columns have a `NOT NULL` constraint by default.
2024-11-14 20:18:28 +00:00
Bob Farrell
b1dc086afb GH actions fixes
Fix `/.json` root path detection
2024-11-14 18:54:26 +00:00
Bob Farrell
c5acaedb73 Strip trailing slash on URIs
`/blogs/` is now the same as `/blogs`.

Root path `/` is a special case.
2024-11-13 20:57:25 +00:00
Bob Farrell
c8ae44b508 Accept password at command line for auth user create
Intended for local development only
2024-11-13 20:35:50 +00:00
Bob Farrell
2dd2f7ae74 Add null logger
Silence logs completely when `null` logger is active.

Add pool size/timeout environment variable configuration for JetQuery.
2024-11-12 22:20:13 +00:00
Bob Farrell
bed91b2131 Fix development logger colors on Windows 2024-11-12 08:52:32 +00:00
Bob Farrell
e4da5bc9c8 Fix broken type detection in database setup 2024-11-12 08:21:51 +00:00
Bob Farrell
a6d1b92f5e Simplify DevelopmentLogger, add ProductionLogger
Add auth helper to create a user from CLI:

```
jetzig auth user:create user@example.com
```
2024-11-11 22:25:35 +00:00
Bob Farrell
d27907a1c5 WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
4210aa5e83 WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
6f8de03f07 WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
f3bcff6387 WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
4793262a5e WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
6c53ccf8fc WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
320c2706ae WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
405762504d WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
dc11412587 WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
fa5b3f240e WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
72a704b8cb WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
b07f5adb8c WIP 2024-11-09 17:13:32 +00:00