create-bcp-app 0.3.0 → 0.3.2

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
@@ -10,7 +10,7 @@ npm run dev
10
10
 
11
11
  ## Project-local BCP CLI
12
12
 
13
- Generated npm scripts use the project-local framework CLI:
13
+ Generated npm scripts use the local framework CLI:
14
14
 
15
15
  ```json
16
16
  {
@@ -64,17 +64,17 @@ Select storage provider:
64
64
 
65
65
  New projects include `bcp.project.json`.
66
66
 
67
- Example for the `0.3.0` target:
67
+ Example for the `0.3.1` target:
68
68
 
69
69
  ```json
70
70
  {
71
71
  "schemaVersion": 1,
72
72
  "framework": "bcp",
73
73
  "projectName": "my-app",
74
- "frameworkPackage": "npm:@chidchanun/bcp@0.3.0",
74
+ "frameworkPackage": "npm:@chidchanun/bcp@0.3.1",
75
75
  "createdWith": {
76
76
  "package": "create-bcp-app",
77
- "version": "0.3.0"
77
+ "version": "0.3.1"
78
78
  },
79
79
  "packageManager": "npm",
80
80
  "presets": {
@@ -88,9 +88,9 @@ Example for the `0.3.0` target:
88
88
 
89
89
  This manifest records scaffold identity only. Do not place secrets in it.
90
90
 
91
- ## BCP Application Platform — 0.3.0+
91
+ ## Application Platform
92
92
 
93
- Applications can optionally centralize server infrastructure through `bcp/application`:
93
+ Applications can centralize server infrastructure through `bcp/application`:
94
94
 
95
95
  ```ts
96
96
  import {
@@ -103,21 +103,99 @@ export const app =
103
103
  });
104
104
  ```
105
105
 
106
- Register existing provider-native services:
106
+ Existing BCP subsystem APIs remain independently usable.
107
+
108
+ ## Dependency Injection & Service Container — 0.3.1+
109
+
110
+ Typed dependencies use `bcp/container`:
111
+
112
+ ```ts
113
+ import {
114
+ createServiceToken,
115
+ provideFactory,
116
+ provideValue,
117
+ } from "bcp/container";
118
+
119
+ const configToken =
120
+ createServiceToken<{
121
+ apiUrl: string;
122
+ }>("config");
123
+
124
+ const repositoryToken =
125
+ createServiceToken<UserRepository>(
126
+ "user-repository"
127
+ );
128
+
129
+ export const app =
130
+ createApp({
131
+ name: "my-app",
132
+ providers: [
133
+ provideValue(
134
+ configToken,
135
+ {
136
+ apiUrl: "https://api.example.com",
137
+ }
138
+ ),
139
+ provideFactory(
140
+ repositoryToken,
141
+ [
142
+ configToken,
143
+ ] as const,
144
+ (_context, [config]) =>
145
+ createRepository(
146
+ config.apiUrl
147
+ )
148
+ ),
149
+ ],
150
+ });
151
+ ```
152
+
153
+ Resolve from server/application code:
154
+
155
+ ```ts
156
+ const repository =
157
+ await app.container.resolve(
158
+ repositoryToken
159
+ );
160
+ ```
161
+
162
+ Supported lifetimes:
163
+
164
+ ```text
165
+ singleton
166
+ scoped
167
+ transient
168
+ ```
169
+
170
+ For request/job/test boundaries:
107
171
 
108
172
  ```ts
109
- app.provide(
110
- "database",
111
- database
112
- );
113
-
114
- app.provide(
115
- "cache",
116
- cache
117
- );
173
+ const scope =
174
+ app.createScope({
175
+ name: "request:123",
176
+ });
118
177
  ```
119
178
 
120
- Register long-running lifecycle resources:
179
+ Testing overrides:
180
+
181
+ ```ts
182
+ const testScope =
183
+ app.createScope({
184
+ name: "test",
185
+ overrides: [
186
+ provideValue(
187
+ mailerToken,
188
+ fakeMailer
189
+ ),
190
+ ],
191
+ });
192
+ ```
193
+
194
+ DI is optional. Existing `app.services` and plugin service registries remain supported.
195
+
196
+ ## Lifecycle resources
197
+
198
+ Long-running infrastructure still uses Deployment Platform resources:
121
199
 
122
200
  ```ts
123
201
  app.addResource({
@@ -137,14 +215,10 @@ app.addResource({
137
215
  });
138
216
  ```
139
217
 
140
- Application startup orders plugins before infrastructure resources and the application start hook. Shutdown reverses dependency order.
141
-
142
- Existing `bcp/database`, `bcp/jobs`, `bcp/workflow`, `bcp/events`, `bcp/realtime`, `bcp/cache`, `bcp/plugins`, `bcp/observability` and `bcp/deployment` APIs remain usable independently.
218
+ In `0.3.1`, the DI container remains active until application resources and plugins have stopped, then disposes injected services in reverse creation order.
143
219
 
144
220
  ## Database presets
145
221
 
146
- Database choices add starter configuration and the matching driver:
147
-
148
222
  - MySQL: `mysql2`
149
223
  - PostgreSQL: `pg`
150
224
  - SQLite: `better-sqlite3`
@@ -157,72 +231,21 @@ For MySQL, PostgreSQL and SQLite, generated `lib/database.ts` exposes BCP databa
157
231
 
158
232
  The JWT Cookie preset creates starter authentication code. BCP supports revocable session stores, permission/policy authorization, route guards and same-origin/CSRF helpers.
159
233
 
160
- ## Background jobs, workflows and events
161
-
162
- ```ts
163
- import {
164
- createJobQueue,
165
- createJobScheduler,
166
- } from "bcp/jobs";
167
- import {
168
- createWorkflow,
169
- } from "bcp/workflow";
170
- ```
171
-
172
- Durable Redis-compatible queues/schedules, workflow orchestration and transactional outbox/event delivery are available without forcing a Redis client dependency.
234
+ ## Jobs, workflows, events and realtime
173
235
 
174
- ## Realtime
175
-
176
- ```ts
177
- import {
178
- createRealtime,
179
- } from "bcp/realtime";
180
-
181
- export const realtime =
182
- createRealtime();
183
- ```
184
-
185
- BCP does not install a WebSocket server library. Applications adapt their provider to `RealtimeSocket`; SSE is built in.
236
+ Use `bcp/jobs`, `bcp/workflow`, `bcp/events` and `bcp/realtime` directly or register selected instances with the Application Platform/DI container.
186
237
 
187
238
  ## Testing
188
239
 
189
- `bcp/testing` provides request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime test harnesses and does not require Jest or Vitest.
240
+ `bcp/testing` provides framework-native request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime helpers. DI scope overrides complement these helpers for application-level dependency replacement.
190
241
 
191
242
  ## Plugins
192
243
 
193
- `bcp/plugins` provides dependency ordering, module composition, lifecycle hooks, config parsing, shared services and async hooks. Plugin definitions/modules can be passed directly to `createApp()`.
194
-
195
- ## Cache Platform v2
244
+ `bcp/plugins` remains available for reusable plugin/module lifecycle composition. Plugin definitions/modules can be passed to `createApp()`.
196
245
 
197
- ```ts
198
- import {
199
- createCacheStore,
200
- } from "bcp/cache";
201
-
202
- export const cache =
203
- createCacheStore();
204
- ```
246
+ ## Observability and deployment
205
247
 
206
- Multi-instance applications can use Redis-compatible cache and lock adapters for distributed cache-fill coordination.
207
-
208
- ## Observability Platform v3
209
-
210
- ```ts
211
- import {
212
- createTracer,
213
- } from "bcp/observability";
214
-
215
- export const tracer =
216
- createTracer({
217
- serviceName: "my-app",
218
- });
219
- ```
220
-
221
- Tracing supports W3C `traceparent`, correlation IDs, request middleware, explicit carriers and provider-neutral exporters.
222
-
223
- ## Deployment Platform v2
224
-
225
- `bcp/deployment` remains available for applications that want to own resource lifecycle directly. `bcp/application` reuses the same resource/readiness/diagnostics model when using the Application Platform.
248
+ `bcp/observability` provides metrics/tracing. `bcp/deployment` remains available when an application wants to own resource lifecycle directly; `bcp/application` reuses its readiness/diagnostics/shutdown model.
226
249
 
227
250
  ## Application packaging
228
251
 
@@ -231,9 +254,7 @@ npm run build
231
254
  npm run package
232
255
  ```
233
256
 
234
- The deployment package excludes application `devDependencies` and project `.env` values. Supply secrets through the deployment environment.
235
-
236
- BCP `0.3.0` prepared framework packages add compiled `application.mjs` to the compiled ESM server-runtime set.
257
+ BCP `0.3.1` prepared packages include compiled `container.mjs` and `application.mjs` server runtimes. Project `.env` files and application devDependencies are excluded from deployment packages.
237
258
 
238
259
  ## Project generators
239
260
 
@@ -261,5 +282,5 @@ npm run generate -- migration create_users
261
282
  For prerelease/local package verification:
262
283
 
263
284
  ```bash
264
- npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.3.0.tgz
285
+ npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.3.1.tgz
265
286
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bcp-app",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Create a new BCP Framework application.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@ npm run update
27
27
 
28
28
  Generated projects include `bcp.project.json` with non-secret scaffold metadata. Commit it with the project, but never put passwords, tokens or access keys in it.
29
29
 
30
- ## Application Platform — BCP 0.3.0+
30
+ ## Application Platform — BCP 0.3.x
31
31
 
32
32
  For applications with several server subsystems, `bcp/application` provides one optional composition root:
33
33
 
@@ -42,14 +42,84 @@ export const app =
42
42
  });
