@chidchanun/bcp 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -2,36 +2,27 @@
2
2
 
3
3
  BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, database access, validation, uploads, storage and standalone Node.js production deployment.
4
4
 
5
- > **Development target:** `0.2.1Documentation Platform`
5
+ > **Development target:** `0.2.3Database Platform v2`
6
6
  >
7
- > `0.2.1` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.3` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
8
8
 
9
9
  ## 0.2 platform
10
10
 
11
- `0.2.0` established the Framework Platform baseline. `0.2.1` builds a machine-readable Documentation Platform on top of that baseline without intentionally removing application runtime public entrypoints.
11
+ `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, and `0.2.3` adds a provider-neutral SQL database platform with MySQL, PostgreSQL and SQLite support without intentionally removing public application entrypoints.
12
12
 
13
- The authoritative platform/documentation contracts are:
13
+ Machine-readable platform contracts:
14
14
 
15
15
  ```text
16
16
  docs/platform-manifest.json
17
- -> runtime target, public entrypoints, capabilities and compatibility
17
+ -> runtime target, capabilities and compatibility
18
18
 
19
19
  docs/docs-web-manifest.json
20
- -> docs sections, routes, Markdown sources and releases
20
+ -> documentation navigation, routes and releases
21
21
 
22
22
  docs/api-manifest.json
23
- -> public package entrypoints, source ownership and guide routes
23
+ -> public package entrypoints and guide ownership
24
24
  ```
25
25
 
26
- Authored documentation remains under `docs/*.md`.
27
-
28
- Read more:
29
-
30
- - [Framework Platform Contract](docs/platform-contract.md)
31
- - [Documentation Platform](docs/documentation-platform.md)
32
- - [API Reference](docs/api-reference.md)
33
- - [Migrating to 0.2.x](docs/migration-0.2.md)
34
-
35
26
  ## Current capabilities
36
27
 
37
28
  | Area | Capability |
@@ -45,14 +36,15 @@ Read more:
45
36
  | Middleware | Middleware System v2 with onion execution |
46
37
  | Validation | Typed validators and structured validation errors |
47
38
  | Error handling | HTTP error helpers and consistent error responses |
48
- | Database | MySQL helpers, transactions and migrations |
39
+ | Database | Provider-neutral MySQL, PostgreSQL and SQLite adapters, transactions, lifecycle and migrations |
49
40
  | Logging | Structured logger, request logger and request IDs |
50
41
  | Uploads | Buffered multipart helpers and production multipart streaming |
51
42
  | Storage | Local + S3-compatible storage, streaming, list/copy/move, metadata, bulk delete and signed URLs |
52
43
  | Caching | Response cache and revalidation primitives |
44
+ | Configuration | Typed `bcp.config.*`, optional `bcp.environment.*`, startup diagnostics and `bcp config check` |
53
45
  | Developer tools | Generators, Doctor/Inspect v2, updater, route inspection and project metadata |
54
46
  | Production | Standalone Node.js build, hardening gateway, graceful shutdown, trusted proxy controls and HTTP timeouts |
55
- | Documentation | Manifest-driven docs navigation, platform metadata and public API entrypoint reference |
47
+ | Documentation | Manifest-driven docs navigation, platform metadata and public API reference |
56
48
 
57
49
  ## Requirements
58
50
 
@@ -60,7 +52,13 @@ Read more:
60
52
  - React `19`
61
53
  - npm
62
54
 
63
- Database framework primitives currently target MySQL. `create-bcp-app` can also scaffold PostgreSQL, SQLite and MongoDB application helpers.
55
+ Database drivers are optional and provider-specific:
56
+
57
+ ```text
58
+ MySQL mysql2
59
+ PostgreSQL pg
60
+ SQLite better-sqlite3
61
+ ```
64
62
 
65
63
  ## Quick start
66
64
 
@@ -80,45 +78,208 @@ Generated projects normally keep one framework dependency key:
80
78
  }
81
79
  ```
82
80
 
83
- Do not install both `bcp` and a second direct `@chidchanun/bcp` dependency in the same application; duplicate framework copies can create separate React/framework contexts.
81
+ Do not install both `bcp` and a second direct `@chidchanun/bcp` dependency in the same application.
84
82
 
85
- ## Application model
83
+ ## Configuration
84
+
85
+ Framework configuration stays in one of:
86
86
 
87
87
  ```text
