jcc-express-mvc 1.9.4 → 1.9.5
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.
- package/final-documentation/Digging Deeper/Helpers.md +8 -7
- package/final-documentation/Digging Deeper/Monitor.md +30 -7
- package/final-documentation/Getting-Started/Frontend.md +12 -3
- package/final-documentation/Getting-Started/Installation.md +11 -3
- package/final-documentation/JCC-Eloquent/Defining-Model.md +1 -1
- package/final-documentation/JCC-Eloquent/JCC-Eloquent-Introduction.md +1 -1
- package/final-documentation/JCC-Eloquent/Pagination.md +13 -10
- package/final-documentation/JCC-Eloquent/Query-Builder.md +2 -2
- package/final-documentation/Security/Authentication.md +39 -5
- package/final-documentation/The Basics/Artisan-Node.md +19 -2
- package/final-documentation/The Basics/Asset-bundling.md +5 -4
- package/lib/Auth/index.d.ts +2 -0
- package/lib/Auth/index.d.ts.map +1 -1
- package/lib/Auth/index.js +15 -16
- package/lib/Auth/type.d.ts +11 -0
- package/lib/Auth/type.d.ts.map +1 -0
- package/lib/Auth/type.js +2 -0
- package/lib/Error/public/419.html +1 -1
- package/lib/Global/helpers.d.ts.map +1 -1
- package/lib/Global/helpers.js +15 -5
- package/lib/Jcc-eloquent/lib/Builder.d.ts +3 -4
- package/lib/Jcc-eloquent/lib/Builder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Builder.js +29 -23
- package/lib/Jcc-eloquent/lib/Model.d.ts +3 -4
- package/lib/Jcc-eloquent/lib/Model.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Model.js +32 -31
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts +1 -2
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/QueryBuilder.js +2 -2
- package/lib/Middleware/index.d.ts.map +1 -1
- package/lib/Middleware/index.js +0 -1
- package/lib/util/index.d.ts +7 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +21 -1
- package/package.json +1 -1
- package/lib/Auth/Auth.d.ts +0 -8
- package/lib/Auth/Auth.d.ts.map +0 -1
- package/lib/Auth/Auth.js +0 -22
- package/lib/Inertia/old-index.d.ts +0 -7
- package/lib/Inertia/old-index.d.ts.map +0 -1
- package/lib/Inertia/old-index.js +0 -55
|
@@ -21,21 +21,22 @@ These helpers are available during request handling and in `tinker` (with contai
|
|
|
21
21
|
|
|
22
22
|
## HTTP context helpers
|
|
23
23
|
|
|
24
|
-
- `request()` -> current `AppRequest`
|
|
25
|
-
- `response()` -> current `AppResponse`
|
|
26
|
-
- `next()` -> current `next` function
|
|
24
|
+
- `request()` -> current `AppRequest` (returns `{}` outside an HTTP request)
|
|
25
|
+
- `response()` -> current `AppResponse` (returns `{}` outside an HTTP request)
|
|
27
26
|
- `view(view, options?, callback?)`
|
|
28
27
|
- `inertia(component, props?, option?)`
|
|
29
28
|
- `redirect(url, status?)`
|
|
30
29
|
- `back(url?)`
|
|
31
30
|
|
|
32
|
-
These depend on per-request container bindings, so they are request-lifecycle helpers.
|
|
31
|
+
These depend on per-request container bindings, so they are request-lifecycle helpers. `request()` and `response()` are safe to call from code that may run outside middleware (for example pagination link builders) — they return an empty object when no request is bound.
|
|
32
|
+
|
|
33
|
+
`next()` is **not** exposed as a global helper. Use the `next` argument in middleware and route handlers directly.
|
|
33
34
|
|
|
34
35
|
---
|
|
35
36
|
|
|
36
37
|
## Auth and authorization helpers
|
|
37
38
|
|
|
38
|
-
- `auth()` ->
|
|
39
|
+
- `auth()` -> `Authentication` class (`Auth.attempt`, `Auth.apiAttempt`, `Auth.logout`, etc.)
|
|
39
40
|
- `Gate` -> `GateFacade`
|
|
40
41
|
- `can(user, ability, model?, ...args)`
|
|
41
42
|
- `authorize(user, ability, ...args)`
|
|
@@ -98,8 +99,8 @@ Global helper types are declared in `jcc-express-mvc/global.d.ts`, so TypeScript
|
|
|
98
99
|
|
|
99
100
|
## Notes
|
|
100
101
|
|
|
101
|
-
- `
|
|
102
|
-
-
|
|
102
|
+
- Helpers that rely on request bindings (`request`, `response`, `validate`, `session`, etc.) are not meaningful before HTTP middleware bootstraps those bindings.
|
|
103
|
+
- `request()` and `response()` catch missing bindings and return `{}` instead of throwing.
|
|
103
104
|
|
|
104
105
|
---
|
|
105
106
|
|
|
@@ -157,8 +157,14 @@ export const monitor: Partial<MonitorConfig> = {
|
|
|
157
157
|
},
|
|
158
158
|
system: { enabled: true, intervalMs: 15_000 },
|
|
159
159
|
errors: { enabled: true },
|
|
160
|
-
database: { enabled:
|
|
161
|
-
queue: { enabled:
|
|
160
|
+
database: { enabled: true, slowQueryMs: 200 },
|
|
161
|
+
queue: { enabled: true },
|
|
162
|
+
commands: { enabled: true },
|
|
163
|
+
schedule: { enabled: true },
|
|
164
|
+
mail: { enabled: true },
|
|
165
|
+
cache: { enabled: true },
|
|
166
|
+
outgoing: { enabled: true },
|
|
167
|
+
logs: { enabled: true },
|
|
162
168
|
},
|
|
163
169
|
|
|
164
170
|
exporters: {
|
|
@@ -187,6 +193,22 @@ export const monitor: Partial<MonitorConfig> = {
|
|
|
187
193
|
recentErrors: 100,
|
|
188
194
|
recentJobs: 100,
|
|
189
195
|
recentQueries: 100,
|
|
196
|
+
recentCommands: 100,
|
|
197
|
+
recentScheduledTasks: 100,
|
|
198
|
+
recentNotifications: 100,
|
|
199
|
+
recentMail: 100,
|
|
200
|
+
recentCacheOps: 100,
|
|
201
|
+
recentOutgoingRequests: 100,
|
|
202
|
+
recentLogs: 100,
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
storage: {
|
|
206
|
+
driver: config.get("MONITOR_STORAGE", "memory") as
|
|
207
|
+
| "memory"
|
|
208
|
+
| "file"
|
|
209
|
+
| "redis"
|
|
210
|
+
| "database",
|
|
211
|
+
file: { path: config.get("MONITOR_STORAGE_PATH", "storage/monitor") },
|
|
190
212
|
},
|
|
191
213
|
|
|
192
214
|
alerts: {
|
|
@@ -258,13 +280,14 @@ The `/_monitor` path is excluded from request metric collection so the dashboard
|
|
|
258
280
|
| --------------- | ------------------------------------------------------------------- |
|
|
259
281
|
| Requests | Auto — `MonitorMiddleware` records every request |
|
|
260
282
|
| Exceptions | Auto — `ErrorCollector` + `MonitorErrorMiddleware` |
|
|
261
|
-
| Queries |
|
|
262
|
-
| Jobs |
|
|
283
|
+
| Queries | Auto when `collectors.database.enabled` — ORM query hooks |
|
|
284
|
+
| Jobs | Auto when `collectors.queue.enabled` — `Queue` records job events |
|
|
285
|
+
| Commands | Auto when `collectors.commands.enabled` — console kernel records runs |
|
|
286
|
+
| Scheduled Tasks | Auto when `collectors.schedule.enabled` — scheduler records runs |
|
|
263
287
|
| Mail | Auto when `collectors.mail.enabled` — wraps the `Mail` facade |
|
|
264
288
|
| Cache | Auto when `collectors.cache.enabled` — wraps `Cache.get/put/forget` |
|
|
265
|
-
| Outgoing | Auto when `collectors.outgoing.enabled` —
|
|
266
|
-
|
|
|
267
|
-
| Scheduled Tasks | Manual — `Monitor.recordScheduledTask({ ... })` from the runner |
|
|
289
|
+
| Outgoing | Auto when `collectors.outgoing.enabled` — axios + `fetch` patch |
|
|
290
|
+
| Logs | Auto when `collectors.logs.enabled` — framework logger integration |
|
|
268
291
|
| Notifications | Manual — `Monitor.recordNotification({ ... })` after dispatch |
|
|
269
292
|
|
|
270
293
|
---
|
|
@@ -156,11 +156,20 @@ Vite is the default bundler: fast builds and Hot Module Replacement (HMR) during
|
|
|
156
156
|
|
|
157
157
|
For Blade tags, `public/hot`, manifest resolution, and troubleshooting, see [Asset-bundling.md](../The Basics/Asset-bundling.md).
|
|
158
158
|
|
|
159
|
-
Local workflow —
|
|
159
|
+
Local workflow — use two terminals:
|
|
160
160
|
|
|
161
161
|
```bash
|
|
162
|
-
|
|
163
|
-
bun
|
|
162
|
+
# Terminal 1 — backend (recommended: Laravel-style watcher)
|
|
163
|
+
bun artisanNode serve
|
|
164
|
+
|
|
165
|
+
# Terminal 2 — Vite assets (writes public/hot)
|
|
166
|
+
bun run watch # or: npm run watch
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Alternative backend command:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
bun run dev # or: npm run dev → bun --watch server.ts (simpler, no serve watcher)
|
|
164
173
|
```
|
|
165
174
|
|
|
166
175
|
Production-style build:
|
|
@@ -224,6 +224,14 @@ This starts Vite in watch mode (React/Vue, Tailwind, hot reload, etc.). Let it k
|
|
|
224
224
|
|
|
225
225
|
In a second terminal, from the same project root:
|
|
226
226
|
|
|
227
|
+
```bash
|
|
228
|
+
bun artisanNode serve
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
This is the recommended dev server: it watches backend files, reloads silently, keeps the same port, and reacts to `public/hot` when Vite starts.
|
|
232
|
+
|
|
233
|
+
Alternative (simpler, without the Laravel-style watcher):
|
|
234
|
+
|
|
227
235
|
```bash
|
|
228
236
|
bun run dev
|
|
229
237
|
```
|
|
@@ -234,7 +242,7 @@ or:
|
|
|
234
242
|
npm run dev
|
|
235
243
|
```
|
|
236
244
|
|
|
237
|
-
This
|
|
245
|
+
This runs `bun --watch server.ts`, which boots Express and your bootstrap pipeline with Bun's built-in file watcher.
|
|
238
246
|
|
|
239
247
|
### 7.3 Open the app
|
|
240
248
|
|
|
@@ -267,7 +275,7 @@ Use `bun artisanNode list` or `bun artisanNode help [command]` to see commands (
|
|
|
267
275
|
- [ ] `.env` exists and is filled in for your machine (starter projects already have the file; cloned repos may need `cp .env.example .env`)
|
|
268
276
|
- [ ] `bun artisanNode key:generate` has set `JWT_SECRET` (required for JWT auth)
|
|
269
277
|
- [ ] `bun artisanNode migrate` completed (or you intentionally skip DB for now)
|
|
270
|
-
- [ ] `watch` then `dev` both run without crashing (`bun run` / `npm run` as you prefer)
|
|
278
|
+
- [ ] `watch` then `serve` (or `dev`) both run without crashing (`bun run` / `npm run` as you prefer)
|
|
271
279
|
- [ ] Browser loads `http://localhost:<PORT>`
|
|
272
280
|
|
|
273
281
|
---
|
|
@@ -287,7 +295,7 @@ Use `bun artisanNode list` or `bun artisanNode help [command]` to see commands (
|
|
|
287
295
|
|
|
288
296
|
- [Configuration.md](./Configuration.md) — `.env`, `app/Config`, and how values are loaded at runtime
|
|
289
297
|
- [Directory-structure.md](./Directory-structure.md) — Project folders and what each is for
|
|
290
|
-
- [Frontend.md](./Frontend.md) — Why `watch` runs
|
|
298
|
+
- [Frontend.md](./Frontend.md) — Why `watch` runs alongside `serve` (Vite + Inertia)
|
|
291
299
|
- [Deployment.md](./Deployment.md) — Production `.env`, builds, migrations, and process management
|
|
292
300
|
- `docs/docs-for-dev.md` — broad framework guide (routing, Eloquent, validation, queues, etc.)
|
|
293
301
|
- `docs/getting-started.md` — shorter orientation
|
|
@@ -279,7 +279,7 @@ Route.middleware(["apiAuth"]).get("/me", async (req) => {
|
|
|
279
279
|
If `hasToken` is not enabled on the model:
|
|
280
280
|
|
|
281
281
|
```text
|
|
282
|
-
ModelTokenError: User Missing required token. Please set 'protected hasToken = true' .
|
|
282
|
+
ModelTokenError: User Model Missing required token. Please set 'protected hasToken = true' .
|
|
283
283
|
```
|
|
284
284
|
|
|
285
285
|
The global error handler returns `500` with the error message for `ModelTokenError`.
|
|
@@ -111,7 +111,7 @@ export class User extends Model {
|
|
|
111
111
|
Model-level pagination helper exists:
|
|
112
112
|
|
|
113
113
|
```typescript
|
|
114
|
-
const page = await User.paginate(
|
|
114
|
+
const page = await User.paginate(15);
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
This returns `data` plus pagination metadata/links.
|
|
@@ -4,16 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
JCC-Eloquent provides pagination at both model and builder level.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Pagination reads the current HTTP request via the global `request()` helper — you do **not** pass `req` as the first argument. Page number comes from `request().query.page` (default `1`). Link URLs use `request().protocol`, host, and path.
|
|
8
|
+
|
|
9
|
+
Both methods return `data` + pagination metadata.
|
|
8
10
|
|
|
9
11
|
---
|
|
10
12
|
|
|
11
13
|
## Model pagination
|
|
12
14
|
|
|
13
|
-
`Model.paginate(
|
|
15
|
+
`Model.paginate(perPage?, page?)`:
|
|
14
16
|
|
|
15
17
|
```typescript
|
|
16
|
-
const paginatedUsers = await User.paginate(
|
|
18
|
+
const paginatedUsers = await User.paginate(15);
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
This returns:
|
|
@@ -31,7 +33,7 @@ Builder pagination works on filtered queries:
|
|
|
31
33
|
```typescript
|
|
32
34
|
const page = await User.where("active", true)
|
|
33
35
|
.orderBy("created_at", "desc")
|
|
34
|
-
.paginate(
|
|
36
|
+
.paginate(20);
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
Use this when pagination must respect custom constraints.
|
|
@@ -43,7 +45,7 @@ Use this when pagination must respect custom constraints.
|
|
|
43
45
|
`simplePaginate` uses offset pagination without running a `COUNT(*)` query — faster for large tables when you don't need a total count:
|
|
44
46
|
|
|
45
47
|
```typescript
|
|
46
|
-
const page = await User.where("active", true).simplePaginate(
|
|
48
|
+
const page = await User.where("active", true).simplePaginate(15);
|
|
47
49
|
```
|
|
48
50
|
|
|
49
51
|
Response shape:
|
|
@@ -70,7 +72,7 @@ No `total` or `total_pages` — just whether there is a next page.
|
|
|
70
72
|
`cursorPaginate` implements keyset (cursor-based) pagination — stable and O(1) for any page depth, regardless of table size:
|
|
71
73
|
|
|
72
74
|
```typescript
|
|
73
|
-
const page = await User.orderBy("id").cursorPaginate(
|
|
75
|
+
const page = await User.orderBy("id").cursorPaginate(20);
|
|
74
76
|
```
|
|
75
77
|
|
|
76
78
|
Response shape:
|
|
@@ -112,7 +114,7 @@ Pass the next page by forwarding `?cursor=<token>` from `meta.next_cursor`.
|
|
|
112
114
|
For full manual control:
|
|
113
115
|
|
|
114
116
|
```typescript
|
|
115
|
-
const currentPage = Number(
|
|
117
|
+
const currentPage = Number(request().query?.page || 1);
|
|
116
118
|
const perPage = 20;
|
|
117
119
|
const offset = (currentPage - 1) * perPage;
|
|
118
120
|
|
|
@@ -131,7 +133,8 @@ const rows = await User.orderBy("id", "desc").offset(offset).limit(perPage).get(
|
|
|
131
133
|
|
|
132
134
|
## Summary
|
|
133
135
|
|
|
134
|
-
- Use `paginate(
|
|
135
|
-
- Use `simplePaginate(
|
|
136
|
-
- Use `cursorPaginate(
|
|
136
|
+
- Use `paginate(perPage)` for standard pagination with total counts and page links.
|
|
137
|
+
- Use `simplePaginate(perPage)` for large tables where you don't need a total count.
|
|
138
|
+
- Use `cursorPaginate(perPage)` for high-performance, stable pagination on large or frequently-updated tables.
|
|
139
|
+
- Pagination uses the global `request()` helper for page number and link generation — call it inside a route handler or middleware context.
|
|
137
140
|
- Use `offset` + `limit` only for fully custom paging flows.
|
|
@@ -258,7 +258,7 @@ await User.where("id", 1).updateJson("preferences.notifications.email", false);
|
|
|
258
258
|
For large datasets where `COUNT(*)` is too slow, use cursor-based (keyset) pagination:
|
|
259
259
|
|
|
260
260
|
```typescript
|
|
261
|
-
const page = await User.orderBy("id").cursorPaginate(
|
|
261
|
+
const page = await User.orderBy("id").cursorPaginate(20);
|
|
262
262
|
```
|
|
263
263
|
|
|
264
264
|
Response shape:
|
|
@@ -291,7 +291,7 @@ Pass the next page by forwarding `?cursor=<token>` from `meta.next_cursor`.
|
|
|
291
291
|
Offset pagination without a `COUNT(*)` query — faster for large tables:
|
|
292
292
|
|
|
293
293
|
```typescript
|
|
294
|
-
const page = await User.where("active", true).simplePaginate(
|
|
294
|
+
const page = await User.where("active", true).simplePaginate(15);
|
|
295
295
|
```
|
|
296
296
|
|
|
297
297
|
Response:
|
|
@@ -101,9 +101,43 @@ Route.middleware(["loginThrottle"]).post("/auth/login", async (req, res, next) =
|
|
|
101
101
|
Route.middleware(["auth"]).get("/home", homeHandler);
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
### API token login (
|
|
104
|
+
### API token login (`apiAttempt`)
|
|
105
105
|
|
|
106
|
-
For stateless API clients,
|
|
106
|
+
For stateless API clients, use `auth().apiAttempt()` to validate credentials and issue a bearer token in one step:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
Route.post("/api/login", async () => {
|
|
110
|
+
const result = await auth().apiAttempt({ field: "email", table: "User" });
|
|
111
|
+
|
|
112
|
+
if (!result.success) {
|
|
113
|
+
return response().status(401).json({ message: result.message });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
token: result.token,
|
|
118
|
+
user: result.user,
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
Route.middleware(["apiAuth"]).get("/api/me", async (req) => {
|
|
123
|
+
return { user: req.user };
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`apiAttempt` options:
|
|
128
|
+
|
|
129
|
+
| Field | Default | Description |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| `field` | `"email"` | Request input key to match (`email`, `phone`, `username`, etc.) |
|
|
132
|
+
| `table` | `"User"` | Model name resolved via `getModel()` |
|
|
133
|
+
|
|
134
|
+
The request body must include the credential field and `password`. On success, returns `{ success: true, token, user, message }`. On failure, returns `{ success: false, token: null, user: null, message: "Invalid credentials" }`.
|
|
135
|
+
|
|
136
|
+
The model must have `protected hasToken = true`. User lookup and password verification are shared with session login via `findUserForAuth()`.
|
|
137
|
+
|
|
138
|
+
### Manual token login (`createToken`)
|
|
139
|
+
|
|
140
|
+
You can also issue a token manually after your own credential check:
|
|
107
141
|
|
|
108
142
|
```typescript
|
|
109
143
|
import { User } from "@/Model/User";
|
|
@@ -120,13 +154,13 @@ Route.middleware(["apiAuth"]).get("/api/me", async (req) => {
|
|
|
120
154
|
});
|
|
121
155
|
```
|
|
122
156
|
|
|
123
|
-
|
|
157
|
+
Full `createToken` details: [Defining-Model.md](../JCC-Eloquent/Defining-Model.md#api-tokens-createtoken).
|
|
124
158
|
|
|
125
159
|
---
|
|
126
160
|
|
|
127
161
|
## Summary
|
|
128
162
|
|
|
129
163
|
- Authentication uses JWT cookies with rotating refresh tokens.
|
|
130
|
-
- Use `Auth.attempt(next)` for login, `auth`/`apiAuth` middleware for protection.
|
|
131
|
-
- For API
|
|
164
|
+
- Use `Auth.attempt(next)` for cookie login, `auth().apiAttempt()` for API email/password + bearer token, and `auth`/`apiAuth` middleware for protection.
|
|
165
|
+
- For manual API tokens, enable `hasToken` on the model and call `createToken()` — `apiAuth` reloads the user from JWT claims.
|
|
132
166
|
- `Auth.logout()` clears auth state and redirects to login.
|
|
@@ -60,12 +60,29 @@ bun artisanNode db:wipe
|
|
|
60
60
|
## Dev server
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
bun artisanNode serve #
|
|
63
|
+
bun artisanNode serve # Laravel-style dev server with file watcher (entry: server.ts)
|
|
64
64
|
bun artisanNode serve app.ts # use a different entry file
|
|
65
65
|
bun artisanNode watch # alias of `serve`
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
`serve` (alias `watch`)
|
|
68
|
+
`serve` (alias `watch`) is the recommended backend dev command. It:
|
|
69
|
+
|
|
70
|
+
- watches backend paths (`app/`, `route/`, `jcc-express-mvc/`, `resources/views/`, etc.)
|
|
71
|
+
- reloads **silently** on code changes (no terminal clear, no restart banner)
|
|
72
|
+
- keeps the same `PORT` from `.env` across restarts
|
|
73
|
+
- watches `public/hot` so the backend picks up Vite when the dev asset server starts
|
|
74
|
+
|
|
75
|
+
Run Vite separately for frontend assets:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Terminal 1 — backend (file watcher + Express)
|
|
79
|
+
bun artisanNode serve
|
|
80
|
+
|
|
81
|
+
# Terminal 2 — frontend (Vite HMR, writes public/hot)
|
|
82
|
+
npm run watch
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`npm run dev` (`bun --watch server.ts`) is a simpler alternative without the Laravel-style watcher. Prefer `bun artisanNode serve` when you want silent reloads, stable ports, and `public/hot` integration.
|
|
69
86
|
|
|
70
87
|
---
|
|
71
88
|
|
|
@@ -15,11 +15,12 @@ For Inertia, SSR, and the HTTP kernel’s `inertia()` middleware, see `Getting-S
|
|
|
15
15
|
Typical `package.json` scripts:
|
|
16
16
|
|
|
17
17
|
- `watch` — Runs `vite` (dev server, HMR, writes `public/hot`).
|
|
18
|
-
- `dev` — Runs
|
|
18
|
+
- `dev` — Runs `bun --watch server.ts` (simple backend reload; no Laravel-style watcher).
|
|
19
|
+
- `serve` — Run via `bun artisanNode serve` (recommended backend dev server; see `Artisan-Node.md`).
|
|
19
20
|
- `vite-build` — `vite build` plus `vite build --ssr` when you ship SSR (adjust to your app).
|
|
20
21
|
- `build` — TypeScript compile (`tsc`) for the server codebase; not a substitute for `vite-build`.
|
|
21
22
|
|
|
22
|
-
Start Vite before hitting pages that use `@vite`, or
|
|
23
|
+
Start Vite before hitting pages that use `@vite`, or refresh after `public/hot` appears. The template layer reads `public/hot` on each request in development.
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
@@ -41,13 +42,13 @@ Add or change `input` when you create new entrypoints. Tailwind and React (or Vu
|
|
|
41
42
|
|
|
42
43
|
## `public/hot` and the dev server
|
|
43
44
|
|
|
44
|
-
In non-production, `EngineHelpers` reads `public/hot` (first line is the Vite origin, e.g. `http://127.0.0.1:5173`). That value becomes `viteHost` for:
|
|
45
|
+
In non-production, `EngineHelpers` reads `public/hot` on **each render** (first line is the Vite origin, e.g. `http://127.0.0.1:5173`). That value becomes `viteHost` for:
|
|
45
46
|
|
|
46
47
|
- Module `<script>` tags pointing at your entries.
|
|
47
48
|
- Optional link to the CSS entry when you pass more than one resource in `@vite` (first entry is treated as CSS in dev in that case).
|
|
48
49
|
- Injection of `/@vite/client` for HMR.
|
|
49
50
|
|
|
50
|
-
If `hot` is missing, tags may point at an empty base—run `npm run watch` / `bun run watch`.
|
|
51
|
+
If `hot` is missing, tags may point at an empty base — run `npm run watch` / `bun run watch`. After Vite creates `public/hot`, refresh the page (or use `bun artisanNode serve`, which watches `public/hot` and reloads the backend when Vite starts).
|
|
51
52
|
|
|
52
53
|
---
|
|
53
54
|
|
package/lib/Auth/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AppRequest, AppResponse, AppNext } from "../Interface";
|
|
2
2
|
import { type IRefreshTokenStore } from "./refreshTokenStore";
|
|
3
|
+
import { ApiAuthResponse, ApiAuthType } from "./type";
|
|
3
4
|
export declare class Authentication {
|
|
4
5
|
private static refreshStore;
|
|
5
6
|
/** Use a shared store (e.g. Redis) when running multiple app instances. */
|
|
@@ -12,6 +13,7 @@ export declare class Authentication {
|
|
|
12
13
|
private static setTokens;
|
|
13
14
|
/** Handle user login attempt */
|
|
14
15
|
static attempt(next: AppNext, redirect?: string): Promise<void>;
|
|
16
|
+
static apiAttempt(data: ApiAuthType): Promise<ApiAuthResponse>;
|
|
15
17
|
/**
|
|
16
18
|
* After the user is resolved (e.g. OAuth via Socialite), issue JWT cookies
|
|
17
19
|
* and redirect or JSON response like {@link Authentication.attempt}.
|
package/lib/Auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAkBhE,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAsBtD,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,YAAY,CAAgD;IAE3E,2EAA2E;IAC3E,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI;IAI5D,qDAAqD;IACrD,OAAO,CAAC,MAAM,CAAC,cAAc;IAc7B,0DAA0D;mBACrC,OAAO;IAS5B,wFAAwF;IACxF,OAAO,CAAC,MAAM,CAAC,SAAS;IA0BxB,gCAAgC;WACnB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,GAAE,MAAgB;WA2BjD,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IAwBpE;;;OAGG;WACU,aAAa,CACxB,GAAG,EAAE,UAAU,EACf,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,QAAQ,GAAE,MAAgB,GACzB,OAAO,CAAC,IAAI,CAAC;IA4BhB,+BAA+B;WAClB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO;IAsC1E,qBAAqB;IACrB,MAAM,CAAC,MAAM;IAsBb,4FAA4F;IAC5F,MAAM,CAAC,KAAK,IAAI,OAAO;IAWvB,MAAM,CAAC,IAAI;IAIX,MAAM,CAAC,EAAE;WAII,WAAW,CACtB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,QAAQ,GAAE,MAAgB;CAI7B"}
|
package/lib/Auth/index.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Authentication = void 0;
|
|
4
4
|
const util_1 = require("../util");
|
|
5
|
-
const Config_1 = require("../Config/Config");
|
|
6
5
|
const ValidationException_v2_1 = require("../Error/ValidationException-v2");
|
|
7
|
-
const Jcc_eloquent_1 = require("../Jcc-eloquent");
|
|
8
6
|
const refreshTokenStore_1 = require("./refreshTokenStore");
|
|
9
7
|
const REFRESH_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
10
8
|
const ACCESS_MAX_AGE_MS = 60 * 60 * 1000;
|
|
@@ -47,20 +45,7 @@ class Authentication {
|
|
|
47
45
|
const field = this.getCredentials(data);
|
|
48
46
|
if (!Object.keys(field).length)
|
|
49
47
|
return { user: null, field: "email" };
|
|
50
|
-
let user =
|
|
51
|
-
const orm = Config_1.config.get("DB_ORM");
|
|
52
|
-
if (orm === "mongodb" || orm === "mongoose") {
|
|
53
|
-
user = await User.findOne(field).select("+password");
|
|
54
|
-
}
|
|
55
|
-
else if (orm === "sequelize") {
|
|
56
|
-
user = await User.findOne({ where: field });
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// JCC ORM
|
|
60
|
-
user = await Jcc_eloquent_1.DB.table("users")
|
|
61
|
-
.where(Object.keys(field)[0], Object.values(field)[0])
|
|
62
|
-
.first();
|
|
63
|
-
}
|
|
48
|
+
let user = await (0, util_1.findUserForAuth)(User, field);
|
|
64
49
|
return { user, field: Object.keys(field)[0] || "email" };
|
|
65
50
|
}
|
|
66
51
|
/** Generate and attach tokens to cookies (refresh is rotated server-side via `jti`). */
|
|
@@ -100,6 +85,20 @@ class Authentication {
|
|
|
100
85
|
next(error);
|
|
101
86
|
}
|
|
102
87
|
}
|
|
88
|
+
static async apiAttempt(data) {
|
|
89
|
+
data = data || { field: "email", table: "User" };
|
|
90
|
+
const input = request().input(data.field || "");
|
|
91
|
+
const password = request().input("password");
|
|
92
|
+
const { [data.table]: Model } = (0, util_1.getModel)(data.table);
|
|
93
|
+
let user = await (0, util_1.findUserForAuth)(Model, { [data.field]: input });
|
|
94
|
+
if (!user) {
|
|
95
|
+
return (0, util_1.authResponseMessages)(false, "Invalid credentials", null, null);
|
|
96
|
+
}
|
|
97
|
+
if (!(await (0, util_1.verifyHash)(password, user?.password || ""))) {
|
|
98
|
+
return (0, util_1.authResponseMessages)(false, "Invalid credentials", null, null);
|
|
99
|
+
}
|
|
100
|
+
return (0, util_1.authResponseMessages)(true, "Login successful", user?.toJSON(), user.createToken({}));
|
|
101
|
+
}
|
|
103
102
|
/**
|
|
104
103
|
* After the user is resolved (e.g. OAuth via Socialite), issue JWT cookies
|
|
105
104
|
* and redirect or JSON response like {@link Authentication.attempt}.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Auth/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
package/lib/Auth/type.js
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Global/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAqBzD,eAAO,MAAM,aAAa,GAAI,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Global/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAqBzD,eAAO,MAAM,aAAa,GAAI,KAAK,WAAW,SAmI7C,CAAC"}
|
package/lib/Global/helpers.js
CHANGED
|
@@ -50,14 +50,24 @@ const globalHelpers = (app) => {
|
|
|
50
50
|
};
|
|
51
51
|
globalThis.Gate = Authorization_1.GateFacade;
|
|
52
52
|
globalThis.request = () => {
|
|
53
|
-
|
|
53
|
+
try {
|
|
54
|
+
return app.resolve("request");
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
54
59
|
};
|
|
55
60
|
globalThis.response = () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
try {
|
|
62
|
+
return app.resolve("response");
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
60
67
|
};
|
|
68
|
+
// (globalThis as any).next = () => {
|
|
69
|
+
// return app.resolve<AppNext>("next");
|
|
70
|
+
// };
|
|
61
71
|
globalThis.auth = () => {
|
|
62
72
|
return index_1.Authentication;
|
|
63
73
|
};
|
|
@@ -2,7 +2,6 @@ import { Knex } from "knex";
|
|
|
2
2
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
import { AggregateInput, JoinCallback, SubJoinCallback, WhereInput } from "./Types";
|
|
4
4
|
import { type CursorPagination, type SimplePagination } from "./Interfaces";
|
|
5
|
-
import type { Request } from "express";
|
|
6
5
|
import type { Model } from "./Model";
|
|
7
6
|
import { QueryBuilder } from "./QueryBuilder";
|
|
8
7
|
export declare class Builder {
|
|
@@ -195,13 +194,13 @@ export declare class Builder {
|
|
|
195
194
|
/**
|
|
196
195
|
* Paginate without counting total rows (fetch `perPage + 1` to detect `has_more`).
|
|
197
196
|
*/
|
|
198
|
-
simplePaginate(
|
|
197
|
+
simplePaginate(perPage?: number | string, page?: number): Promise<SimplePagination>;
|
|
199
198
|
/**
|
|
200
199
|
* Cursor-based pagination (keyset) on `column` — no `COUNT`, stable for large offsets.
|
|
201
200
|
* Pass the next page via `?cursor=` (from `meta.next_cursor`). Uses `perPage + 1` to detect `has_more`.
|
|
202
201
|
*/
|
|
203
|
-
cursorPaginate(
|
|
204
|
-
paginate(
|
|
202
|
+
cursorPaginate(perPage?: number | string, column?: string, direction?: "asc" | "desc"): Promise<CursorPagination>;
|
|
203
|
+
paginate(perPage?: number | string, page?: number): Promise<any>;
|
|
205
204
|
plunk(column: string): this;
|
|
206
205
|
/**
|
|
207
206
|
* Get an array of values for a single column (alias like Laravel pluck).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Builder.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/Builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EACL,cAAc,EACd,YAAY,EAGZ,eAAe,EACf,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Builder.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/Builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EACL,cAAc,EACd,YAAY,EAGZ,eAAe,EACf,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,EAAE,CAAO;IACjB,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,KAAK,CAA6B;IACnC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAM;IAChD,UAAU,EAAE,OAAO,CAAQ;IAC3B,aAAa,EAAE,OAAO,CAAS;IAGtC,OAAc,SAAS,yDAAoD;;IAM3E,MAAM,CAAC,oBAAoB,IAAI,IAAI,CAAC,WAAW,GAAG,IAAI;IA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W;IAMzB,OAAO,CAAC,KAAK;IAQb;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAIvD"}
|
|
@@ -761,37 +761,38 @@ class Builder {
|
|
|
761
761
|
/**
|
|
762
762
|
* Paginate without counting total rows (fetch `perPage + 1` to detect `has_more`).
|
|
763
763
|
*/
|
|
764
|
-
async simplePaginate(
|
|
765
|
-
const
|
|
764
|
+
async simplePaginate(perPage = 15, page = 1) {
|
|
765
|
+
const req = request();
|
|
766
|
+
const pageNum = Math.max(1, Number(page || 1));
|
|
766
767
|
const perPageNum = Number(perPage);
|
|
767
|
-
const offset = (
|
|
768
|
+
const offset = (pageNum - 1) * perPageNum;
|
|
768
769
|
const rows = await this.clone()
|
|
769
770
|
.offset(offset)
|
|
770
771
|
.limit(perPageNum + 1)
|
|
771
772
|
.get();
|
|
772
773
|
const hasMore = rows.length > perPageNum;
|
|
773
774
|
const data = hasMore ? rows.slice(0, perPageNum) : rows;
|
|
774
|
-
const nextPage = hasMore ?
|
|
775
|
-
const prevPage =
|
|
775
|
+
const nextPage = hasMore ? pageNum + 1 : null;
|
|
776
|
+
const prevPage = pageNum > 1 ? pageNum - 1 : null;
|
|
776
777
|
return {
|
|
777
778
|
data,
|
|
778
779
|
meta: {
|
|
779
|
-
current_page:
|
|
780
|
+
current_page: pageNum,
|
|
780
781
|
per_page: perPage,
|
|
781
782
|
has_more: hasMore,
|
|
782
783
|
next_page: nextPage,
|
|
783
784
|
prev_page: prevPage,
|
|
784
785
|
},
|
|
785
786
|
links: {
|
|
786
|
-
first: utils_1.Utils.mergeRequestQuery(
|
|
787
|
+
first: utils_1.Utils.mergeRequestQuery(req, { page: 1, cursor: null }),
|
|
787
788
|
next: nextPage
|
|
788
|
-
? utils_1.Utils.mergeRequestQuery(
|
|
789
|
+
? utils_1.Utils.mergeRequestQuery(req, {
|
|
789
790
|
page: nextPage,
|
|
790
791
|
cursor: null,
|
|
791
792
|
})
|
|
792
793
|
: null,
|
|
793
794
|
prev: prevPage
|
|
794
|
-
? utils_1.Utils.mergeRequestQuery(
|
|
795
|
+
? utils_1.Utils.mergeRequestQuery(req, {
|
|
795
796
|
page: prevPage,
|
|
796
797
|
cursor: null,
|
|
797
798
|
})
|
|
@@ -803,10 +804,11 @@ class Builder {
|
|
|
803
804
|
* Cursor-based pagination (keyset) on `column` — no `COUNT`, stable for large offsets.
|
|
804
805
|
* Pass the next page via `?cursor=` (from `meta.next_cursor`). Uses `perPage + 1` to detect `has_more`.
|
|
805
806
|
*/
|
|
806
|
-
async cursorPaginate(
|
|
807
|
+
async cursorPaginate(perPage = 15, column, direction = "asc") {
|
|
808
|
+
const req = request();
|
|
807
809
|
const per = Number(perPage);
|
|
808
810
|
const col = column ?? (this.model ? new this.model().primaryKey : "id");
|
|
809
|
-
const raw =
|
|
811
|
+
const raw = req?.query?.cursor;
|
|
810
812
|
const cursorParam = raw === undefined || raw === null
|
|
811
813
|
? ""
|
|
812
814
|
: Array.isArray(raw)
|
|
@@ -825,7 +827,7 @@ class Builder {
|
|
|
825
827
|
const rows = await q.limit(per + 1).get();
|
|
826
828
|
const hasMore = rows.length > per;
|
|
827
829
|
const data = hasMore ? rows.slice(0, per) : rows;
|
|
828
|
-
const path = `${
|
|
830
|
+
const path = `${req.protocol}://${req.get("host")}${req.path}`;
|
|
829
831
|
let nextCursor = null;
|
|
830
832
|
if (hasMore && data.length > 0) {
|
|
831
833
|
const last = data[data.length - 1];
|
|
@@ -847,37 +849,41 @@ class Builder {
|
|
|
847
849
|
links: {
|
|
848
850
|
path,
|
|
849
851
|
next: nextCursor
|
|
850
|
-
? utils_1.Utils.mergeRequestQuery(
|
|
852
|
+
? utils_1.Utils.mergeRequestQuery(req, {
|
|
851
853
|
cursor: nextCursor,
|
|
852
854
|
page: null,
|
|
853
855
|
})
|
|
854
856
|
: null,
|
|
855
857
|
prev: cursorParam !== ""
|
|
856
|
-
? utils_1.Utils.mergeRequestQuery(
|
|
858
|
+
? utils_1.Utils.mergeRequestQuery(req, { cursor: null, page: null })
|
|
857
859
|
: null,
|
|
858
860
|
},
|
|
859
861
|
};
|
|
860
862
|
}
|
|
861
|
-
async paginate(
|
|
862
|
-
const
|
|
863
|
-
const
|
|
863
|
+
async paginate(perPage = 15, page = 1) {
|
|
864
|
+
const req = request();
|
|
865
|
+
const pageNum = Math.max(1, Number(req?.query?.page || page) || 1);
|
|
866
|
+
const offset = (pageNum - 1) * Number(perPage);
|
|
864
867
|
const perPageNum = Number(perPage);
|
|
865
868
|
// Create one clone for counting (preserves original query state)
|
|
866
869
|
const countQuery = this.clone();
|
|
867
|
-
const total = await countQuery.count();
|
|
870
|
+
// const total = await countQuery.count();
|
|
868
871
|
// Reuse the original query builder for data (more efficient)
|
|
869
|
-
const data = await
|
|
872
|
+
const [total, data] = await Promise.all([
|
|
873
|
+
countQuery.count(),
|
|
874
|
+
this.offset(offset).limit(perPageNum).get(),
|
|
875
|
+
]);
|
|
870
876
|
const totalPages = Math.ceil(total / perPageNum);
|
|
871
|
-
const path = `${
|
|
877
|
+
const path = `${req.protocol}://${req.get("host")}${req.path}`;
|
|
872
878
|
return {
|
|
873
879
|
data: data,
|
|
874
880
|
meta: {
|
|
875
|
-
current_page:
|
|
881
|
+
current_page: pageNum,
|
|
876
882
|
per_page: perPage,
|
|
877
883
|
total: total,
|
|
878
884
|
total_pages: totalPages,
|
|
879
|
-
has_more:
|
|
880
|
-
links: utils_1.Utils.generatePaginationLinks(path,
|
|
885
|
+
has_more: pageNum < totalPages,
|
|
886
|
+
links: utils_1.Utils.generatePaginationLinks(path, pageNum, totalPages),
|
|
881
887
|
},
|
|
882
888
|
links: {
|
|
883
889
|
first: `${path}?page=1`,
|
|
@@ -2,7 +2,6 @@ import { BaseModel } from "./BaseModel";
|
|
|
2
2
|
import { Builder } from "./Builder";
|
|
3
3
|
import { MorphTo } from "./Relations";
|
|
4
4
|
import type { RelationshipQueryBuilder } from "./Relations/RelationTypes";
|
|
5
|
-
import { Request } from "express";
|
|
6
5
|
import { CursorPagination, Pagination, SimplePagination } from "./Interfaces";
|
|
7
6
|
export declare class Model extends BaseModel {
|
|
8
7
|
relations: Record<string, any>;
|
|
@@ -12,17 +11,17 @@ export declare class Model extends BaseModel {
|
|
|
12
11
|
getKeyName(): string;
|
|
13
12
|
static getPrimaryKey(): string;
|
|
14
13
|
getKey(): any;
|
|
15
|
-
static paginate<T extends Model>(this: typeof Model & (new (...args: any[]) => T),
|
|
14
|
+
static paginate<T extends Model>(this: typeof Model & (new (...args: any[]) => T), perPage?: number | string, page?: number): Promise<Pagination<T>>;
|
|
16
15
|
/**
|
|
17
16
|
* Offset pagination without a total `COUNT` (Laravel `simplePaginate`).
|
|
18
17
|
* Uses `page` query param; fetches `perPage + 1` rows to set `has_more`.
|
|
19
18
|
*/
|
|
20
|
-
static simplePaginate<T extends Model>(this: typeof Model & (new (...args: any[]) => T),
|
|
19
|
+
static simplePaginate<T extends Model>(this: typeof Model & (new (...args: any[]) => T), perPage?: number | string, page?: number): Promise<SimplePagination<T>>;
|
|
21
20
|
/**
|
|
22
21
|
* Keyset / cursor pagination (Laravel `cursorPaginate`).
|
|
23
22
|
* Next page: `?cursor=` from `meta.next_cursor`. Default order is `column` asc.
|
|
24
23
|
*/
|
|
25
|
-
static cursorPaginate<T extends Model>(this: typeof Model & (new (...args: any[]) => T),
|
|
24
|
+
static cursorPaginate<T extends Model>(this: typeof Model & (new (...args: any[]) => T), perPage?: number | string, column?: string, direction?: "asc" | "desc"): Promise<CursorPagination<T>>;
|
|
26
25
|
/**
|
|
27
26
|
* Creates a records in the database.
|
|
28
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/Model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAA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AQ,CAAC,GACtD,OAAO;IAIH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAWpC,WAAW,CAAC,IAAI,EAAE,MAAM;IAI/B;;OAEG;IACU,IAAI,CACf,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC;IAahB,MAAM,CAAC,SAAS;IAIhB,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAO/B,WAAW,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAyB;CAQxE"}
|
|
@@ -35,46 +35,47 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
35
35
|
// -----------------
|
|
36
36
|
// Pagination
|
|
37
37
|
// -----------------
|
|
38
|
-
static async paginate(
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
38
|
+
static async paginate(perPage = 15, page = 1) {
|
|
39
|
+
return this.clone().paginate(perPage, page);
|
|
40
|
+
// const pageNum = Math.max(1, Number(page || req?.query?.page) || 1);
|
|
41
|
+
// const offset = (page - 1) * Number(perPage);
|
|
42
|
+
// const count = await this.clone().count();
|
|
43
|
+
// const total = count;
|
|
44
|
+
// const data = await this.select()
|
|
45
|
+
// .offset(offset)
|
|
46
|
+
// .limit(Number(perPage))
|
|
47
|
+
// .get();
|
|
48
|
+
// const totalPages = Math.ceil(total / Number(perPage));
|
|
49
|
+
// const path = `${request.protocol}://${request.get("host")}${request.path}`;
|
|
50
|
+
// return {
|
|
51
|
+
// data: data as T[],
|
|
52
|
+
// meta: {
|
|
53
|
+
// current_page: page,
|
|
54
|
+
// per_page: perPage,
|
|
55
|
+
// total: total,
|
|
56
|
+
// total_pages: totalPages,
|
|
57
|
+
// has_more: page < totalPages,
|
|
58
|
+
// links: Utils.generatePaginationLinks(path, page, totalPages),
|
|
59
|
+
// },
|
|
60
|
+
// links: {
|
|
61
|
+
// first: `${path}?page=1`,
|
|
62
|
+
// last: `${path}?page=${totalPages}`,
|
|
63
|
+
// },
|
|
64
|
+
// };
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
67
|
* Offset pagination without a total `COUNT` (Laravel `simplePaginate`).
|
|
67
68
|
* Uses `page` query param; fetches `perPage + 1` rows to set `has_more`.
|
|
68
69
|
*/
|
|
69
|
-
static async simplePaginate(
|
|
70
|
-
return this.clone().simplePaginate(
|
|
70
|
+
static async simplePaginate(perPage = 15, page = 1) {
|
|
71
|
+
return this.clone().simplePaginate(perPage, page);
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
* Keyset / cursor pagination (Laravel `cursorPaginate`).
|
|
74
75
|
* Next page: `?cursor=` from `meta.next_cursor`. Default order is `column` asc.
|
|
75
76
|
*/
|
|
76
|
-
static async cursorPaginate(
|
|
77
|
-
return this.clone().cursorPaginate(
|
|
77
|
+
static async cursorPaginate(perPage = 15, column, direction = "asc") {
|
|
78
|
+
return this.clone().cursorPaginate(perPage, column, direction);
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* Creates a records in the database.
|
|
@@ -388,7 +389,7 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
388
389
|
}
|
|
389
390
|
createToken(payload = { id: this.getKey() }) {
|
|
390
391
|
if (!this.hasToken) {
|
|
391
|
-
throw new ModelTokenError_1.ModelTokenError(`${this.constructor.name} Missing required token. Please set 'protected hasToken = true' .`);
|
|
392
|
+
throw new ModelTokenError_1.ModelTokenError(`${this.constructor.name} Model Missing required token. Please set 'protected hasToken = true' .`);
|
|
392
393
|
}
|
|
393
394
|
return (0, util_1.jwtSign)(payload, { expiresIn: "22h" });
|
|
394
395
|
}
|
|
@@ -2,7 +2,6 @@ import type { Builder } from "./Builder";
|
|
|
2
2
|
import { ModelEvent } from "./Event/ModelEvent";
|
|
3
3
|
import { type Knex } from "knex";
|
|
4
4
|
import { AggregateInput, JoinCallback, SubJoinCallback, WhereInput } from "./Types";
|
|
5
|
-
import { Request } from "express";
|
|
6
5
|
export declare class QueryBuilder extends ModelEvent {
|
|
7
6
|
protected data?: Record<string, any> | undefined;
|
|
8
7
|
protected static table: string;
|
|
@@ -369,7 +368,7 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
369
368
|
static onlyTrashed(): Builder;
|
|
370
369
|
static getRaw(): any;
|
|
371
370
|
static firstRaw(): any;
|
|
372
|
-
static paginate(
|
|
371
|
+
static paginate(perPage?: number | string, page?: number): Promise<any>;
|
|
373
372
|
static findOrCreate(where: Record<string, any>, data: Record<string, any>): Promise<any>;
|
|
374
373
|
}
|
|
375
374
|
//# sourceMappingURL=QueryBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/QueryBuilder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,EACf,UAAU,EACX,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/QueryBuilder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,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,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;WAIrC,WAAW,IAAI,OAAO;WAItB,MAAM;WAIN,QAAQ;WAGT,QAAQ,CACnB,OAAO,GAAE,MAAM,GAAG,MAAW,EAC7B,IAAI,GAAE,MAAU,GACf,OAAO,CAAC,GAAG,CAAC;WAEF,YAAY,CACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACxB,OAAO,CAAC,GAAG,CAAC;CAQhB"}
|
|
@@ -577,14 +577,14 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
577
577
|
static firstRaw() {
|
|
578
578
|
return this.query().firstRaw();
|
|
579
579
|
}
|
|
580
|
-
static async paginate(
|
|
580
|
+
static async paginate(perPage = 15, page = 1) { }
|
|
581
581
|
static async findOrCreate(where, data) {
|
|
582
582
|
const result = await this.query().where(where).first();
|
|
583
583
|
if (result) {
|
|
584
584
|
return result;
|
|
585
585
|
}
|
|
586
586
|
else {
|
|
587
|
-
return this.query().
|
|
587
|
+
return this.query().create(data);
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
590
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Middleware/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAyB,EAEvB,cAAc,EACf,MAAM,SAAS,CAAC;AAejB,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAc;gBAEb,GAAG,EAAE,WAAW;IAWrB,0BAA0B,CAAC,gBAAgB,EAAE,cAAc,EAAE;IAM7D,eAAe;IAWf,GAAG,CAAC,gBAAgB,EAAE,cAAc,EAAE;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Middleware/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAyB,EAEvB,cAAc,EACf,MAAM,SAAS,CAAC;AAejB,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAc;gBAEb,GAAG,EAAE,WAAW;IAWrB,0BAA0B,CAAC,gBAAgB,EAAE,cAAc,EAAE;IAM7D,eAAe;IAWf,GAAG,CAAC,gBAAgB,EAAE,cAAc,EAAE;IA+B7C,OAAO,CAAC,yBAAyB;IASjC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,UAAU;CAGnB"}
|
package/lib/Middleware/index.js
CHANGED
|
@@ -59,7 +59,6 @@ class Middleware {
|
|
|
59
59
|
this.expressApp.use(((req, res, next) => {
|
|
60
60
|
this.app.instance("request", req);
|
|
61
61
|
this.app.instance("response", res);
|
|
62
|
-
this.app.instance("next", next);
|
|
63
62
|
res.on("finish", () => {
|
|
64
63
|
this.app.forgetMany(["request", "response", "next"]);
|
|
65
64
|
});
|
package/lib/util/index.d.ts
CHANGED
|
@@ -169,4 +169,11 @@ export declare const JSInBuilTClass: (className: string) => boolean;
|
|
|
169
169
|
* @param callback
|
|
170
170
|
*/
|
|
171
171
|
export declare const defer: (callback: () => any) => void;
|
|
172
|
+
export declare const findUserForAuth: (User: any, input: Record<string, any>) => Promise<any>;
|
|
173
|
+
export declare const authResponseMessages: (success?: boolean, message?: string, user?: Record<string, any> | null, token?: string | null) => {
|
|
174
|
+
success: boolean;
|
|
175
|
+
message: string;
|
|
176
|
+
user: Record<string, any> | null;
|
|
177
|
+
token: string | null;
|
|
178
|
+
};
|
|
172
179
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/util/index.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,UAAU,EAGX,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/util/index.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,UAAU,EAGX,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAOxC;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,GACc,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,UAAU,QAAO,IAG7B,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,SAMtC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,GACW,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,GACY,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,GACM,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,GACW,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,GACW,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,GAEvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAO,KAAK,CAAC,GAAG,CAGxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,GAM1C,CAAC;AA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AAC;AAEF,eAAO,MAAM,eAAe,GAC1B,MAAM,GAAG,EACT,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,iBAU3B,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,UAAS,OAAe,EACxB,UAAS,MAA8B,EACvC,OAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAW,EACvC,QAAO,MAAM,GAAG,IAAW;;;;;CAQ5B,CAAC"}
|
package/lib/util/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defer = exports.JSInBuilTClass = exports.extractQuery = exports.isModelInstance = exports.tap = exports.resolveModelBinding = exports.isSequelizeModel = exports.isMongooseModel = exports.findUserById = exports.pluralizeStr = exports.getJobClass = exports.getModelFile = exports.asyncHandler = exports.capitalize = exports.saveImage = exports.jwtSubjectId = exports.jwtVerify = exports.jwtSign = exports.jwtTokenType = exports.verifyHash = exports.bcrypt = exports.getProvider = exports.getProviders = exports.getRoute = exports.getRequest = exports.getMiddleware = exports.getModel = exports.getApiController = exports.getController = exports.loadRoute = exports.loadRoutes = exports.rootPath = void 0;
|
|
6
|
+
exports.authResponseMessages = exports.findUserForAuth = exports.defer = exports.JSInBuilTClass = exports.extractQuery = exports.isModelInstance = exports.tap = exports.resolveModelBinding = exports.isSequelizeModel = exports.isMongooseModel = exports.findUserById = exports.pluralizeStr = exports.getJobClass = exports.getModelFile = exports.asyncHandler = exports.capitalize = exports.saveImage = exports.jwtSubjectId = exports.jwtVerify = exports.jwtSign = exports.jwtTokenType = exports.verifyHash = exports.bcrypt = exports.getProvider = exports.getProviders = exports.getRoute = exports.getRequest = exports.getMiddleware = exports.getModel = exports.getApiController = exports.getController = exports.loadRoute = exports.loadRoutes = exports.rootPath = void 0;
|
|
7
7
|
exports.authSessionCookieOptions = authSessionCookieOptions;
|
|
8
8
|
exports.jwtLegacyAccessTokenRejected = jwtLegacyAccessTokenRejected;
|
|
9
9
|
exports.checkJwtAccessTokenPayload = checkJwtAccessTokenPayload;
|
|
@@ -475,3 +475,23 @@ const defer = (callback) => {
|
|
|
475
475
|
});
|
|
476
476
|
};
|
|
477
477
|
exports.defer = defer;
|
|
478
|
+
const findUserForAuth = async (User, input) => {
|
|
479
|
+
const orm = Config_1.config.get("DB_ORM");
|
|
480
|
+
if (orm === "mongodb" || orm === "mongoose") {
|
|
481
|
+
return await User.findOne({ ...input }).select("+password");
|
|
482
|
+
}
|
|
483
|
+
if (orm === "sequelize") {
|
|
484
|
+
return await User.findOne({ where: { ...input } });
|
|
485
|
+
}
|
|
486
|
+
return await User.where({ ...input }).first();
|
|
487
|
+
};
|
|
488
|
+
exports.findUserForAuth = findUserForAuth;
|
|
489
|
+
const authResponseMessages = (success = false, message = "Invalid credentials", user = null, token = null) => {
|
|
490
|
+
return {
|
|
491
|
+
success,
|
|
492
|
+
message,
|
|
493
|
+
user,
|
|
494
|
+
token,
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
exports.authResponseMessages = authResponseMessages;
|
package/package.json
CHANGED
package/lib/Auth/Auth.d.ts
DELETED
package/lib/Auth/Auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Auth/Auth.ts"],"names":[],"mappings":"AAAA,qBAAa,IAAI;IAEf,EAAE;IAIF,IAAI;IAIJ,eAAe;IAIf,OAAO;IAIP,KAAK;CAGN"}
|
package/lib/Auth/Auth.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Auth = void 0;
|
|
4
|
-
class Auth {
|
|
5
|
-
//
|
|
6
|
-
id() {
|
|
7
|
-
return request().user.id;
|
|
8
|
-
}
|
|
9
|
-
user() {
|
|
10
|
-
return request().user;
|
|
11
|
-
}
|
|
12
|
-
isAuthenticated() {
|
|
13
|
-
return request().user ? true : false;
|
|
14
|
-
}
|
|
15
|
-
isGuest() {
|
|
16
|
-
return request().user ? false : true;
|
|
17
|
-
}
|
|
18
|
-
check() {
|
|
19
|
-
return this.isAuthenticated();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.Auth = Auth;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AppRequest, AppResponse, AppNext } from "../Interface";
|
|
2
|
-
interface InertiaOptions {
|
|
3
|
-
rootView: string;
|
|
4
|
-
}
|
|
5
|
-
export declare const inertia: (options: InertiaOptions) => (req: AppRequest, res: AppResponse, next: AppNext) => void;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=old-index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"old-index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Inertia/old-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEhE,UAAU,cAAc;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAiED,eAAO,MAAM,OAAO,GAAI,SAAS,cAAc,WAzC9B,UAAU,OAAO,WAAW,QAAQ,OAAO,SA0CxB,CAAC"}
|
package/lib/Inertia/old-index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inertia = void 0;
|
|
4
|
-
class InertiaMiddleware {
|
|
5
|
-
shareProps(req, res, props) {
|
|
6
|
-
const errors = {
|
|
7
|
-
...res.locals.errors,
|
|
8
|
-
...(res.locals.error?.email ? res.locals.error : {}),
|
|
9
|
-
};
|
|
10
|
-
const auth = { ...req.user };
|
|
11
|
-
let getFlash = req.flash() || { type: "" };
|
|
12
|
-
const type = Object.keys(getFlash).length > 0 ? Object.keys(getFlash)[0] : "";
|
|
13
|
-
const flash = {
|
|
14
|
-
message: type ? getFlash[type][0] : "",
|
|
15
|
-
status: res.statusCode,
|
|
16
|
-
type,
|
|
17
|
-
};
|
|
18
|
-
getFlash = {};
|
|
19
|
-
return { ...props, auth, flash, errors };
|
|
20
|
-
}
|
|
21
|
-
inertia(options) {
|
|
22
|
-
return (req, res, next) => {
|
|
23
|
-
res.inertia = (component, props = {}, option = {}) => {
|
|
24
|
-
const isInertiaRequest = req.header("X-Inertia");
|
|
25
|
-
const sharedProps = this.shareProps(req, res, props);
|
|
26
|
-
if (isInertiaRequest) {
|
|
27
|
-
res.setHeader("X-Inertia", "true");
|
|
28
|
-
return res.json({
|
|
29
|
-
component,
|
|
30
|
-
props: sharedProps,
|
|
31
|
-
url: req.url,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
res.render(options.rootView, {
|
|
35
|
-
inertia: JSON.stringify({
|
|
36
|
-
component,
|
|
37
|
-
props: sharedProps,
|
|
38
|
-
url: req.url,
|
|
39
|
-
}),
|
|
40
|
-
option,
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
res.inertiaRedirect = (url, message, type = "success") => {
|
|
44
|
-
if (message) {
|
|
45
|
-
req.flash(type, message);
|
|
46
|
-
}
|
|
47
|
-
return res.redirect(303, url);
|
|
48
|
-
};
|
|
49
|
-
next();
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const inertiaMiddleware = new InertiaMiddleware();
|
|
54
|
-
const inertia = (options) => inertiaMiddleware.inertia(options);
|
|
55
|
-
exports.inertia = inertia;
|