miolo 3.0.0-beta.204 → 3.0.0-beta.206
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/bin/create/pkgjson.mjs +4 -1
- package/package.json +11 -11
- package/src/engines/schema/input.mjs +4 -2
- package/src/engines/schema/output.mjs +5 -2
- package/template/.agent/skills/miolo-app-arch/SKILL.md +26 -58
- package/template/.agent/skills/miolo-auth/SKILL.md +5 -5
- package/template/.agent/skills/miolo-database/SKILL.md +11 -11
- package/template/.agent/skills/miolo-routing/SKILL.md +8 -8
- package/template/.agent/skills/miolo-schemas/SKILL.md +2 -2
- package/template/.agent/skills/miolo-ssr/SKILL.md +2 -2
- package/template/package.json +9 -9
- package/template/src/server/{db/io → io/db}/todos/read.mjs +1 -1
- package/template/src/server/miolo/auth/basic.mjs +1 -1
- package/template/src/server/miolo/auth/passport.mjs +1 -1
- package/template/src/server/miolo/db.mjs +1 -1
- package/template/src/server/miolo/ssr/loader.mjs +1 -1
- package/template/src/server/routes/todos/mod.mjs +3 -3
- package/template/src/server/routes/todos/read.mjs +2 -2
- package/template/src/server/routes/users/user.mjs +2 -2
- /package/template/src/server/{console → bot}/check_today.mjs +0 -0
- /package/template/src/server/{cache → io/cache}/base.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/filter.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/todos/delete.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/todos/find.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/todos/toggle.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/todos/upsave.mjs +0 -0
- /package/template/src/server/{db → io/db}/triggers/user.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/users/auth.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/users/pwd.mjs +0 -0
- /package/template/src/server/{db/io → io/db}/users/save.mjs +0 -0
package/bin/create/pkgjson.mjs
CHANGED
|
@@ -28,7 +28,10 @@ export function transformPackageJson(content, appName) {
|
|
|
28
28
|
|
|
29
29
|
// Then, replace file:../ references with npm versions
|
|
30
30
|
const version = getMioloVersion()
|
|
31
|
-
transformed = transformed.replace(
|
|
31
|
+
transformed = transformed.replace(
|
|
32
|
+
/"file:\.\.\/(miolo-cli|miolo-react|miolo-model|miolo)"/g,
|
|
33
|
+
`"${version}"`
|
|
34
|
+
)
|
|
32
35
|
|
|
33
36
|
return transformed
|
|
34
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miolo",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.206",
|
|
4
4
|
"description": "all-in-one koa-based server",
|
|
5
5
|
"author": "Donato Lorenzo <donato@afialapis.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -44,17 +44,17 @@
|
|
|
44
44
|
"prepublishOnly": "npm run lint && npm run dist"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@babel/plugin-proposal-decorators": "^7.29.
|
|
48
|
-
"@babel/preset-env": "^7.29.
|
|
49
|
-
"@babel/preset-react": "^7.
|
|
50
|
-
"@dotenvx/dotenvx": "^1.
|
|
47
|
+
"@babel/plugin-proposal-decorators": "^7.29.7",
|
|
48
|
+
"@babel/preset-env": "^7.29.7",
|
|
49
|
+
"@babel/preset-react": "^7.29.7",
|
|
50
|
+
"@dotenvx/dotenvx": "^1.71.0",
|
|
51
51
|
"@koa/bodyparser": "^6.1.0",
|
|
52
52
|
"@koa/cors": "^5.0.0",
|
|
53
|
-
"@koa/router": "^15.
|
|
53
|
+
"@koa/router": "^15.6.0",
|
|
54
54
|
"@maxmind/geoip2-node": "^6.3.4",
|
|
55
55
|
"@rollup/plugin-alias": "^6.0.0",
|
|
56
|
-
"@rollup/plugin-babel": "^7.
|
|
57
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
56
|
+
"@rollup/plugin-babel": "^7.1.0",
|
|
57
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
58
58
|
"@rollup/plugin-json": "^6.1.0",
|
|
59
59
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
60
60
|
"@rollup/plugin-replace": "^6.0.3",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"koa-session": "^7.0.2",
|
|
84
84
|
"koa-static": "^5.0.0",
|
|
85
85
|
"nanoid": "^5.1.11",
|
|
86
|
-
"nodemailer": "^8.0.
|
|
86
|
+
"nodemailer": "^8.0.10",
|
|
87
87
|
"passport-google-oauth20": "^2.0.0",
|
|
88
88
|
"passport-local": "^1.0.0",
|
|
89
|
-
"rollup": "^4.
|
|
89
|
+
"rollup": "^4.61.0",
|
|
90
90
|
"rollup-plugin-node-externals": "^9.0.1",
|
|
91
91
|
"rollup-plugin-postcss": "^4.0.2",
|
|
92
92
|
"socket.io": "^4.8.3",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"statuses": "^2.0.2",
|
|
95
95
|
"tailwindcss": "^4.3.0",
|
|
96
96
|
"tinguir": "^0.0.7",
|
|
97
|
-
"vite": "^8.0.
|
|
97
|
+
"vite": "^8.0.16",
|
|
98
98
|
"winston": "^3.19.0",
|
|
99
99
|
"winston-daily-rotate-file": "^5.0.0",
|
|
100
100
|
"yargs-parser": "^22.0.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Joi from "joi"
|
|
2
2
|
|
|
3
|
-
export function with_miolo_input_schema(fn, schema) {
|
|
3
|
+
export function with_miolo_input_schema(fn, schema, options) {
|
|
4
4
|
return async (ctx, params) => {
|
|
5
5
|
let error
|
|
6
6
|
|
|
@@ -14,7 +14,9 @@ export function with_miolo_input_schema(fn, schema) {
|
|
|
14
14
|
// perform validation
|
|
15
15
|
let v
|
|
16
16
|
try {
|
|
17
|
-
v = schema.validate(params
|
|
17
|
+
v = schema.validate(params, {
|
|
18
|
+
...(options || {})
|
|
19
|
+
})
|
|
18
20
|
} catch (uerror) {
|
|
19
21
|
error = `Unexpected error validating input data for ${fn.name}: ${uerror?.message || uerror}`
|
|
20
22
|
ctx.miolo.logger.silly(`[validation][${fn.name}] ${error}`)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Joi from "joi"
|
|
2
2
|
import { diffObjs } from "./diffObjs.mjs"
|
|
3
3
|
|
|
4
|
-
export function with_miolo_output_schema(fn, schema) {
|
|
4
|
+
export function with_miolo_output_schema(fn, schema, options) {
|
|
5
5
|
const fnName = fn?.name ? `[${fn.name}]` : ""
|
|
6
6
|
|
|
7
7
|
return async (ctx, params) => {
|
|
@@ -20,7 +20,10 @@ export function with_miolo_output_schema(fn, schema) {
|
|
|
20
20
|
// perform validation over the result
|
|
21
21
|
let v
|
|
22
22
|
try {
|
|
23
|
-
v = schema.validate(result, {
|
|
23
|
+
v = schema.validate(result, {
|
|
24
|
+
stripUnknown: true,
|
|
25
|
+
...(options || {})
|
|
26
|
+
})
|
|
24
27
|
} catch (uerror) {
|
|
25
28
|
error = `Unexpected error validating output data for ${fn.name}: ${uerror?.message || uerror}`
|
|
26
29
|
ctx.miolo.logger.silly(`[validation]${fnName} ${error}`)
|
|
@@ -5,7 +5,7 @@ description: Standard architecture patterns for miolo applications. Use when cre
|
|
|
5
5
|
|
|
6
6
|
# Miolo Application Architecture
|
|
7
7
|
|
|
8
|
-
This skill defines the standard architecture for miolo applications based on
|
|
8
|
+
This skill defines the standard architecture for miolo applications, based on modern best practices (as seen in `miolo-sample`).
|
|
9
9
|
|
|
10
10
|
## Project Structure Overview
|
|
11
11
|
|
|
@@ -21,7 +21,7 @@ miolo-app/
|
|
|
21
21
|
├── biome.json # Biome configuration
|
|
22
22
|
├── postcss.config.js # PostCSS/Tailwind configuration
|
|
23
23
|
├── docker/ # Docker deployment configuration
|
|
24
|
-
├── db/ # Database initialization
|
|
24
|
+
├── db/ # Database initialization scripts and files
|
|
25
25
|
├── build/ # Production build output
|
|
26
26
|
├── src/ # Source code
|
|
27
27
|
│ ├── cli/ # Client-side React application
|
|
@@ -89,14 +89,12 @@ Docker deployment configuration:
|
|
|
89
89
|
- `docker-compose.yaml` - Service orchestration
|
|
90
90
|
- `Dockerfile` - Container build instructions
|
|
91
91
|
|
|
92
|
-
### db/
|
|
92
|
+
### db/
|
|
93
93
|
|
|
94
94
|
Database initialization scripts:
|
|
95
95
|
- `init.sh` - Database creation and setup script
|
|
96
96
|
- `sql/` - SQL migration files (executed in alphabetical order)
|
|
97
97
|
|
|
98
|
-
Not required for all apps, but recommended for PostgreSQL-based applications.
|
|
99
|
-
|
|
100
98
|
### build/
|
|
101
99
|
|
|
102
100
|
Production build output (generated, not versioned):
|
|
@@ -107,7 +105,7 @@ Created by `npm run build`, used in production deployment.
|
|
|
107
105
|
|
|
108
106
|
### src/cli/
|
|
109
107
|
|
|
110
|
-
Client-side React application code. **Fixed subdirectory structure**:
|
|
108
|
+
Client-side React application code. Utilizes **React Router v7** for client routing and deeply integrates **React Contexts** for state management. **Fixed subdirectory structure**:
|
|
111
109
|
|
|
112
110
|
```
|
|
113
111
|
src/cli/
|
|
@@ -132,12 +130,12 @@ src/cli/
|
|
|
132
130
|
└── ... # Feature-specific page directories
|
|
133
131
|
```
|
|
134
132
|
|
|
135
|
-
**Rules:**
|
|
133
|
+
**Rules & Best Practices:**
|
|
136
134
|
- Respect the subdirectory structure
|
|
137
|
-
-
|
|
135
|
+
- **React Contexts**: Contexts are heavily prioritized for global state, data caching, and UI management.
|
|
136
|
+
- **Client Routing**: Uses `react-router` v7. Main split happens in `Index.jsx` based on session state (using contexts).
|
|
138
137
|
- Pages go in `pages/`, grouped by feature
|
|
139
138
|
- Reusable UI components in `components/`
|
|
140
|
-
- Contexts follow the established pattern (Context.jsx, Provider.jsx, useContext.mjs)
|
|
141
139
|
|
|
142
140
|
### src/ns/
|
|
143
141
|
|
|
@@ -145,55 +143,49 @@ Shared code accessible from both client and server:
|
|
|
145
143
|
|
|
146
144
|
```
|
|
147
145
|
src/ns/
|
|
148
|
-
└── models/ # Data models
|
|
149
|
-
├── base/ # Base classes
|
|
146
|
+
└── models/ # Data models (using miolo-model)
|
|
147
|
+
├── base/ # Base classes
|
|
150
148
|
└── ... # Application-specific models
|
|
151
149
|
```
|
|
152
150
|
|
|
153
|
-
|
|
151
|
+
**miolo-model**: Utilize the `miolo-model` package to define robust data models that can be seamlessly validated and used across both client and server.
|
|
154
152
|
|
|
155
153
|
### src/server/
|
|
156
154
|
|
|
157
|
-
Backend server code. **
|
|
155
|
+
Backend server code. **Fixed subdirectory structure**:
|
|
158
156
|
|
|
159
157
|
```
|
|
160
158
|
src/server/
|
|
161
159
|
├── server.mjs # Server entry point
|
|
162
|
-
├──
|
|
163
|
-
├──
|
|
164
|
-
│ ├──
|
|
165
|
-
│
|
|
166
|
-
│
|
|
167
|
-
│
|
|
168
|
-
│ └── triggers/ # Database triggers
|
|
169
|
-
├── lib/ # Server libraries
|
|
160
|
+
├── bot/ # Scripts to run from cron or console
|
|
161
|
+
├── io/ # Data I/O layer
|
|
162
|
+
│ ├── cache/ # Cache layer between DB and outside world (naming: ch_)
|
|
163
|
+
│ └── db/ # Database operations only. Uses schemas. (naming: db_)
|
|
164
|
+
│ ├── users/ # User-related queries
|
|
165
|
+
│ └── ... # Feature-specific query directories
|
|
170
166
|
├── miolo/ # Miolo server configuration
|
|
171
167
|
│ ├── auth/ # Authentication strategies
|
|
172
168
|
│ ├── cache.mjs # Cache configuration
|
|
173
|
-
│ ├── cron/ # Cron jobs
|
|
174
169
|
│ ├── db.mjs # Database configuration
|
|
175
170
|
│ ├── http.mjs # HTTP configuration
|
|
176
171
|
│ ├── index.mjs # Main miolo config
|
|
177
172
|
│ ├── routes/ # Base route configuration
|
|
178
|
-
│ └── ssr/ # Server-side rendering
|
|
179
|
-
├── routes/ #
|
|
173
|
+
│ └── ssr/ # Server-side rendering entry and loader
|
|
174
|
+
├── routes/ # Centralized GET/POST routes. Index all r_ functions.
|
|
180
175
|
│ ├── index.mjs # Route registration
|
|
181
176
|
│ ├── users/ # User endpoints
|
|
182
177
|
│ └── ... # Feature-specific route directories
|
|
178
|
+
├── trigger/ # Outgoing functionalities: mailing, messaging, notifications.
|
|
183
179
|
└── utils/ # Server utilities
|
|
184
180
|
```
|
|
185
181
|
|
|
186
182
|
**Rules:**
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
-
|
|
190
|
-
-
|
|
191
|
-
-
|
|
192
|
-
|
|
193
|
-
**Key pattern:** When adding a new feature:
|
|
194
|
-
1. Create queries in `db/io/feature-name/`
|
|
195
|
-
2. Create route handlers in `routes/feature-name/`
|
|
196
|
-
3. Register routes in `routes/index.mjs`
|
|
183
|
+
- **`io/db/`**: STRICTLY database operations. Functions must use validation schemas and start with `db_`.
|
|
184
|
+
- **`io/cache/`**: Caching layer handling data fetching from DB with a cache mechanism. Functions start with `ch_`.
|
|
185
|
+
- **`routes/`**: Centralizes all HTTP endpoints. Functions start with `r_`. These functions pick the request, and call `io/db`, `io/cache`, or `trigger/` as appropriate. Special mention applies to functions used in the `before`/`after` hooks of routes.
|
|
186
|
+
- **`trigger/`**: Contains side-effect outgoing modules like emails, push notifications, or webhooks.
|
|
187
|
+
- **`bot/`**: CLI or cron scripts meant to execute periodically or via the console.
|
|
188
|
+
- **SSR (Server-Side Rendering)**: Configuration and loaders for SSR are stored in `miolo/ssr/`. It speeds up initial load and SEO by preloading data on the server.
|
|
197
189
|
|
|
198
190
|
### src/static/
|
|
199
191
|
|
|
@@ -203,8 +195,6 @@ Static assets:
|
|
|
203
195
|
src/static/
|
|
204
196
|
├── fonts/ # Custom fonts
|
|
205
197
|
├── img/ # Images
|
|
206
|
-
│ ├── default/ # Default images (avatars, etc.)
|
|
207
|
-
│ └── ...
|
|
208
198
|
├── public/ # Public root files (favicon, robots.txt)
|
|
209
199
|
└── style/ # Global CSS
|
|
210
200
|
```
|
|
@@ -218,28 +208,6 @@ src/static/
|
|
|
218
208
|
|
|
219
209
|
## Best Practices
|
|
220
210
|
|
|
221
|
-
1. **Respect directory structure** - Don't create new top-level directories without reason
|
|
222
|
-
2. **Use import aliases** - Always use `#cli/`, `#server/`, etc. for imports
|
|
223
|
-
3. **Follow naming conventions** - Use lowercase with hyphens for directories, camelCase for files
|
|
224
|
-
4. **Organize by feature** - In routes/ and db/io/, group by domain/feature
|
|
225
|
-
5. **Keep server config in miolo/** - Don't modify unless necessary
|
|
226
|
-
6. **Use contexts for state** - Follow established context patterns in cli/context/
|
|
227
|
-
|
|
228
|
-
## Common Patterns
|
|
229
|
-
|
|
230
|
-
**Adding a new feature:**
|
|
231
|
-
```
|
|
232
|
-
1. Add database queries: src/server/db/io/myfeature/*.mjs
|
|
233
|
-
2. Add API routes: src/server/routes/myfeature/*.mjs
|
|
234
|
-
3. Register routes: src/server/routes/index.mjs
|
|
235
|
-
4. Add client pages: src/cli/pages/myfeature/*.jsx
|
|
236
|
-
5. Add components if needed: src/cli/components/myfeature/*.jsx
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
**Adding authentication:**
|
|
240
|
-
- Strategies in `src/server/miolo/auth/`
|
|
241
|
-
- Configure in `src/server/miolo/index.mjs`
|
|
242
|
-
|
|
243
211
|
**Adding static assets:**
|
|
244
212
|
- Images: `src/static/img/`
|
|
245
213
|
- Fonts: `src/static/fonts/`
|
|
@@ -43,7 +43,7 @@ Unified authentication using Passport.js supporting both **local (username/passw
|
|
|
43
43
|
|
|
44
44
|
```javascript
|
|
45
45
|
import { db_find_user_by_id, db_auth_user,
|
|
46
|
-
db_user_find_or_create_from_google } from '#server/db/
|
|
46
|
+
db_user_find_or_create_from_google } from '#server/io/db/users/auth.mjs'
|
|
47
47
|
|
|
48
48
|
const get_user_id = (user, done, ctx) => {
|
|
49
49
|
const uid = user?.id
|
|
@@ -295,7 +295,7 @@ export default [{
|
|
|
295
295
|
|
|
296
296
|
### User Authentication (Local)
|
|
297
297
|
|
|
298
|
-
**File:** `src/server/db/
|
|
298
|
+
**File:** `src/server/io/db/users/auth.mjs`
|
|
299
299
|
|
|
300
300
|
```javascript
|
|
301
301
|
import { sha512 } from '#server/utils/crypt.mjs'
|
|
@@ -395,7 +395,7 @@ MIOLO_SESSION_SALT=your-random-salt-here
|
|
|
395
395
|
|
|
396
396
|
## Database Trigger for Password Hashing
|
|
397
397
|
|
|
398
|
-
**File:** `src/server/db/triggers/user.mjs`
|
|
398
|
+
**File:** `src/server/io/db/triggers/user.mjs`
|
|
399
399
|
|
|
400
400
|
```javascript
|
|
401
401
|
import { sha512 } from '#server/utils/crypt.mjs'
|
|
@@ -445,6 +445,6 @@ session: {
|
|
|
445
445
|
|
|
446
446
|
See actual implementations:
|
|
447
447
|
- `src/server/miolo/auth/passport.mjs` - Passport authentication config
|
|
448
|
-
- `src/server/db/
|
|
449
|
-
- `src/server/db/triggers/user.mjs` - Password hashing trigger
|
|
448
|
+
- `src/server/io/db/users/auth.mjs` - User authentication queries
|
|
449
|
+
- `src/server/io/db/triggers/user.mjs` - Password hashing trigger
|
|
450
450
|
- `src/server/utils/crypt.mjs` - Hashing utilities
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: miolo-database
|
|
3
|
-
description: Database query patterns and organization for miolo applications. Use when creating database queries, organizing db
|
|
3
|
+
description: Database query patterns and organization for miolo applications. Use when creating database queries, organizing io/db structure, writing SQL, or implementing data access layers in miolo apps. For validation schemas, see miolo-schemas skill.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Miolo Database Patterns
|
|
@@ -9,10 +9,10 @@ Database query organization and patterns for miolo applications using PostgreSQL
|
|
|
9
9
|
|
|
10
10
|
## Database Layer Organization
|
|
11
11
|
|
|
12
|
-
All database queries are in `src/server/db
|
|
12
|
+
All database queries are in `src/server/io/db/`, organized by domain:
|
|
13
13
|
|
|
14
14
|
```
|
|
15
|
-
src/server/db/
|
|
15
|
+
src/server/io/db/
|
|
16
16
|
├── filter.mjs # Common query filters
|
|
17
17
|
├── users/ # User-related queries
|
|
18
18
|
│ ├── auth.mjs
|
|
@@ -31,7 +31,7 @@ src/server/db/io/
|
|
|
31
31
|
All database functions follow consistent naming and structure:
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
// src/server/db/
|
|
34
|
+
// src/server/io/db/items/read.mjs
|
|
35
35
|
|
|
36
36
|
export async function db_item_read(ctx, params) {
|
|
37
37
|
ctx.miolo.logger.verbose('[db_item_read] Reading items...')
|
|
@@ -196,12 +196,12 @@ if (users.length === 0) {
|
|
|
196
196
|
|
|
197
197
|
## Query Filters with make_query_filter
|
|
198
198
|
|
|
199
|
-
All SELECT queries should use `make_query_filter()` from `db/
|
|
199
|
+
All SELECT queries should use `make_query_filter()` from `io/db/filter.mjs` to build WHERE clauses:
|
|
200
200
|
|
|
201
|
-
**File:** `src/server/db/
|
|
201
|
+
**File:** `src/server/io/db/filter.mjs`
|
|
202
202
|
|
|
203
203
|
```javascript
|
|
204
|
-
import { make_query_filter } from '#server/db/
|
|
204
|
+
import { make_query_filter } from '#server/io/db/filter.mjs'
|
|
205
205
|
|
|
206
206
|
export async function db_todo_read(ctx, filter) {
|
|
207
207
|
ctx.miolo.logger.verbose('[db_todo_read] Reading todos...')
|
|
@@ -346,13 +346,13 @@ Run initialization:
|
|
|
346
346
|
6. **Use transactions** - For multi-query operations that must succeed/fail together
|
|
347
347
|
7. **Index properly** - Add indexes on frequently queried columns
|
|
348
348
|
8. **Limit results** - Always use LIMIT for list queries to prevent large responses
|
|
349
|
-
9. **Keep queries in db
|
|
349
|
+
9. **Keep queries in io/db/** - Never write SQL in route handlers
|
|
350
350
|
10. **Always log** - Use `ctx.miolo.logger` for all operations (`verbose` level)
|
|
351
351
|
|
|
352
352
|
## Examples from miolo-sample
|
|
353
353
|
|
|
354
354
|
See actual implementations:
|
|
355
|
-
- `src/server/db/
|
|
356
|
-
- `src/server/db/
|
|
357
|
-
- `src/server/db/
|
|
355
|
+
- `src/server/io/db/todos/read.mjs` - Read queries
|
|
356
|
+
- `src/server/io/db/todos/upsave.mjs` - Insert/update pattern
|
|
357
|
+
- `src/server/io/db/users/auth.mjs` - Authentication query
|
|
358
358
|
- `src/server/miolo/db.mjs` - Database configuration
|
|
@@ -5,7 +5,7 @@ description: API routing patterns for miolo applications. Use when creating or m
|
|
|
5
5
|
|
|
6
6
|
# Miolo Routing Patterns
|
|
7
7
|
|
|
8
|
-
Standard patterns for creating API routes in miolo applications following miolo
|
|
8
|
+
Standard patterns for creating API routes in miolo applications following miolo conventions.
|
|
9
9
|
|
|
10
10
|
## Route Organization
|
|
11
11
|
|
|
@@ -61,7 +61,7 @@ export default [{
|
|
|
61
61
|
Route handlers receive `(ctx, params)` and return `{ ok, data }` or `{ ok, error }`:
|
|
62
62
|
|
|
63
63
|
```javascript
|
|
64
|
-
import { db_item_read } from '#server/db/
|
|
64
|
+
import { db_item_read } from '#server/io/db/items/read.mjs'
|
|
65
65
|
|
|
66
66
|
export async function r_item_list(ctx, params) {
|
|
67
67
|
try {
|
|
@@ -114,8 +114,8 @@ Complete CRUD implementation:
|
|
|
114
114
|
|
|
115
115
|
```javascript
|
|
116
116
|
// items/mod.mjs
|
|
117
|
-
import { db_item_upsave } from '#server/db/
|
|
118
|
-
import { db_item_delete } from '#server/db/
|
|
117
|
+
import { db_item_upsave } from '#server/io/db/items/upsave.mjs'
|
|
118
|
+
import { db_item_delete } from '#server/io/db/items/delete.mjs'
|
|
119
119
|
|
|
120
120
|
export async function r_item_upsave(ctx, params) {
|
|
121
121
|
try {
|
|
@@ -280,9 +280,9 @@ export async function r_item_find(ctx, params) {
|
|
|
280
280
|
|
|
281
281
|
## Adding a New Feature
|
|
282
282
|
|
|
283
|
-
1. **Create database functions** in `src/server/db/
|
|
283
|
+
1. **Create database functions** in `src/server/io/db/feature/`:
|
|
284
284
|
```javascript
|
|
285
|
-
// db/
|
|
285
|
+
// io/db/items/read.mjs
|
|
286
286
|
export async function db_item_read(ctx, params) { /* ... */ }
|
|
287
287
|
```
|
|
288
288
|
|
|
@@ -308,14 +308,14 @@ export async function r_item_find(ctx, params) {
|
|
|
308
308
|
|
|
309
309
|
## Best Practices
|
|
310
310
|
|
|
311
|
-
1. **Use database abstraction** - Never write SQL in routes, use `db
|
|
311
|
+
1. **Use database abstraction** - Never write SQL in routes, use `io/db/` functions
|
|
312
312
|
2. **Consistent naming** - Routes start with `r_`, database functions with `db_`
|
|
313
313
|
3. **Always log** - Use `ctx.miolo.logger` for all operations (`info`level)
|
|
314
314
|
4. **Return consistent format** - Always `{ ok, data }` or `{ ok, error }`
|
|
315
315
|
5. **Validate inputs (and outputs)** - Use Joi schemas for validation
|
|
316
316
|
6. **Handle errors** - Wrap in try/catch, return meaningful errors
|
|
317
317
|
7. **Check user access** - Use `ctx.state.user` to verify permissions
|
|
318
|
-
8. **Keep handlers thin** - Business logic in `db
|
|
318
|
+
8. **Keep handlers thin** - Business logic in `io/db/`, routes only handle HTTP
|
|
319
319
|
|
|
320
320
|
## Examples from miolo-sample
|
|
321
321
|
|
|
@@ -324,6 +324,6 @@ const eventSchema = Joi.object({
|
|
|
324
324
|
|
|
325
325
|
See actual implementations:
|
|
326
326
|
- `src/server/utils/schema.mjs` - Partial schema definitions
|
|
327
|
-
- `src/server/db/
|
|
328
|
-
- `src/server/db/
|
|
327
|
+
- `src/server/io/db/todos/read.mjs` - Database function with schema
|
|
328
|
+
- `src/server/io/db/todos/upsave.mjs` - Insert/update with schema
|
|
329
329
|
- `src/server/routes/index.mjs` - Route schemas (inline and wrapper)
|
|
@@ -16,8 +16,8 @@ The SSR loader preloads data on the server before sending the initial HTML to th
|
|
|
16
16
|
**File:** `src/server/miolo/ssr/loader.mjs`
|
|
17
17
|
|
|
18
18
|
```javascript
|
|
19
|
-
import { db_todo_read } from '#server/db/
|
|
20
|
-
import { db_user_profile } from '#server/db/
|
|
19
|
+
import { db_todo_read } from '#server/io/db/todos/read.mjs'
|
|
20
|
+
import { db_user_profile } from '#server/io/db/users/read.mjs'
|
|
21
21
|
|
|
22
22
|
const loader = async (ctx) => {
|
|
23
23
|
let todos = []
|
package/template/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"deb": "npx miolo deb",
|
|
14
14
|
"create-bin": "npx miolo create-bin",
|
|
15
15
|
"build": "rm -fr build/cli/* build/server/* &&npx miolo build && npm run create-bin",
|
|
16
|
-
"build-bin": "npx miolo build-bin --bin-entry=src/server/
|
|
16
|
+
"build-bin": "npx miolo build-bin --bin-entry=src/server/bot/check_today.mjs",
|
|
17
17
|
"start": "node ./build/server/run.mjs start 1>> /var/log/miolo-sample.log 2>&1",
|
|
18
18
|
"stop": "node ./build/server/run.mjs stop 1>> /var/log/miolo-sample.log 2>&1",
|
|
19
19
|
"restart": "node ./build/server/run.mjs restart 1>> /var/log/miolo-sample.log 2>&1"
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"farrapa": "^3.0.0-beta.10",
|
|
45
45
|
"intre": "^3.0.0-beta.4",
|
|
46
46
|
"joi": "^18.2.1",
|
|
47
|
-
"lucide-react": "^1.
|
|
48
|
-
"miolo-cli": "^3.0.0-beta.
|
|
47
|
+
"lucide-react": "^1.17.0",
|
|
48
|
+
"miolo-cli": "^3.0.0-beta.206",
|
|
49
49
|
"miolo-model": "file:../miolo-model",
|
|
50
|
-
"miolo-react": "^3.0.0-beta.
|
|
50
|
+
"miolo-react": "^3.0.0-beta.206",
|
|
51
51
|
"next-themes": "^0.4.6",
|
|
52
52
|
"radix-ui": "^1.4.3",
|
|
53
|
-
"react": "^19.2.
|
|
54
|
-
"react-dom": "^19.2.
|
|
55
|
-
"react-router": "^7.
|
|
53
|
+
"react": "^19.2.7",
|
|
54
|
+
"react-dom": "^19.2.7",
|
|
55
|
+
"react-router": "^7.16.0",
|
|
56
56
|
"recharts": "^3.8.1",
|
|
57
57
|
"sonner": "^2.0.7",
|
|
58
58
|
"tailwind": "^4.0.0",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"tw-animate-css": "^1.4.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@biomejs/biome": "2.4.
|
|
65
|
-
"miolo": "^3.0.0-beta.
|
|
64
|
+
"@biomejs/biome": "2.4.16",
|
|
65
|
+
"miolo": "^3.0.0-beta.206",
|
|
66
66
|
"sass-embedded": "^1.100.0"
|
|
67
67
|
},
|
|
68
68
|
"overrides": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Joi from "joi"
|
|
2
2
|
import { with_miolo_input_schema } from "miolo"
|
|
3
|
-
import { make_query_filter } from "#server/db/
|
|
3
|
+
import { make_query_filter } from "#server/io/db/filter.mjs"
|
|
4
4
|
import { bool_null, opt_int, opt_str_null } from "#server/utils/schema.mjs"
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// import path from 'path'
|
|
2
2
|
// import {fileURLToPath} from 'url'
|
|
3
|
-
import { beforeInsertUser } from "#server/db/triggers/user.mjs"
|
|
3
|
+
import { beforeInsertUser } from "#server/io/db/triggers/user.mjs"
|
|
4
4
|
|
|
5
5
|
// const __filename = fileURLToPath(import.meta.url)
|
|
6
6
|
// const __dirname = path.dirname(__filename)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { db_todo_delete } from "#server/db/
|
|
2
|
-
import { db_todo_toggle } from "#server/db/
|
|
3
|
-
import { db_todo_upsave } from "#server/db/
|
|
1
|
+
import { db_todo_delete } from "#server/io/db/todos/delete.mjs"
|
|
2
|
+
import { db_todo_toggle } from "#server/io/db/todos/toggle.mjs"
|
|
3
|
+
import { db_todo_upsave } from "#server/io/db/todos/upsave.mjs"
|
|
4
4
|
|
|
5
5
|
export async function r_todo_upsave(ctx, params) {
|
|
6
6
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { db_todo_find } from "#server/db/
|
|
2
|
-
import { db_todo_read } from "#server/db/
|
|
1
|
+
import { db_todo_find } from "#server/io/db/todos/find.mjs"
|
|
2
|
+
import { db_todo_read } from "#server/io/db/todos/read.mjs"
|
|
3
3
|
|
|
4
4
|
export async function r_todo_list(ctx, _params) {
|
|
5
5
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { db_password_change } from "#server/db/
|
|
2
|
-
import { db_user_save } from "#server/db/
|
|
1
|
+
import { db_password_change } from "#server/io/db/users/pwd.mjs"
|
|
2
|
+
import { db_user_save } from "#server/io/db/users/save.mjs"
|
|
3
3
|
import { generateRandomPassword } from "#server/utils/crypt.mjs"
|
|
4
4
|
|
|
5
5
|
export async function r_forgot(ctx, params) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|