@orieljs/framework 0.1.0-alpha.15 → 0.1.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/{chunk-GCMPAXIK.js → chunk-3QHTNAMZ.js} +6 -4
  2. package/dist/{chunk-GCMPAXIK.js.map → chunk-3QHTNAMZ.js.map} +1 -1
  3. package/dist/{chunk-BKA5F3TH.js → chunk-6AXJB4CD.js} +5 -1
  4. package/dist/chunk-6AXJB4CD.js.map +1 -0
  5. package/dist/{chunk-7GPMFMS7.js → chunk-MG4YEWMV.js} +1239 -488
  6. package/dist/chunk-MG4YEWMV.js.map +1 -0
  7. package/dist/{chunk-FVI6X3VJ.js → chunk-YNDMTTWL.js} +114 -8
  8. package/dist/chunk-YNDMTTWL.js.map +1 -0
  9. package/dist/contracts.d.ts +112 -1
  10. package/dist/contracts.js +5 -1
  11. package/dist/{index.d-lffxurFs.d.ts → index.d-DA-Iu2a2.d.ts} +39 -2
  12. package/dist/index.d.ts +2780 -2137
  13. package/dist/index.js +1410 -543
  14. package/dist/index.js.map +1 -1
  15. package/dist/{jsx-runtime-Bc5KJzwb.d.ts → jsx-runtime-CenT41Y0.d.ts} +1 -1
  16. package/dist/jsx-runtime.d.ts +2 -2
  17. package/dist/jsx-runtime.js +3 -3
  18. package/dist/{testing-CVpo7aRl.d.ts → testing-B8J_HhF4.d.ts} +6 -2
  19. package/dist/testing.d.ts +2 -2
  20. package/dist/testing.js +3 -3
  21. package/docs/authentication.md +45 -3
  22. package/docs/authorization.md +2 -4
  23. package/docs/cache.md +29 -5
  24. package/docs/configuration.md +84 -7
  25. package/docs/console.md +41 -2
  26. package/docs/container.md +4 -0
  27. package/docs/csrf.md +2 -2
  28. package/docs/database.md +22 -0
  29. package/docs/deployment.md +39 -17
  30. package/docs/eloquent-factories.md +4 -3
  31. package/docs/eloquent-mutators.md +2 -1
  32. package/docs/eloquent-relationships.md +28 -3
  33. package/docs/eloquent-resources.md +253 -0
  34. package/docs/eloquent.md +41 -0
  35. package/docs/errors.md +12 -3
  36. package/docs/events.md +3 -1
  37. package/docs/facades.md +1 -0
  38. package/docs/helpers.md +33 -2
  39. package/docs/inertia.md +11 -2
  40. package/docs/installation.md +4 -2
  41. package/docs/laravel.md +71 -0
  42. package/docs/lifecycle.md +5 -2
  43. package/docs/live.md +88 -8
  44. package/docs/mail.md +28 -3
  45. package/docs/middleware.md +20 -12
  46. package/docs/navigation.json +8 -0
  47. package/docs/notifications.md +22 -0
  48. package/docs/pagination.md +4 -0
  49. package/docs/passwords.md +4 -6
  50. package/docs/providers.md +3 -5
  51. package/docs/queues.md +64 -2
  52. package/docs/requests.md +42 -3
  53. package/docs/responses.md +7 -4
  54. package/docs/routing.md +85 -7
  55. package/docs/scheduling.md +25 -0
  56. package/docs/session.md +2 -2
  57. package/docs/starter-kits.md +26 -7
  58. package/docs/storage.md +10 -4
  59. package/docs/testing.md +10 -2
  60. package/docs/two-factor.md +34 -1
  61. package/docs/upgrade.md +111 -2
  62. package/docs/validation.md +70 -9
  63. package/docs/views.md +1 -0
  64. package/docs/vite.md +2 -1
  65. package/package.json +43 -35
  66. package/dist/chunk-7GPMFMS7.js.map +0 -1
  67. package/dist/chunk-BKA5F3TH.js.map +0 -1
  68. package/dist/chunk-FVI6X3VJ.js.map +0 -1
@@ -280,3 +280,28 @@ Schedule.command('emails:send')
280
280
 
281
281
  `then()` is another name for `after()`. A task skipped by a constraint, an overlap or another server runs none of
282
282
  its hooks.
283
+
284
+ ## Events
285
+
286
+ The scheduler dispatches Laravel's [events](events.md) as it runs each due task, in `schedule:run`, `schedule:work`
287
+ and the Vercel cron alike. Each has the scheduled `task`:
288
+
289
+ - `ScheduledTaskStarting` before the task runs, once its constraints have passed and its locks are taken;
290
+ - `ScheduledTaskFinished` once it has run, with its `runtime` in seconds, to two decimals;
291
+ - `ScheduledTaskFailed` when it fails, with the `exception`. A task that throws dispatches only this one; a command
292
+ that exits non-zero, or a closure that returns `false`, dispatches `ScheduledTaskFinished` first, as in Laravel;
293
+ - `ScheduledTaskSkipped` when a `when()` or `skip()` constraint holds a due task back.
294
+
295
+ A task held back by `withoutOverlapping()` or `onOneServer()` dispatches none of them.
296
+
297
+ ```ts title="app/Providers/AppServiceProvider.ts"
298
+ import { Event, Log, ScheduledTaskFailed, ServiceProvider } from '@orieljs/framework'
299
+
300
+ export class AppServiceProvider extends ServiceProvider {
301
+ override boot(): void {
302
+ Event.listen(ScheduledTaskFailed, (event: ScheduledTaskFailed) => {
303
+ void Log.error(`${event.task.getSummaryForDisplay()} failed`, { error: String(event.exception) })
304
+ })
305
+ }
306
+ }
307
+ ```
package/docs/session.md CHANGED
@@ -103,8 +103,8 @@ time that session is written.
103
103
 
