@chidchanun/bcp 0.1.17 → 0.1.19
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/docs/README.md +350 -0
- package/docs/middleware.md +486 -24
- package/docs/releases/0.1.18.md +119 -0
- package/docs/releases/0.1.19.md +106 -0
- package/docs/validation.md +342 -0
- package/package.json +5 -1
- package/packages/client/src/validation.ts +1118 -0
- package/packages/server/src/middleware-loader.ts +34 -7
- package/packages/server/src/middleware-proxy.ts +325 -159
- package/packages/server/src/middleware.ts +544 -104
package/docs/README.md
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# BCP Framework Documentation Source
|
|
2
|
+
|
|
3
|
+
This directory is the documentation source of truth for the BCP Framework documentation website.
|
|
4
|
+
|
|
5
|
+
The recommended documentation website project name is `bcp-docs`.
|
|
6
|
+
|
|
7
|
+
> Documentation target: BCP Framework `0.1.19`
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
The `bcp-docs` website should turn the Markdown files in this directory into a structured developer documentation experience without duplicating framework behavior in a separate source of truth.
|
|
12
|
+
|
|
13
|
+
When framework behavior changes:
|
|
14
|
+
|
|
15
|
+
1. update the framework source and tests,
|
|
16
|
+
2. update the relevant file in `docs/`,
|
|
17
|
+
3. update the release note in `docs/releases/`,
|
|
18
|
+
4. then publish or synchronize the content to `bcp-docs`.
|
|
19
|
+
|
|
20
|
+
The website should not invent API behavior that is not documented or tested in the framework repository.
|
|
21
|
+
|
|
22
|
+
## Recommended website navigation
|
|
23
|
+
|
|
24
|
+
### Getting Started
|
|
25
|
+
|
|
26
|
+
| Website route | Source file | Description |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `/docs/getting-started` | `getting-started.md` | Create and run a BCP application |
|
|
29
|
+
| `/docs/configuration` | `configuration.md` | Framework configuration |
|
|
30
|
+
| `/docs/application-modules` | `application-modules.md` | Client/server module boundaries |
|
|
31
|
+
| `/docs/deployment` | `deployment.md` | Production and deployment guidance |
|
|
32
|
+
| `/docs/updating` | `updating.md` | Upgrade an existing BCP project |
|
|
33
|
+
|
|
34
|
+
### Routing and Data
|
|
35
|
+
|
|
36
|
+
| Website route | Source file | Description |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `/docs/routing` | `routing.md` | File-based routing |
|
|
39
|
+
| `/docs/server-data-loaders` | `server-data-loaders.md` | Server-side page data |
|
|
40
|
+
| `/docs/route-guards` | `route-guards.md` | Scoped page authorization |
|
|
41
|
+
| `/docs/form-actions` | `form-actions.md` | Server mutations and forms |
|
|
42
|
+
| `/docs/server-request-apis` | `server-request-apis.md` | Request, cookie, redirect and response APIs |
|
|
43
|
+
| `/docs/validation` | `validation.md` | Typed form/API validation and field errors |
|
|
44
|
+
|
|
45
|
+
### Authentication
|
|
46
|
+
|
|
47
|
+
| Website route | Source file | Description |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| `/docs/authentication` | `authentication.md` | Authentication Core and `bcp/auth` |
|
|
50
|
+
| `/docs/auth-route-guards` | `auth-route-guards.md` | `requireAuth`, `requireRole` and guard integration |
|
|
51
|
+
| `/docs/session-auth` | `session-auth.md` | Low-level JWT cookie sessions |
|
|
52
|
+
|
|
53
|
+
### Database
|
|
54
|
+
|
|
55
|
+
| Website route | Source file | Description |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| `/docs/database` | `database.md` | `bcp/database`, MySQL and transactions |
|
|
58
|
+
| `/docs/database-migrations` | `database-migrations.md` | Migration CLI and migration files |
|
|
59
|
+
|
|
60
|
+
### Runtime and Infrastructure
|
|
61
|
+
|
|
62
|
+
| Website route | Source file | Description |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| `/docs/middleware` | `middleware.md` | Middleware System v2 and v1 compatibility |
|
|
65
|
+
| `/docs/caching` | `caching.md` | Cache and revalidation |
|
|
66
|
+
| `/docs/security` | `security.md` | Framework security defaults |
|
|
67
|
+
| `/docs/development-logging` | `development-logging.md` | Development request logging |
|
|
68
|
+
|
|
69
|
+
### Releases
|
|
70
|
+
|
|
71
|
+
Use the files under `docs/releases/` for release pages.
|
|
72
|
+
|
|
73
|
+
Recommended route format:
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
/releases/0.1.17
|
|
77
|
+
/releases/0.1.18
|
|
78
|
+
/releases/0.1.19
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The newest release should also be available from `/releases`.
|
|
82
|
+
|
|
83
|
+
## Homepage content for bcp-docs
|
|
84
|
+
|
|
85
|
+
The documentation homepage should describe BCP as a React full-stack framework and highlight the currently implemented capabilities.
|
|
86
|
+
|
|
87
|
+
Recommended feature groups:
|
|
88
|
+
|
|
89
|
+
### Application
|
|
90
|
+
|
|
91
|
+
- File-based routing
|
|
92
|
+
- React SSR
|
|
93
|
+
- SPA navigation
|
|
94
|
+
- Persistent layouts
|
|
95
|
+
- Loading and error UI
|
|
96
|
+
- API routes
|
|
97
|
+
- Client islands / partial hydration
|
|
98
|
+
|
|
99
|
+
### Server data and mutations
|
|
100
|
+
|
|
101
|
+
- Server data loaders
|
|
102
|
+
- Route guards
|
|
103
|
+
- Form actions
|
|
104
|
+
- Request-scoped server APIs
|
|
105
|
+
- Cookies and redirects
|
|
106
|
+
- `bcp/validation`
|
|
107
|
+
- Typed form/API validation
|
|
108
|
+
- Field and form error output
|
|
109
|
+
|
|
110
|
+
### Database
|
|
111
|
+
|
|
112
|
+
- `bcp/database`
|
|
113
|
+
- Lazy MySQL connection pool
|
|
114
|
+
- Queries and prepared execution
|
|
115
|
+
- Transactions
|
|
116
|
+
- Database migrations
|
|
117
|
+
- Migration status and rollback
|
|
118
|
+
|
|
119
|
+
### Authentication
|
|
120
|
+
|
|
121
|
+
- `bcp/auth`
|
|
122
|
+
- JWT cookie sessions
|
|
123
|
+
- Typed users and session data
|
|
124
|
+
- Session rotation
|
|
125
|
+
- `requireAuth()`
|
|
126
|
+
- `requireRole()`
|
|
127
|
+
- Auth-aware route guards
|
|
128
|
+
|
|
129
|
+
### Middleware
|
|
130
|
+
|
|
131
|
+
- Middleware System v2
|
|
132
|
+
- Middleware chains
|
|
133
|
+
- Real `await next()` downstream execution
|
|
134
|
+
- Before/after response interception
|
|
135
|
+
- Shared request context state
|
|
136
|
+
- Matchers
|
|
137
|
+
- Rewrite and redirect
|
|
138
|
+
- Backward-compatible Middleware v1 handlers
|
|
139
|
+
|
|
140
|
+
### Production and DX
|
|
141
|
+
|
|
142
|
+
- `create-bcp-app`
|
|
143
|
+
- Interactive project setup
|
|
144
|
+
- Tailwind preset
|
|
145
|
+
- Database/auth presets
|
|
146
|
+
- `bcp update`
|
|
147
|
+
- Standalone production builds
|
|
148
|
+
- Critical CSS
|
|
149
|
+
- Cache/revalidation
|
|
150
|
+
- Security defaults
|
|
151
|
+
- Unit/integration/E2E/package smoke testing in the framework repository
|
|
152
|
+
|
|
153
|
+
## Suggested homepage hero
|
|
154
|
+
|
|
155
|
+
Suggested content, not a required exact copy:
|
|
156
|
+
|
|
157
|
+
```text
|
|
158
|
+
BCP Framework
|
|
159
|
+
A React full-stack framework for building server-rendered applications with routing,
|
|
160
|
+
data loading, server mutations, authentication, databases, validation, middleware and production tooling.
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Primary actions:
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
Get Started
|
|
167
|
+
Read the Docs
|
|
168
|
+
View on GitHub
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The website may display the current release version from project metadata instead of hard-coding it in multiple UI files.
|
|
172
|
+
|
|
173
|
+
## Suggested documentation sidebar
|
|
174
|
+
|
|
175
|
+
```text
|
|
176
|
+
Getting Started
|
|
177
|
+
Introduction
|
|
178
|
+
Installation
|
|
179
|
+
Project Structure
|
|
180
|
+
Configuration
|
|
181
|
+
Updating
|
|
182
|
+
|
|
183
|
+
Core
|
|
184
|
+
Routing
|
|
185
|
+
Application Modules
|
|
186
|
+
Server Request APIs
|
|
187
|
+
Server Data Loaders
|
|
188
|
+
Route Guards
|
|
189
|
+
Form Actions
|
|
190
|
+
Validation
|
|
191
|
+
|
|
192
|
+
Authentication
|
|
193
|
+
Authentication Core
|
|
194
|
+
Auth Route Guards
|
|
195
|
+
JWT Sessions
|
|
196
|
+
|
|
197
|
+
Database
|
|
198
|
+
Database
|
|
199
|
+
Migrations
|
|
200
|
+
|
|
201
|
+
Runtime
|
|
202
|
+
Middleware
|
|
203
|
+
Caching
|
|
204
|
+
Security
|
|
205
|
+
|
|
206
|
+
Production
|
|
207
|
+
Deployment
|
|
208
|
+
Development Logging
|
|
209
|
+
|
|
210
|
+
Releases
|
|
211
|
+
0.1.19
|
|
212
|
+
0.1.18
|
|
213
|
+
0.1.17
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Suggested documentation page layout
|
|
217
|
+
|
|
218
|
+
Each documentation page should support:
|
|
219
|
+
|
|
220
|
+
- title
|
|
221
|
+
- short summary
|
|
222
|
+
- previous/next page navigation
|
|
223
|
+
- table of contents generated from headings
|
|
224
|
+
- syntax-highlighted code blocks
|
|
225
|
+
- copy-code button
|
|
226
|
+
- deep links to headings
|
|
227
|
+
- responsive sidebar
|
|
228
|
+
- mobile navigation
|
|
229
|
+
- light/dark appearance
|
|
230
|
+
- framework version label
|
|
231
|
+
- link to the corresponding source Markdown file in GitHub
|
|
232
|
+
|
|
233
|
+
Optional later additions:
|
|
234
|
+
|
|
235
|
+
- documentation search
|
|
236
|
+
- version selector
|
|
237
|
+
- API symbol index
|
|
238
|
+
- interactive examples
|
|
239
|
+
- edit-on-GitHub links
|
|
240
|
+
|
|
241
|
+
## Code examples
|
|
242
|
+
|
|
243
|
+
Examples should use the public package entrypoints that application developers actually install.
|
|
244
|
+
|
|
245
|
+
Preferred:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import {
|
|
249
|
+
auth,
|
|
250
|
+
requireAuth,
|
|
251
|
+
} from "bcp/auth";
|
|
252
|
+
|
|
253
|
+
import {
|
|
254
|
+
db,
|
|
255
|
+
} from "bcp/database";
|
|
256
|
+
|
|
257
|
+
import {
|
|
258
|
+
v,
|
|
259
|
+
validateFormData,
|
|
260
|
+
} from "bcp/validation";
|
|
261
|
+
|
|
262
|
+
import {
|
|
263
|
+
type MiddlewarePipelineHandler,
|
|
264
|
+
} from "bcp/middleware";
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Avoid documenting internal monorepo imports such as:
|
|
268
|
+
|
|
269
|
+
```text
|
|
270
|
+
packages/server/src/...
|
|
271
|
+
packages/client/src/...
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
unless a page is explicitly explaining framework internals.
|
|
275
|
+
|
|
276
|
+
## Version labels
|
|
277
|
+
|
|
278
|
+
The website should distinguish:
|
|
279
|
+
|
|
280
|
+
- current stable npm version
|
|
281
|
+
- documentation target version
|
|
282
|
+
- unreleased/main documentation if it is shown
|
|
283
|
+
|
|
284
|
+
Do not label unreleased `main` behavior as already available from npm until the corresponding package has been published.
|
|
285
|
+
|
|
286
|
+
## Framework commands to document
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
bcp dev
|
|
290
|
+
bcp routes
|
|
291
|
+
bcp build
|
|
292
|
+
bcp start
|
|
293
|
+
bcp update
|
|
294
|
+
bcp version
|
|
295
|
+
|
|
296
|
+
bcp db create create_users
|
|
297
|
+
bcp db migrate
|
|
298
|
+
bcp db status
|
|
299
|
+
bcp db rollback
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Project creation:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
npx create-bcp-app@latest my-app
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Middleware v2 documentation priority
|
|
309
|
+
|
|
310
|
+
BCP 0.1.18 introduced a meaningful middleware architecture change, so the `bcp-docs` website should make the distinction between v1 and v2 clear.
|
|
311
|
+
|
|
312
|
+
The middleware page should prominently explain:
|
|
313
|
+
|
|
314
|
+
```text
|
|
315
|
+
v1 next() = return a pass-through instruction
|
|
316
|
+
v2 await next() = execute downstream middleware/application and receive Response
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Existing v1 code remains supported, so migration documentation should describe v2 as an additive upgrade rather than a mandatory rewrite.
|
|
320
|
+
|
|
321
|
+
See `middleware.md` for the full API and examples.
|
|
322
|
+
|
|
323
|
+
## Validation documentation priority
|
|
324
|
+
|
|
325
|
+
BCP 0.1.19 introduces the public `bcp/validation` entrypoint. The docs website should show validation in both form-action and API-route examples.
|
|
326
|
+
|
|
327
|
+
Important concepts to surface:
|
|
328
|
+
|
|
329
|
+
- `v.object`, `v.string`, `v.number`, `v.boolean`, `v.array`
|
|
330
|
+
- FormData coercion with `validateFormData()`
|
|
331
|
+
- `success/data` versus `issues/fieldErrors/formErrors`
|
|
332
|
+
- object fields are stripped unless `allowUnknown: true`
|
|
333
|
+
- `refine()` for custom application rules
|
|
334
|
+
- no external validation dependency is required
|
|
335
|
+
|
|
336
|
+
See `validation.md` for the complete API and examples.
|
|
337
|
+
|
|
338
|
+
## Release workflow for documentation
|
|
339
|
+
|
|
340
|
+
Before publishing a new BCP release:
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
npm run typecheck
|
|
344
|
+
npm run test:unit
|
|
345
|
+
npm run rc:check
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
After npm publication, the docs website can update its displayed stable version.
|
|
349
|
+
|
|
350
|
+
The framework repository remains authoritative for API correctness; `bcp-docs` is the presentation layer for that content.
|