43
43
  ```
44
44
 
45
- Register shared service instances before startup:
45
+ ## Dependency Injection BCP 0.3.1+
46
+
47
+ Use `bcp/container` for typed application dependencies:
48
+
49
+ ```ts
50
+ import {
51
+ createServiceToken,
52
+ provideFactory,
53
+ provideValue,
54
+ } from "bcp/container";
55
+
56
+ const configToken =
57
+ createServiceToken<{
58
+ apiUrl: string;
59
+ }>("config");
60
+
61
+ const clientToken =
62
+ createServiceToken<ApiClient>(
63
+ "api-client"
64
+ );
65
+
66
+ export const app =
67
+ createApp({
68
+ name: "bcp-app",
69
+ providers: [
70
+ provideValue(
71
+ configToken,
72
+ {
73
+ apiUrl: "https://api.example.com",
74
+ }
75
+ ),
76
+ provideFactory(
77
+ clientToken,
78
+ [
79
+ configToken,
80
+ ] as const,
81
+ (_context, [config]) =>
82
+ createApiClient(
83
+ config.apiUrl
84
+ )
85
+ ),
86
+ ],
87
+ });
88
+ ```
89
+
90
+ Resolve typed services:
91
+
92
+ ```ts
93
+ const client =
94
+ await app.container.resolve(
95
+ clientToken
96
+ );
97
+ ```
98
+
99
+ Provider lifetimes are `singleton`, `scoped` and `transient`.
100
+
101
+ For request/job/test scopes:
102
+
103
+ ```ts
104
+ const scope =
105
+ app.createScope({
106
+ name: "request:123",
107
+ });
108
+ ```
109
+
110
+ Testing overrides can replace selected providers within a child scope without changing the root application container.
111
+
112
+ The legacy Plugin Platform registry remains supported:
46
113
 
47
114
  ```ts