104
104
  The `redis` driver talks to the Redis server of `config/database.ts`: `connection` names an entry of
105
105
  `database.redis` (`default` unless you set `SESSION_CONNECTION`). Its keys start with `oriel_session:` and expire after
106
- `lifetime`. Oriel's Redis client, `ioredis`, comes with the framework, and the connection is closed when your app shuts
107
- down.
106
+ `lifetime`. The driver needs Oriel's Redis client, `ioredis`, which you install yourself (`npm install ioredis`), and
107
+ the connection is closed when your app shuts down.
108
108
 
109
109
  ## Interacting with the session
110
110
 
@@ -129,7 +129,7 @@ The Live kit's pages are components in `app/Live`, and its other markup is in `r
129
129
  | `resources/js/app.ts` | Starts Live in the browser, with the Light / Dark / System switch, the menus, and the dashboard's Copy buttons and tick |
130
130
 
131
131
  A Live page's route names its component: `Route.get('login', Login)`. Every update the browser sends runs the page
132
- route's `auth`, `verified`, `guest` and `can` middleware again, so a signed-out tab can't run an action. TypeScript's
132
+ route's `auth`, `verified`, `guest`, `can` and `password.confirm` middleware again, so a signed-out tab can't run an action. TypeScript's
133
133
  `private` doesn't hide a method from the browser: name it with `#` or a leading `_`, or mark it `@Locked`.
134
134
  [Live](live.md) explains components.
135
135
 
@@ -236,16 +236,33 @@ welcome page in `routes/web.ts`:
236
236
  | `/settings` | `GET` | | A redirect to `/settings/profile` |
237
237
  | `/settings/profile` | `GET`, `PATCH`, `DELETE` | `profile.edit`, `profile.update`, `profile.destroy` | The profile page, updating the name and email, and deleting the account |
238
238
  | `/settings/password` | `GET`, `PUT` | `password.edit`, `password.update` | The password page, and changing the password |
239
+ | `/settings/two-factor` | `GET`, `POST`, `DELETE` | `two-factor.show`, `two-factor.enable`, `two-factor.disable` | The two-factor page, setting up an app, and turning it off |
240
+ | `/settings/two-factor/confirm` | `POST` | `two-factor.confirm` | Confirming the app with its first code |
241
+ | `/settings/two-factor/recovery-codes` | `POST` | `two-factor.regenerate-recovery-codes` | New recovery codes |
239
242
  | `/settings/appearance` | `GET` | `appearance.edit` | The appearance page |
243
+ | `/confirm-password` | `GET`, `POST` | `password.confirm`, `password.confirm.store` | The password confirmation page, and confirming |
244
+ | `/two-factor-challenge` | `GET`, `POST` | `two-factor.login`, `two-factor.login.store` | The code asked for at login, and sending it |
240
245
 
241
246
  Where a URI has two methods and one name, the name is the `GET` route's. The guest pages are behind the `guest`
242
- middleware, and the rest behind `auth`. In the Live kit, a page's route is a `GET` route to its component, and the
247
+ middleware, and the rest behind `auth`; the two-factor settings also behind `password.confirm`, and the challenge
248
+ behind `guest` and `two-factor.challenge`. In the Live kit, a page's route is a `GET` route to its component, and the
243
249
  forms are the component's actions: the `POST`, `PATCH`, `PUT` and `DELETE` routes, and `logout` and
244
250
  `verification.send`, aren't there. `node oriel route:list` shows them all.
245
251
 
246
- > [!NOTE]
247
- > Laravel's starter kits also have two-factor authentication and a password confirmation page. Oriel's kits have
248
- > neither.
252
+ ### Two-factor authentication
253
+
254
+ Settings → Two-factor asks for the password first, then not again for `auth.password_timeout` seconds (three hours).
255
+ There a user sets up an authenticator app: the page shows a QR code and the setup key, and the app's first code turns
256
+ two-factor on. The page then shows eight recovery codes, once, with a link to download them; it can make new ones, and
257
+ turn two-factor off. From then on, logging in asks for a code from the app, or a recovery code, each of which works
258
+ once.
259
+
260
+ The setup key and the codes stay off the browser's history: the Inertia kits encrypt the page's history state and
261
+ clear it when the user logs out, and the Live kit drops them from the page as it is left.
262
+
263
+ The kits set `two_factor: { enabled: true, methods: ['app'] }` in `config/auth.ts`, so it is each user's choice: a
264
+ user who hasn't set up an app signs in with the password alone. [Two-factor login](two-factor.md) covers the settings,
265
+ and email codes, which the kits don't offer.
249
266
 
250
267
  ### Email verification
251
268
 
@@ -288,11 +305,13 @@ The kits limit the routes an attacker would try many times:
288
305
  | Signing in | 5 failed attempts per email address and IP address, then locked for a minute |
289
306
  | The verification link, and sending it again | 6 requests a minute (`throttle:6,1`) |
290
307
  | Changing the password | 6 requests a minute (`throttle:6,1`) |
308
+ | Confirming the password | 6 requests a minute (`throttle:6,1`) |
309
+ | A two-factor code at login | 5 a minute for each account (the `two-factor` limiter in `routes/auth.ts`), and 5 wrong codes end the login |
291
310
  | Sending a reset link | One link per email address a minute (`passwords.users.throttle` in `config/auth.ts`) |
292
311
 
293
312
  The login limit is in `LoginRequest`, in `app/Http/Requests/Auth` (in the Live kit, in the `Login` component): change