88
- Browser
89
-
90
- Security / middleware / cache
91
-
92
- Route guard
93
-
94
- Loader / action / API route
95
-
96
- React SSR
97
-
98
- Hydration / SPA navigation
88
+ bcp.config.ts
89
+ bcp.config.mts
90
+ bcp.config.js
91
+ bcp.config.mjs
99
92
  ```
100
93
 
101
- Typical route structure:
94
+ Example:
95
+
96
+ ```ts
97
+ import {
98
+ defineConfig,
99
+ } from "bcp/config";
100
+
101
+ export default defineConfig({
102
+ server: {
103
+ port: 3000,
104
+ hostname: "0.0.0.0",
105
+ },
106
+ build: {
107
+ minify: true,
108
+ sourceMaps: false,
109
+ },
110
+ security: {
111
+ poweredByHeader: false,
112
+ },
113
+ });
114
+ ```
115
+
116
+ Configuration precedence remains:
102
117
 
103
118
  ```text
104
- app/
105
- ├─ layout.tsx
106
- ├─ page.tsx
107
- ├─ dashboard/
108
- │ ├─ guard.ts
109
- │ └─ users/
110
- │ └─ [id]/
111
- │ ├─ loader.ts
112
- │ ├─ actions.ts
113
- │ └─ page.tsx
114
- └─ api/
115
- └─ upload/
116
- └─ route.ts
119
+ CLI override
120
+
121
+ BCP_* environment
122
+
123
+ bcp.config.*
124
+
125
+ framework defaults
126
+ ```
127
+
128
+ Read more: [Configuration](docs/configuration.md)
129
+
130
+ ## Environment Validation — 0.2.2
131
+
132
+ Application-specific variables can be declared in an optional environment schema:
133
+
134
+ ```text
135
+ bcp.environment.ts
136
+ ```
137
+
138
+ Example:
139
+
140
+ ```ts
141
+ import {
142
+ defineEnvironment,
143
+ } from "bcp/config";
144
+
145
+ export default defineEnvironment({
146
+ DB_HOST: {
147
+ type: "string",
148
+ required: true,
149
+ },
150
+
151
+ DB_PORT: {
152
+ type: "number",
153
+ default: 3306,
154
+ min: 1,
155
+ max: 65535,
156
+ },
157
+
158
+ SESSION_SECRET: {
159
+ type: "string",
160
+ required: true,
161
+ secret: true,
162
+ minLength: 32,
163
+ },
164
+
165
+ FEATURE_ENABLED: {
166
+ type: "boolean",
167
+ default: false,
168
+ },
169
+
170
+ BCP_PUBLIC_API_URL: {
171
+ type: "url",
172
+ required: true,
173
+ },
174
+ });
175
+ ```
176
+
177
+ Supported types:
178
+
179
+ ```text
180
+ string
181
+ number
182
+ boolean
183
+ url
184
+ ```
185
+
186
+ Validate the current project:
187
+
188
+ ```bash
189
+ bcp config check
190
+ ```
191
+
192
+ JSON diagnostics:
193
+
194
+ ```bash
195
+ bcp config check --json
196
+ ```
197
+
198
+ On Windows, where Microsoft SQL Server may provide another `bcp.exe`, prefer:
199
+
200
+ ```powershell
201
+ npm exec -- bcp-framework config check
202
+ npm exec -- bcp-framework config check --json
203
+ ```
204
+
205
+ `bcp dev` and `bcp build` also validate `bcp.environment.*` before startup/build. Invalid required values fail early.
206
+
207
+ The development supervisor watches:
208
+
209
+ ```text
210
+ .env*
211
+ bcp.config.*
212
+ bcp.environment.*
213
+ ```
214
+
215
+ and restarts the worker when one of those files changes.
216
+
217
+ ### Secret safety
218
+
219
+ Variables beginning with `BCP_PUBLIC_` can be embedded into browser bundles.
220
+
221
+ A variable marked:
222
+
223
+ ```ts
224
+ secret: true
225
+ ```
226
+
227
+ must not use `BCP_PUBLIC_`. BCP reports this as a configuration error.
228
+
229
+ `secret: true` is tooling metadata; it does not encrypt environment values.
230
+
231
+ Read more: [Environment Validation](docs/environment-validation.md)
232
+
233
+ ## Database Platform v2 — 0.2.3
234
+
235
+ Application code uses the same server-only entrypoint across supported SQL providers:
236
+
237
+ ```ts
238
+ import {
239
+ db,
240
+ createDatabase,
241
+ } from "bcp/database";
242
+ ```
243
+
244
+ Built-in providers:
245
+
246
+ ```text
247
+ mysql
248
+ postgresql
249
+ sqlite
250
+ ```
251
+
252
+ Connections remain lazy, while explicit lifecycle control is available when needed:
253
+
254
+ ```ts
255
+ await db.connect();
256
+
257
+ // application work
258
+
259
+ await db.disconnect();
260
+ ```
261
+
262
+ `db.close()` remains available for backward-compatible shutdown handling.
263
+
264
+ Database migrations use the same CLI across providers:
265
+
266
+ ```bash
267
+ bcp db create create_users
268
+ bcp db migrate
269
+ bcp db status
270
+ bcp db rollback
117
271
  ```
118
272
 
273
+ BCP makes its internal migration bookkeeping provider-aware. Application SQL itself is not automatically translated between SQL dialects.
274
+
275
+ Read more:
276
+
277
+ - [Database](docs/database.md)
278
+ - [Database Migrations](docs/database-migrations.md)
279
+
119
280
  ## Public entrypoints
120
281
 
121
- The `0.2.x` platform contract recognizes:
282
+ The current `0.2.x` platform contract recognizes:
122
283
 
123
284
  ```text