48
115
  app.provide("database", database);
49
- app.provide("cache", cache);
50
116
  ```
51
117
 
52
- Register lifecycle-owned resources:
118
+ Use typed `ServiceToken<T>` providers for new application dependency injection code.
119
+
120
+ ## Lifecycle resources
121
+
122
+ Long-running infrastructure uses `app.addResource()`:
53
123
 
54
124
  ```ts
55
125
  app.addResource({
@@ -69,13 +139,13 @@ app.addResource({
69
139
  });
70
140
  ```
71
141
 
72
- Then start the application runtime from your server/bootstrap composition code:
142
+ Then start the application runtime from server/bootstrap code:
73
143
 
74
144
  ```ts
75
145
  await app.start();
76
146
  ```
77
147
 
78
- Existing plugin modules can be passed directly to `createApp()`. Existing subsystem APIs remain available independently when a centralized application runtime is unnecessary.
148
+ BCP `0.3.1` keeps the DI container alive until application resources/plugins have stopped, then disposes resolved services in reverse creation order.
79
149
 
80
150
  ## Authentication and authorization
81
151
 
@@ -83,25 +153,11 @@ JWT Cookie projects can use `createAuth()` and optional `AuthSessionStore` revoc
83
153
 
84
154
  ## Database
85
155
 
86
- MySQL, PostgreSQL and SQLite projects expose the BCP database platform through `bcp/database`.
87
-
88
- ## Jobs, scheduling and workflows
89
-
90
- ```ts
91
- import {
92
- createJobQueue,
93
- createJobScheduler,
94
- } from "bcp/jobs";
95
- import {
96
- createWorkflow,
97
- } from "bcp/workflow";
98
- ```
99
-
100
- Durable jobs support leases, heartbeat, stale recovery and DLQ. Workflows support sequential/parallel steps, retries, persisted delays and compensation.
156
+ MySQL, PostgreSQL and SQLite projects expose database primitives through `bcp/database`.
101
157
 
102
- ## Transactional events
158
+ ## Jobs, workflows and events
103
159
 
104
- Use `bcp/events` when business data and an integration event must commit in the same SQL transaction. The outbox dispatcher can deliver through durable jobs or an application publisher after commit.
160
+ Use `bcp/jobs`, `bcp/workflow` and `bcp/events` independently or compose instances through the Application Platform.
105
161
 
106
162
  ## Realtime
107
163
 
@@ -118,58 +174,35 @@ BCP does not install a WebSocket server library. Adapt the selected provider thr
118
174
 
119
175
  ## Testing
120
176
 
121
- `bcp/testing` provides request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime/SSE test helpers without requiring Jest or Vitest.
177
+ `bcp/testing` provides framework-native server test helpers. `bcp/container` child-scope overrides can replace application dependencies during tests.
122
178
 
123
179
  ## Plugins
124
180
 
125
- `bcp/plugins` provides reusable server-side plugins/modules, dependency ordering, lifecycle hooks, config parsing, shared services and awaited hooks. Plugin definitions/modules can also be composed by `bcp/application`.
126
-
127
- ## Cache Platform v2
181
+ `bcp/plugins` provides reusable server-side plugins/modules, dependency ordering, lifecycle hooks, config parsing, shared services and awaited hooks.
128
182
 
129
- ```ts
130
- import {
131
- createCacheStore,
132
- } from "bcp/cache";
133
-
134
- export const cache =
135
- createCacheStore();
136
- ```
137
-
138
- Use Redis-compatible cache/lock adapters for multi-instance cache-fill coordination when needed.
139
-
140
- ## Observability Platform v3
141
-
142
- ```ts
143
- import {
144
- createTracer,
145
- } from "bcp/observability";
146
-
147
- export const tracer =
148
- createTracer({
149
- serviceName: "bcp-app",
150
- });
151
- ```
183
+ ## Cache and observability
152
184
 
153
- Tracing supports AsyncLocalStorage context, W3C `traceparent`, correlation IDs, request tracing, trace carriers and provider-neutral exporters.
185
+ `bcp/cache` provides provider-neutral cache/lock primitives. `bcp/observability` provides metrics, health and tracing.
154
186
 
155
187
  ## Deployment lifecycle
156
188
 
157
- `bcp/deployment` remains available when the project wants direct lifecycle ownership. `bcp/application` reuses the same resource/readiness/diagnostics model and adds application/plugin composition around it.
189
+ `bcp/deployment` remains available for direct lifecycle ownership. `bcp/application` composes the same readiness/diagnostics/shutdown model.
158
190
 
159
- Application Platform startup order is:
191
+ Application startup order in `0.3.1` is:
160
192
 
161
193
  ```text
162
194
  application setup
195
+ container
163
196
  plugins
164
197
  resources
165
198
  application start
166
199
  ```
167
200
 
168
- Shutdown reverses resource dependencies before disposing the application.
201
+ Shutdown reverses deployment dependencies, then runs application disposal.
169
202
 
170
203
  ## API baseline
171
204
 
172
- BCP `0.3.0` preserves the public `0.2.19` entrypoints and adds `bcp/application`. Application code should import documented public `bcp/*` entrypoints and avoid private framework `packages/*` paths.
205
+ BCP `0.3.1` advances `0.3.0` additively with `bcp/container`. Application code should use documented public `bcp/*` entrypoints and avoid private framework `packages/*` paths.
173
206
 
174
207
  ## Production build
175
208
 
@@ -184,9 +217,9 @@ npm start
184
217
  npm run package
185
218
  ```
186
219
 
187
- BCP excludes project `.env` files and application `devDependencies` from the deployment package. Supply secrets through the deployment environment.
220
+ BCP excludes project `.env` files and application `devDependencies` from deployment packages. Supply secrets through the deployment environment.
188
221
 
189
- BCP 0.3.0 adds compiled `application.mjs` to the main compiled server-runtime entrypoints.
222
+ Prepared `0.3.1` packages include compiled `container.mjs` and `application.mjs` runtimes.
190
223
 
191
224
  ## Direct CLI usage
192
225