294
- the `5` in `tooManyAttempts()` to allow more. In the Live kit, sending the verification mail again and changing the
295
- password are component actions, which have no limit of their own.
313
+ the `5` in `tooManyAttempts()` to allow more. In the Live kit, the forms are component actions, which take no route
314
+ middleware: `throttle()`, in `app/Support/throttle.ts`, gives them the same limits.
296
315
 
297
316
  ### Customizing user creation
298
317
 
package/docs/storage.md CHANGED
@@ -20,7 +20,8 @@ import { Storage } from '@orieljs/framework'
20
20
  await Storage.disk('local').put('example.txt', 'Contents')
21
21
  ```
22
22
 
23
- A path that climbs out of the root with `../` throws.
23
+ A path that climbs out of the root with `../` throws. A new app's `local` disk has `serve: true`, so its files can be
24
+ shared through [temporary URLs](#temporary-urls), as in Laravel 11.
24
25
 
25
26
  ### The public disk
26
27
 
@@ -127,15 +128,20 @@ set), with the bucket as a subdomain, or in the path when `usePathStyleEndpoint`
127
128
 
128
129
  ### Temporary URLs
129
130
 
130
- On an S3 disk, `temporaryUrl()` gives a signed URL that works until the date you give:
131
+ `temporaryUrl()` gives a signed URL that works until the date you give, on an S3 disk and on a `local` disk with
132
+ `serve: true`:
131
133
 
132
134
  ```ts
133
135
  import { Storage } from '@orieljs/framework'
134
136
 
135
- const url = await Storage.disk('s3').temporaryUrl('report.pdf', new Date(Date.now() + 5 * 60_000))
137
+ const url = await Storage.disk('local').temporaryUrl('invoices/1042.pdf', new Date(Date.now() + 5 * 60_000))
136
138
  ```
137
139
 
138
- A `local` disk can't sign URLs, and throws.
140
+ A served `local` disk has a route, `storage.<disk>`, at its `url`'s path, else at `/storage`: the link above is
141
+ `<APP_URL>/storage/invoices/1042.pdf?expires=…&signature=…`, signed over its path and query with your `APP_KEY`. The
142
+ route sends the file inline, uncached and sandboxed, so nothing in it runs. A link that's altered or has expired gets
143
+ a 403, or a 404 in production, and a path with no file gets a 404. On a served disk whose `visibility` is `public`,
144
+ every file is sent, with or without a signature. A `local` disk without `serve: true` throws.
139
145
 
140
146
  ### File metadata
141
147
 
package/docs/testing.md CHANGED
@@ -123,8 +123,16 @@ node oriel test tests/Feature/User.test.ts
123
123
  node oriel test --filter="the application returns"
124
124
  ```
125
125
 
126
- Anything after `--` goes to Vitest as it is, such as `node oriel test -- --coverage` for a coverage report (with
127
- `@vitest/coverage-v8` installed).
126
+ Options `oriel test` doesn't know go to Vitest as they are, in their place, such as `--coverage` for a coverage report
127
+ (with `@vitest/coverage-v8` installed) or `-t` for a name pattern:
128
+
129
+ ```sh
130
+ node oriel test --coverage
131
+
132
+ node oriel test tests/Unit --reporter=dot
133
+ ```
134
+
135
+ So does anything after `--`, for an option `oriel` takes itself: `node oriel test -- --help` shows Vitest's help.
128
136
 
129
137
  ### Running tests in parallel
130
138
 
@@ -16,7 +16,10 @@ Each user has a method:
16
16
  - **Authenticator app**: the user scans a QR code with an app such as Google Authenticator or 1Password and confirms
17
17
  it with one code; from then on, the app's code is asked for.
18
18
 