124
285
  bcp
@@ -134,15 +295,14 @@ bcp/server-only
134
295
  bcp/middleware
135
296
  ```
136
297
 
137
- Application code should use these public package entrypoints rather than importing internal framework files under `packages/`.
298
+ Application code should use public entrypoints instead of importing framework internals under `packages/`.
138
299
 
139
- The public list is validated in both:
300
+ See:
140
301
 
302
+ - [API Reference](docs/api-reference.md)
141
303
  - [Platform Manifest](docs/platform-manifest.json)
142
304
  - [API Manifest](docs/api-manifest.json)
143
305
 
144
- See [API Reference](docs/api-reference.md) for ownership and related guides.
145
-
146
306
  ## CLI
147
307
 
148
308
  Core commands:
@@ -153,6 +313,7 @@ bcp build
153
313
  bcp start
154
314
  bcp routes
155
315
  bcp update
316
+ bcp config check
156
317
  bcp doctor
157
318
  bcp inspect
158
319
  bcp version
@@ -178,112 +339,48 @@ bcp generate migration create_users
178
339
 
179
340
  Page/API/middleware generators require `--force` before replacing an existing scaffold target.
180
341
 
181
- On Windows, Microsoft SQL Server may provide another `bcp.exe`. For direct PowerShell usage prefer the project-local collision-free alias:
182
-
183
- ```powershell
184
- npm exec -- bcp-framework doctor
185
- npm exec -- bcp-framework inspect
186
- npm exec -- bcp-framework routes
187
- npm exec -- bcp-framework generate page dashboard/users
188
- ```
189
-
190
- ## Routing, loaders, guards and actions
191
-
192
- BCP discovers pages from `app/**/page.tsx` and API handlers from `app/**/route.ts`.
193
-
194
- ```text
195
- app/page.tsx /
196
- app/users/[id]/page.tsx /users/:id
197
- app/docs/[...slug]/page.tsx /docs/*
198
- app/catalog/[[...slug]]/page.tsx /catalog and /catalog/*
199
- app/(admin)/settings/page.tsx /settings
200
- app/api/users/route.ts /api/users
201
- ```
202
-
203
- Route-owned server features stay colocated:
342
+ ## Application model
204
343
 
205
344
  ```text
206
- page.tsx
207
- loader.ts
208
- guard.ts
209
- actions.ts
210
- ```
211
-
212
- Guides:
213
-
214
- - [Routing](docs/routing.md)
215
- - [Server Data Loaders](docs/server-data-loaders.md)
216
- - [Route Guards](docs/route-guards.md)
217
- - [Form Actions](docs/form-actions.md)
218
-
219
- ## Authentication and server APIs
220
-
221
- ```ts
222
- import {
223
- auth,
224
- requireAuth,
225
- requireRole,
226
- } from "bcp/auth";
227
-
228
- import {
229
- cookies,
230
- headers,
231
- requestId,
232
- requestMethod,
233
- requestUrl,
234
- } from "bcp/server";
235
- ```
236
-
237
- Guides:
238
-
239
- - [Authentication](docs/authentication.md)
240
- - [JWT Sessions](docs/session-auth.md)
241
- - [Server Request APIs](docs/server-request-apis.md)
242
-
243
- ## Database
244
-
245
- ```ts
246
- import {
247
- db,
248
- } from "bcp/database";
345
+ Browser
346
+
347
+ Security / middleware / cache
348
+
349
+ Route guard
350
+
351
+ Loader / action / API route
352
+
353
+ React SSR
354
+
355
+ Hydration / SPA navigation
249
356
  ```
250
357
 
251
- BCP's database layer includes lazy MySQL pool creation, query/execute helpers, transactions and migrations.
252
-
253
- Guides:
254
-
255
- - [Database](docs/database.md)
256
- - [Database Migrations](docs/database-migrations.md)
257
-
258
- ## Storage and uploads
259
-
260
- `create-bcp-app` can scaffold:
358
+ Typical route structure:
261
359
 
262
360
  ```text
263
- None
264
- Local Server
265
- Amazon S3
266
- Cloudflare R2
361
+ app/
362
+ ├─ layout.tsx
363
+ ├─ page.tsx
364
+ ├─ dashboard/
365
+ │ ├─ guard.ts
366
+ │ └─ users/
367
+ │ └─ [id]/
368
+ │ ├─ loader.ts
369
+ │ ├─ actions.ts
370
+ │ └─ page.tsx
371
+ └─ api/
372
+ └─ upload/
373
+ └─ route.ts
267
374
  ```
268
375
 
269
- BCP storage supports local and S3-compatible adapters, streaming reads/writes, ranges, object listing, copy/move, portable metadata, bulk deletion and S3 signed URLs.
270
-
271
- Guides:
272
-
273
- - [File Upload](docs/file-upload.md)
274
- - [Storage & File Delivery](docs/storage.md)
275
- - [Storage Ecosystem](docs/storage-ecosystem.md)
276
- - [S3-Compatible Storage](docs/s3-storage.md)
277
-
278
376
  ## Production build
279
377
 
280
- Build:
281
-
282
378
  ```bash
283
379
  npm run build
380
+ npm run start
284
381
  ```
285
382
 
286
- Output:
383
+ Standalone output:
287
384
 
288
385
  ```text
289
386
  .bcp-framework/build/
@@ -293,81 +390,37 @@ Output:
293
390
  └─ server.mjs
294
391
  ```
295
392
 
296
- Run:
297
-
298
- ```bash
299
- npm run start
300
- ```
301
-
302
- The `0.2.x` production target remains:
393
+ The current production target remains:
303
394
 
304
395
  ```text
305
396
  standalone-node
306
397
  ```
307
398
 
308
- Native `.exe`, desktop and mobile compilation are future roadmap work and are not part of the current platform contract.
399
+ Native `.exe`, desktop and mobile compilation remain later roadmap work.
309
400
 
310
- Production hardening supports configurable request/header/keep-alive/shutdown timeouts, trusted-proxy handling and `SIGTERM` / `SIGINT` graceful shutdown.
401
+ Production hardening includes configurable request/header/keep-alive/shutdown timeouts, trusted-proxy handling and graceful `SIGTERM` / `SIGINT` shutdown.
311
402
 
312
403
  Read more: [Production Hardening](docs/production-hardening.md)
313
404
 
314
- ## Documentation Platform — 0.2.1
405
+ ## Documentation Platform
315
406
 
316
- `0.2.1` makes the framework repository directly consumable by `bcp-docs-web`.
407
+ The framework repository is the documentation source of truth.
317
408
 
318
- Recommended website flow:
409
+ `bcp-docs-web` consumes:
319
410
 
320
411
  ```text
321
- selected framework ref
322
-
323
412
  docs/docs-web-manifest.json
324
413
  docs/platform-manifest.json
325
414
  docs/api-manifest.json
326
-
327
- validate version + release state + public entrypoints
328
-
329
- load referenced Markdown
330
-
331
- sync CMS/search/navigation
332
-
333
- render bcp-docs-web
334
415
  ```
335
416
 
336
- `bcp-docs-web` should not maintain a second hard-coded framework page list.
337
-
338
- The manifests provide:
339
-
340
- ```text
341
- sidebar/category order
342
- website routes
343
- Markdown sources
344
- version + release state
345
- release routes
346
- public package entrypoints
347
- API guide ownership
348
- ```
349
-
350
- The docs sync may target a release ref for historical content:
351
-
352
- ```powershell
353
- npm run docs:sync -- --ref=v0.2.0
354
- ```
417
+ The manifests provide navigation order, routes, Markdown sources, version/release state, public entrypoints and API guide ownership.
355
418
 
356
419
  Read more:
357
420
 
358
- - [Documentation Platform](docs/documentation-platform.md)
359
421
  - [Documentation Source Map](docs/README.md)
360
- - [Docs-Web Manifest](docs/docs-web-manifest.json)
361
- - [Platform Manifest](docs/platform-manifest.json)
362
- - [API Manifest](docs/api-manifest.json)
363
-
364
- ## Updating from 0.1.x / 0.2.x
365
-
366
- `0.2.1` does not intentionally remove application public entrypoints from the `0.2.0` baseline.
367
-
368
- After upgrading, always rebuild the standalone artifact instead of reusing `.bcp-framework/build` from another framework version.
369
-
370
- Read more: [Migrating to 0.2.x](docs/migration-0.2.md)
422
+ - [Documentation Platform](docs/documentation-platform.md)
423
+ - [Environment Validation](docs/environment-validation.md)
371
424
 
372
425
  ## Release validation
373
426
 
@@ -383,9 +436,9 @@ npm run test:e2e
383
436
  npm run rc:check
384
437
  ```
385
438
 
386
- `0.2.1` adds Documentation Platform unit/package checks that validate manifest version parity, docs source existence, API/public-entrypoint parity and prepared npm documentation artifacts.
439
+ `0.2.3` adds Database Platform v2 unit/package checks covering the adapter contract, MySQL/PostgreSQL/SQLite provider resolution, explicit connection lifecycle, failed-initialization retry behavior and provider-specific migration bookkeeping.
387
440
 
388
- Do not tag or publish a release until the final release commit passes the complete RC sequence.
441
+ Do not tag or publish until the final release commit passes the complete RC sequence.
389
442
 
390
443
  ## Release history
391
444
 
@@ -399,23 +452,14 @@ Do not tag or publish a release until the final release commit passes the comple
399
452
  | `0.1.29` | Developer Experience |
400
453
  | `0.2.0` | Framework Platform |
401
454
  | `0.2.1` | Documentation Platform |
455
+ | `0.2.2` | Configuration & Environment v2 |
456
+ | `0.2.3` | Database Platform v2 |
402
457
 
403
458
  ## Roadmap
404
459
 
405
- Next planned milestone:
406
-
407
- ```text
408
- 0.2.2 — Configuration & Environment v2
409
- ```
410
-
411
- Focus:
412
-
413
- - typed production configuration improvements,
414
- - environment validation,
415
- - startup configuration diagnostics,
416
- - configuration schema/inspection tooling.
460
+ `0.2.3 — Database Platform v2` completes the planned database adapter contract, PostgreSQL support, SQLite support, connection lifecycle improvements and migration consistency across the built-in SQL providers.
417
461
 
418
- Application packaging (`bcp package`, native executable experiments) remains later `0.2.x` roadmap work.
462
+ The next planned `0.2.x` focus is application packaging. Native `.exe`, desktop and mobile compilation remain later roadmap work.
419
463
 
420
464
  ## License
421
465