19
- The starter kits don't have two-factor pages yet: you add the routes and pages your app needs, as below.
19
+ The browser [starter kits](starter-kits.md#two-factor-authentication) have it: Settings → Two-factor, behind a
20
+ password confirmation, sets up an authenticator app and shows its recovery codes, and logging in then asks for the
21
+ app's code. They set `methods: ['app']`, so a user who hasn't set up an app signs in with the password alone. The API
22
+ kit and the skeleton don't have it: add the routes and pages your app needs, as below.
20
23
 
21
24
  ## Turning it on
22
25
 
@@ -166,6 +169,10 @@ Route.middleware('auth').group(() => {
166
169
  on a working app throws `TwoFactorAppAlreadyEnabledError`, since a new secret would silently stop the old app's codes: call
167
170
  `disableApp(user)` first. Before the app is confirmed, calling `enableApp()` again just replaces the secret.
168
171
 
172
+ `TwoFactor.appSetup(user)` gives the same secret, URL and QR code again while the app waits for its code, so the page
173
+ can show them after a reload or a wrong code without a new secret. It is `undefined` before `enableApp()` and once the
174
+ app is confirmed.
175
+
169
176
  In a test, `totpCode(secret, Date.now())` from `@orieljs/framework` gives the code the app would show.
170
177
 
171
178
  ## Recovery codes
@@ -186,6 +193,32 @@ import type { User } from '../Models/User'
186
193
  TwoFactor.requireWhen((user) => (user as User).getAttribute('is_admin') === true)
187
194
  ```
188
195
 
196
+ ## Adding two-factor to an app made before alpha.16
197
+
198
+ An app made from a starter kit owns its copy of the kit's code, so upgrading Oriel adds no pages, and nobody is asked
199
+ for a code. To add what a new kit app has:
200
+
201
+ 1. Add the columns: `node oriel two-factor:install`, then `node oriel migrate`.
202
+ 2. Turn it on for the authenticator app only: `two_factor: { enabled: true, methods: ['app'] }` in `config/auth.ts`.
203
+ Not email: `TwoFactor`'s default method is email, which every user has from the start, so with it every user would
204
+ be asked for a mailed code at their next login.
205
+ 3. Hide the secret and the codes: `User`'s `hidden` gains `two_factor_secret` and `two_factor_recovery_codes`, and its
206
+ `casts` `two_factor_confirmed_at: 'datetime'`. Run `node oriel model:types` again.
207
+ 4. Ask for the code at login: `TwoFactor.attempt()` instead of `Auth.attempt()`, as in [Signing in](#signing-in). In
208
+ an Inertia kit that is `LoginRequest.authenticate()`, and `AuthenticatedSessionController.store()` redirects a
209
+ `'challenge'` to `two-factor.login`; in the Live kit, the `Login` component's `login()` does both. At a
210
+ `'challenge'`, put the email in the session as `login.email`: the `two-factor` rate limiter counts codes by it,
211
+ and by the IP address without it.
212
+ 5. Copy the rest from a new alpha.16 app of the same stack (`npm create @orieljs@latest`):
213
+ - **Inertia kits:** `ConfirmablePasswordController` and `TwoFactorChallengeController` (in
214
+ `app/Http/Controllers/Auth`), `Settings/TwoFactorController`, their routes in `routes/auth.ts` (with the
215
+ `two-factor` rate limiter) and `routes/settings.ts`, the pages `Auth/ConfirmPassword`, `Auth/TwoFactorChallenge`
216
+ and `Settings/TwoFactor`, and the Two-factor tab in `SettingsLayout` and the sidebar.
217
+ - **Live kit:** the `ConfirmPassword`, `TwoFactorChallenge` and `Settings/TwoFactor` components, `app/Support/throttle.ts`,
218
+ their routes, the tab in `components/settings/layout.tsx` and the sidebar, and the Copy button's lines in
219
+ `resources/js/app.ts`.
220
+ - **Both:** the two-factor styles at the end of `resources/css/app.css`, `tests/TwoFactor.ts` and the two-factor tests.
221
+
189
222
  ## Events
190
223
 
191
224
  `TwoFactorChallenged` (the code was asked for), `TwoFactorFailed` (a wrong code), `TwoFactorAuthenticated` (the user is
package/docs/upgrade.md CHANGED
@@ -25,6 +25,112 @@ node oriel migrate
25
25
  An app made before 0.1.0-alpha.15 has `^` ranges, which take a later release by themselves the next time the
26
26
  dependencies are installed without a lockfile. Pinning its packages as above stops that.
27
27
 
28
+ ## 0.1.0-alpha.16
29
+
30
+ - **A route middleware that returns nothing is an error**, as a global one is: a 500, "Middleware must return a
31
+ Response.", not an empty 204. Return what `next(request)` gives.
32
+ - **`throttle` runs before route model binding**, as Laravel's: a throttled request no longer looks its model up, and a
33
+ request for a missing model counts toward the limit.
34
+ - **`api/*` routes send CORS headers**, as in Laravel 11: a browser app on another origin can call them (no cookies or
35
+ credentials), and a preflight `OPTIONS` there answers 204. `node oriel install:api` writes `config/cors.ts` to change
36
+ it; `paths: []` or `middleware.remove(HandleCors)` turns it off. An app with its own CORS middleware keeps one of the
37
+ two.
38
+ - **Form fields and query keys nested deeper than 64 brackets answer 400**, as PHP stops at 64.
39
+ - **`serve()` reads `HOST`** (then `SERVER_HOST`) when it's given no `hostname`, and so does `node oriel serve` without
40
+ `--host`. If your server's environment sets `HOST` to something else, pass `hostname`. Node's keep-alive is now 65
41
+ seconds, past common load balancers' 60.
42
+ - **Every command takes Laravel's global options**: `-n`, `-q`, `-v`, `-V` and `--env`. A command that declares one of
43
+ those names keeps it, but `--env=<e>` also runs the app under that environment, loading `.env.<e>`: rename a
44
+ command's own `--env` option if it means something else.
45
+ - **`oriel serve` boots your app as `public/index.ts` does**: `runningInConsole()` is false, so factories,
46
+ `app/Console/Commands` and `routes/console.ts` aren't loaded in the server. Code that relied on them there imports
47
+ what it needs.
48
+ - **`make:policy` without `--model` writes an empty policy**, not one whose methods allow everything. Policies you
49
+ already have are unchanged.
50
+ - **`@orieljs/framework` no longer exports Oriel's internal helpers**, none of them meant for apps: from routing,
51
+ `orderForBindings`, `substituteBindings`, `dispatchRoute`, `mergeGroup`, `renderError`, `resolveMiddleware`,
52
+ `runMiddleware`, `resourceRoutes`, `compareRoutes`, `normalizePath`, `normalizeUri`, `parseParameters`, `toResponse`
53
+ and `healthResponse`; from the HTTP layer, `currentRequest`, `optionalCookieJar`, `optionalSession`, `requestScope`,
54
+ `clientAddress`, `setClientAddress`, `ipMatches`, `fromEntries`, `isBlank`, `mergeRecursive`, `normalizeLists`,
55
+ `parseBracketKey`, `sanitize`, `transformLeaves`, `extensionFromMime`, `exceedsJsonDepth`,
56
+ `applyMiddlewareCallbacks`, `applyExceptionCallbacks`, `statusFor`, `summarizeValidation`, `debugPage`, `escapeHtml`,
57
+ `minimalPage`, `stackFrames`, `statusText`, `bunRuntime`, `serveBun`, `serveNode`, `toWebRequest`, `writeResponse`,
58
+ `detectRuntime`, `servePublicFile`, `addApiRouting`, `API_ROUTES_STUB`, `filterRouteList`, `formatRouteList`,
59
+ `registerHttpCommands` and `routeListRows`; from the console, `suggest`, `parseArgv`, `parseSignature`,
60
+ `resolveArguments`, `resolveOptions` and `validateRequiredArguments`; their types; and the old `ClosureKernel`. If
61
+ you used one, copy it into your app.
62
+ - **A queue connection's `after_commit: true` now holds jobs dispatched inside a database transaction until it
63
+ commits**, a `DB.transaction()` or one `DB.beginTransaction()` opened, and drops them if it rolls back, as
64
+ Laravel's; it was ignored. The transaction `RefreshDatabase` opens around a test holds none. Queued listeners, mail and notifications
65
+ wait too. Inside the transaction, such a dispatch resolves with an empty job ID. A new app's connections have it off.
66
+ - **A route parameter whose `where()` pattern takes slashes keeps them in `route()`'s URLs**, as Laravel's:
67
+ `{path}` with `.*` gives `/docs/guides/intro.md`, not `/docs/guides%2Fintro.md`. Each segment is still encoded.
68
+ - **`alpha`, `alpha_num` and `alpha_dash` accept letters of every script**, as Laravel's: `José` and `中文` pass
69
+ `alpha` now. Write `alpha:ascii` (or `alpha_num:ascii`, `alpha_dash:ascii`) to keep accepting only ASCII.
70
+ - **A form request's `prepareForValidation()`, `after()` and `stopOnFirstFailure` are used**, as Laravel's: if one of
71
+ yours has a member of those names for something else, rename it. A test fake of `ValidationFactory` must return a
72
+ `Validator` with `safe()` and `stopOnFirstFailure()`.
73
+ - **The queue dispatches Laravel's job events**: `JobQueued`, `JobProcessing`, `JobProcessed` and `JobFailed`.
74
+ `Event.fake()` with no list records them too, so a test that queues or runs a job and then calls
75
+ `assertNothingDispatched()` fails: give `Event.fake()` the events the test is about.
76
+ - **Mail and notifications dispatch Laravel's events too**: `MessageSending` and `MessageSent`, and
77
+ `NotificationSending`, `NotificationSent` and `NotificationFailed`. A `MessageSending` listener that returns `false`
78
+ stops the message, so `sendNow()` may resolve `undefined`: `MailerImpl.sendNow()` is typed that way now, as the
79
+ `Mailer` contract already was.
80
+ - **The scheduler dispatches Laravel's task events**: `ScheduledTaskStarting`, `ScheduledTaskFinished`,
81
+ `ScheduledTaskFailed` and `ScheduledTaskSkipped`, so `Event.fake()` with no list records them as well.
82
+ - **On Vercel, work after the response goes to Vercel's `waitUntil()`**: `dispatchAfterResponse()` jobs, terminable
83
+ middleware and `terminating()` callbacks run once the function has answered, within its time limit.
84
+ - **`ioredis` and `nodemailer` no longer come with Oriel.** Install `ioredis` if your app uses a Redis cache store,
85
+ session driver or queue connection (`npm install ioredis`), and `nodemailer` for the `smtp` mailer in an app made
86
+ before 0.1.0-alpha.16 (`npm install nodemailer`; new apps list it). Each is loaded the first time it's needed, and
87
+ an app without it gets an error naming the package to install. `makeRedisClient()`, from the cache, queue and
88
+ session packages, now returns a promise, and `RedisRepository` takes only its store.
89
+ - **Seven contracts gained members**: `DatabaseConnection` has `afterCommit()`; `QueueManager` `before()`, `after()`
90
+ and `failing()`; `RateLimiter` `for()`, `limiter()` and `attempt()`; `HttpRequest` `safe()`;
91
+ `MiddlewareConfigurator` `remove()`, `trimStrings()`, `convertEmptyStringsToNull()`, `trustHosts()` and
92
+ `preventRequestsDuringMaintenance()`; `Application` `maintenanceMode()` and `isDownForMaintenance()`; and
93
+ `Validator` `safe()` and `stopOnFirstFailure()`. A test double of one in your app must add them; TypeScript lists
94
+ what's missing.
95
+ - **Some classes' signatures changed**: `SessionManager.redis()` returns a promise; `RedisStore` takes a client, a
96
+ connection or a function that makes one; `RedisSessionHandler` takes a function that makes its client;
97
+ `ThrottleRequests.handle()` takes its parameters as a rest; `MailManager.sendNow()` and `PendingMail.sendNow()`
98
+ resolve `SentMessage | undefined`; and the auth mixin no longer declares `getKey()`, so a model's own is used. A
99
+ subclass or a test stub of one takes the new shape.
100
+ - **The Live client reloads the page when an update answers 423**, as it does on 401: that is `password.confirm`'s
101
+ answer once a confirmation runs out. An action of yours that answers 423 for its own reason gets a reload.
102
+ - **A new app's `User` casts `password` as `hashed`.** To do the same in yours, add `password: 'hashed'` to the
103
+ model's `casts`: your `Hash.make()` calls keep working, as a hash is kept as it is.
104
+ - **An eager-load `limit()` on a `hasManyThrough` applies to each model too**, as on the other relations: each country
105
+ gets its own latest post, not one post for all the countries together.
106
+ - **Factory results with a count, `createMany()`, a relation's `createMany()` and an Eloquent paginator's
107
+ `getCollection()` are Eloquent collections**, as Laravel's. A relation's `createMany()` returned an array: use
108
+ `.all()`, `.first()` or `.count()` on it. On these, `only()`, `except()`, `unique()`, `diff()` and `contains(key)`
109
+ compare models by key.
110
+ - **`find()` and `findOrFail()` given a key typed `unknown` return a model or a collection**, as they do when the
111
+ key is an array when the request runs (`?id[]=1`): pass `String(id)`, or check the result. A model's `getKey()` is
112
+ now typed as a string, a number or a bigint (or nothing before the model is saved), so `find(model.getKey())`
113
+ still gives a model.
114
+ - **With `types/models.d.ts`, model writes are checked**: `create()`, `make()`, `fill()`, `forceFill()`, `update()`,
115
+ `forceCreate()`, `firstOrNew()`, `firstOrCreate()` and `updateOrCreate()` refuse a key that isn't a column (or a set
116
+ mutator's) and a value of the wrong type. Fix the key; keys known only at run time go in a `Record<string, unknown>`.
117
+ A validated field that isn't a column, which `fill()` would drop, is refused too: leave it out by name,
118
+ `const { tags, ...attributes } = validated`. Run `node oriel model:types` again: the file now gives each model a
119
+ `$self`, so its own methods' `this.update()` and `this.load()` are checked as well. A model method that returns
120
+ `this.load(…)` needs its return type written (TypeScript says it "implicitly has return type 'any'"). Models without
121
+ generated types, and a generic helper's `M extends Model`, take any attributes and relations, as before.
122
+ - **With `types/models.d.ts`, relation names are checked** in `with()`, `load()`, `loadMissing()`, `has()`,
123
+ `whereHas()`, `withCount()` and the aggregates: fix a misspelt one. A name held in a `string` still passes.
124
+ - **Page prop types follow a model's `visible` list, and leave out hidden appends and relations**, as `toJSON()` does,
125
+ and they type the relations `with()` and `load()` loaded and the model's appends: code reading a key the JSON
126
+ doesn't have no longer typechecks. Run `node oriel model:types` (or `migrate`) to regenerate `types/models.d.ts`.
127
+ - **`with()` and `load()` return types carry what they load**: a type test expecting exactly `EloquentCollection<Post>`
128
+ from them takes the new type.
129
+
130
+ New starter kits have two-factor login and password confirmation. An app made from a kit before alpha.16 keeps its
131
+ pages, and nobody is asked for a code: [Adding two-factor to an app made before
132
+ alpha.16](two-factor.md#adding-two-factor-to-an-app-made-before-alpha16) says what to copy.
133
+
28
134
  ## 0.1.0-alpha.15
29
135
 
30
136
  - **Oriel's packages are pinned in new apps.** Nothing to do in an existing app, but you can pin it the same way
@@ -33,8 +139,8 @@ dependencies are installed without a lockfile. Pinning its packages as above sto
33
139
  `find([1, 2])` expecting one model takes `.first()` of the result.
34
140
  - **Two app classes with the same name are stored in a queued job by their folder**, as `Events.OrderShipped` and
35
141
  `Mail.OrderShipped`. A class whose name is its own keeps it. Deploy your app and its workers together.
36
- - **A `limit()` in an eager-load constraint applies to each model**, as in Laravel 11: `Post.with({ comments: (q) =>
37
- q.limit(3) })` gives each post three comments. It needs SQLite 3.25, MySQL 8 or PostgreSQL.
142
+ - **A `limit()` in an eager-load constraint applies to each model**, as in Laravel 11: `Post.with({ comments: (query) =>
143
+ query.limit(3) })` gives each post three comments. It needs SQLite 3.25, MySQL 8 or PostgreSQL.
38
144
  - **`increment()` and `decrement()` on a model dispatch `updating` and `updated`.** An observer that should ignore them
39
145
  checks `wasChanged()` for the columns it cares about.
40
146
  - **Two-factor counts wrong codes in the cache.** On several servers, or on Vercel, the cache store must be shared:
@@ -46,6 +152,9 @@ dependencies are installed without a lockfile. Pinning its packages as above sto
46
152
  started beside it never finishes: await them in turn, or start them from separate transactions.
47
153
  - **Two-factor sign-in rehashes the password** when your hashing settings changed, as `Auth.attempt()` does, so with
48
154
  `auth.session` the user's other sessions end at their next sign-in after the change.
155
+ - **A password saved in the signed-in browser keeps that browser signed in**, a password reset included, whichever
156
+ instance of the user saves it (with `auth.session`). A test that resets the password in its signed-in session, to
157
+ stand for another browser, stays signed in now: reset in another session.
49
158
  - **A chain's `catch` jobs and a batch's `then`, `catch` and `finally` go to the chain's or batch's connection and
50
159
  queue**, not the default: run a worker there.
51
160
  - **`where(column, 'like', …)` on PostgreSQL compares the column as text**, as Laravel does, so it works on numbers and
@@ -570,9 +570,53 @@ export class StorePostRequest extends FormRequest {
570
570
  }
571
571
  ```
572
572
 
573
- Laravel's form requests also have `after()`, `stopOnFirstFailure`, `$redirect`, `prepareForValidation()` and
574
- `passedValidation()`, which Oriel's don't. Change the input before you validate with `request().merge()`, and check
575
- more with a [validator of your own](#performing-additional-validation).
573
+ #### Preparing input for validation
574
+
575
+ `prepareForValidation()` runs first, before `authorize()` and the rules, to change the input. What it merges is
576
+ validated with the rest:
577
+
578
+ ```ts title="app/Http/Requests/StorePostRequest.ts"
579
+ import { FormRequest, request, Str } from '@orieljs/framework'
580
+
581
+ export class StorePostRequest extends FormRequest {
582
+ rules() {
583
+ return { title: 'required|string', slug: 'required|alpha_dash' } as const
584
+ }
585
+
586
+ protected override prepareForValidation(): void {
587
+ request().merge({ slug: Str.slug(String(request().input('title') ?? '')) })
588
+ }
589
+ }
590
+ ```
591
+
592
+ #### Additional checks and stopping early
593
+
594
+ `after()` returns functions that run once the rules have, whether they passed or not, as the validator's
595
+ [`after()`](#performing-additional-validation) does: each receives the validator, whose `fail()` adds a message. With
596
+ `stopOnFirstFailure = true`, the request stops at the first field that fails:
597
+
598
+ ```ts title="app/Http/Requests/StorePostRequest.ts"
599
+ import { FormRequest, request } from '@orieljs/framework'
600
+ import type { Validator } from '@orieljs/framework/contracts'
601
+
602
+ export class StorePostRequest extends FormRequest {
603
+ protected override stopOnFirstFailure = true
604
+
605
+ rules() {
606
+ return { title: 'required|string', body: 'required|string' } as const
607
+ }
608
+
609
+ protected override after() {
610
+ return [
611
+ (validator: Validator) => {
612
+ if (String(request().input('title')).includes('spam')) validator.fail('title', 'Something is wrong with this title!')
613
+ },
614
+ ]
615
+ }
616
+ }
617
+ ```
618
+
619
+ Laravel's `$redirect` and `passedValidation()` aren't in Oriel's form requests.
576
620
 
577
621
  ## Manually creating validators
578
622
 
@@ -733,8 +777,23 @@ const validated = await request().validate({ name: 'required|string', email: 're
733
777
  const { name, email } = validated
734
778
  ```
735
779
 
736
- The data is a plain object. Laravel's `safe()`, with `only()`, `except()` and `merge()`, isn't in Oriel: pick the
737
- keys you want from the object.
780
+ The data is a plain object. `request().safe()` gives what the last `validate()` returned, the request's own or a form
781
+ request's, as a `ValidatedInput`, to pick from:
782
+
783
+ ```ts
784
+ await request().validate({ name: 'required|string', email: 'required|email', tags: 'array' })
785
+
786
+ const safe = request().safe()
787
+
788
+ safe.only('name', 'email')
789
+ safe.except('tags')
790
+ safe.merge({ role: 'member' }).all()
791
+ safe.collect('tags')
792
+ ```
793
+
794
+ `only()` and `except()` take dotted keys too, `has()` says whether every key given is there, and `input()` reads one
795
+ key, with a default. A validator's `safe()` gives the same, typed from its rules: `(await validator.safe()).only('name')`
796
+ is `{ name: string }`. Called before any `validate()`, `request().safe()` throws.
738
797
 
739
798
  ### The validated data's type
740
799
 
@@ -948,16 +1007,18 @@ word, such as `monday`, for a field's name. A number passes as a timestamp, as i
948
1007
 
949
1008
  #### alpha
950
1009
 
951
- Only the letters `A` to `Z` and `a` to `z`. Laravel's accepts letters of any script unless you write `alpha:ascii`;
952
- Oriel's accepts these letters only.
1010
+ Only letters, of any script, and the marks that go with them (Unicode's `\p{L}` and `\p{M}`): `José`, `Ελλάδα` and
1011
+ `中文` pass, a space or a digit doesn't. `alpha:ascii` accepts only the letters `A` to `Z` and `a` to `z`.
953
1012
 
954
1013
  #### alpha_dash
955
1014
 
956
- Only the letters `A` to `Z` and `a` to `z`, digits, `-` and `_`.
1015
+ Only letters and marks, numbers (Unicode's `\p{N}`), `-` and `_`. `alpha_dash:ascii` accepts only `A` to `Z`, `a` to
1016
+ `z`, `0` to `9`, `-` and `_`.
957
1017
 
958
1018
  #### alpha_num
959
1019
 
960
- Only the letters `A` to `Z` and `a` to `z`, and digits.
1020
+ Only letters and marks, and numbers of any script. `alpha_num:ascii` accepts only `A` to `Z`, `a` to `z` and `0` to
1021
+ `9`.
961
1022
 
962
1023
  #### array
963
1024
 
package/docs/views.md CHANGED
@@ -165,6 +165,7 @@ values.
165
165
  > [!WARNING]
166
166
  > Shared data belongs to the app, not to a request: every request's views see the same values. Share what doesn't
167
167
  > change from one user to the next, and give a view the current user's data with a [view composer](#view-composers).
168
+ > In the `local` environment, `View.share()` inside a request logs a warning that says so.
168
169
 
169
170
  ## View composers
170
171
 
package/docs/vite.md CHANGED
@@ -330,7 +330,8 @@ URLs inside your scripts and styles start with it:
330
330
  ASSET_URL=https://cdn.example.com
331
331
  ```
332
332
 
333
- The tags `vite()` writes, and `asset()`, use `app.asset_url`. A new app's `config/app.ts` doesn't have it, so add it:
333
+ The tags `vite()` writes, and `asset()`, use `app.asset_url`, which a new app's `config/app.ts` reads from `ASSET_URL`.
334
+ An app made before 0.1.0-alpha.16 adds the line:
334
335
 
335
336
  ```ts title="config/app.ts"
336
337
  import { env } from '@orieljs/framework'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orieljs/framework",
3
- "version": "0.1.0-alpha.15",
3
+ "version": "0.1.0-alpha.16",
4
4
  "description": "Oriel: a Laravel-style, full-stack TypeScript framework for Node.js and Bun.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -48,9 +48,7 @@
48
48
  "bcryptjs": "3.0.3",
49
49
  "cron-parser": "5.10.1",
50
50
  "dotenv": "18.0.3",
51
- "ioredis": "6.0.0",
52
51
  "kysely": "0.29.6",
53
- "nodemailer": "10.3.1",
54
52
  "pino": "10.3.1",
55
53
  "pluralize": "8.0.0",
56
54
  "uqr": "0.1.3"
@@ -60,37 +58,39 @@
60
58
  "@aws-sdk/client-s3": "3.1139.0",
61
59
  "@aws-sdk/s3-request-presigner": "3.1139.0",
62
60
  "@vercel/blob": "2.8.2",
63
- "@orieljs/collections": "0.1.0-alpha.15",
64
- "@orieljs/config": "0.1.0-alpha.15",
65
- "@orieljs/cache": "0.1.0-alpha.15",
66
- "@orieljs/auth": "0.1.0-alpha.15",
67
- "@orieljs/console": "0.1.0-alpha.15",
68
- "@orieljs/bus": "0.1.0-alpha.15",
69
- "@orieljs/contracts": "0.1.0-alpha.15",
70
- "@orieljs/cookie": "0.1.0-alpha.15",
71
- "@orieljs/container": "0.1.0-alpha.15",
72
- "@orieljs/encryption": "0.1.0-alpha.15",
73
- "@orieljs/database": "0.1.0-alpha.15",
74
- "@orieljs/events": "0.1.0-alpha.15",
75
- "@orieljs/filesystem": "0.1.0-alpha.15",
76
- "@orieljs/hashing": "0.1.0-alpha.15",
77
- "@orieljs/inertia": "0.1.0-alpha.15",
78
- "@orieljs/http": "0.1.0-alpha.15",
79
- "@orieljs/live": "0.1.0-alpha.15",
80
- "@orieljs/mail": "0.1.0-alpha.15",
81
- "@orieljs/notifications": "0.1.0-alpha.15",
82
- "@orieljs/log": "0.1.0-alpha.15",
83
- "@orieljs/obfuscate": "0.1.0-alpha.15",
84
- "@orieljs/pipeline": "0.1.0-alpha.15",
85
- "@orieljs/queue": "0.1.0-alpha.15",
86
- "@orieljs/support": "0.1.0-alpha.15",
87
- "@orieljs/foundation": "0.1.0-alpha.15",
88
- "@orieljs/session": "0.1.0-alpha.15",
89
- "@orieljs/routing": "0.1.0-alpha.15",
90
- "@orieljs/validation": "0.1.0-alpha.15",
91
- "@orieljs/testing": "0.1.0-alpha.15",
92
- "@orieljs/view": "0.1.0-alpha.15",
93
- "@orieljs/vercel": "0.1.0-alpha.15"
61
+ "ioredis": "6.0.0",
62
+ "nodemailer": "10.3.1",
63
+ "@orieljs/cache": "0.1.0-alpha.16",
64
+ "@orieljs/collections": "0.1.0-alpha.16",
65
+ "@orieljs/console": "0.1.0-alpha.16",
66
+ "@orieljs/config": "0.1.0-alpha.16",
67
+ "@orieljs/container": "0.1.0-alpha.16",
68
+ "@orieljs/contracts": "0.1.0-alpha.16",
69
+ "@orieljs/auth": "0.1.0-alpha.16",
70
+ "@orieljs/database": "0.1.0-alpha.16",
71
+ "@orieljs/cookie": "0.1.0-alpha.16",
72
+ "@orieljs/encryption": "0.1.0-alpha.16",
73
+ "@orieljs/events": "0.1.0-alpha.16",
74
+ "@orieljs/filesystem": "0.1.0-alpha.16",
75
+ "@orieljs/foundation": "0.1.0-alpha.16",
76
+ "@orieljs/bus": "0.1.0-alpha.16",
77
+ "@orieljs/inertia": "0.1.0-alpha.16",
78
+ "@orieljs/hashing": "0.1.0-alpha.16",
79
+ "@orieljs/http": "0.1.0-alpha.16",
80
+ "@orieljs/log": "0.1.0-alpha.16",
81
+ "@orieljs/mail": "0.1.0-alpha.16",
82
+ "@orieljs/notifications": "0.1.0-alpha.16",
83
+ "@orieljs/pipeline": "0.1.0-alpha.16",
84
+ "@orieljs/obfuscate": "0.1.0-alpha.16",
85
+ "@orieljs/queue": "0.1.0-alpha.16",
86
+ "@orieljs/session": "0.1.0-alpha.16",
87
+ "@orieljs/support": "0.1.0-alpha.16",
88
+ "@orieljs/testing": "0.1.0-alpha.16",
89
+ "@orieljs/validation": "0.1.0-alpha.16",
90
+ "@orieljs/view": "0.1.0-alpha.16",
91
+ "@orieljs/vercel": "0.1.0-alpha.16",
92
+ "@orieljs/live": "0.1.0-alpha.16",
93
+ "@orieljs/routing": "0.1.0-alpha.16"
94
94
  },
95
95
  "peerDependencies": {
96
96
  "pg": "^8.23.0",
@@ -98,7 +98,9 @@
98
98
  "better-sqlite3": "^13.0.3",
99
99
  "@aws-sdk/client-s3": "^3.1139.0",
100
100
  "@aws-sdk/s3-request-presigner": "^3.1139.0",
101
- "@vercel/blob": "^2.8.2"
101
+ "@vercel/blob": "^2.8.2",
102
+ "ioredis": "^6.0.0",
103
+ "nodemailer": "^10.3.1"
102
104
  },
103
105
  "peerDependenciesMeta": {
104
106
  "pg": {
@@ -118,6 +120,12 @@
118
120
  },
119
121
  "@vercel/blob": {
120
122
  "optional": true
123
+ },
124
+ "ioredis": {
125
+ "optional": true
126
+ },
127
+ "nodemailer": {
128
+ "optional": true
121
129
  }
122
130
  },
123
131
  "scripts": {