@chidchanun/bcp 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.
@@ -1,8 +1,8 @@
1
1
  # API Reference
2
2
 
3
- BCP Framework exposes supported package entrypoints through the `bcp` package. Application code should import these public entrypoints instead of private implementation files under `packages/`.
3
+ BCP Framework exposes supported APIs through public `bcp/*` package entrypoints. Application code should not import private implementation files under `packages/`.
4
4
 
5
- The machine-readable source for this page is `docs/api-manifest.json`.
5
+ The machine-readable ownership source is `docs/api-manifest.json` and the reviewed package-resolution baseline is `docs/api-freeze-snapshot.json`.
6
6
 
7
7
  ## `bcp`
8
8
 
@@ -12,13 +12,11 @@ Common exports include `Form`, `Link`, `createIsland`, `navigate`, `notFound` an
12
12
 
13
13
  ## `bcp/island`
14
14
 
15
- Partial-hydration island APIs including `createIsland` and island loading strategy types.
15
+ Partial-hydration island creation and loading strategy APIs.
16
16
 
17
17
  ## `bcp/cache`
18
18
 
19
- Backward-compatible request/data caching plus Cache Platform v2 shared-store APIs.
20
-
21
- Important exports:
19
+ Request/data caching plus Cache Platform v2 adapters, locks, invalidation and metrics.
22
20
 
23
21
  ```text
24
22
  cache
@@ -35,47 +33,29 @@ createRedisCacheLockAdapter
35
33
  createCacheMetrics
36
34
  ```
37
35
 
38
- Public contracts include `CacheAdapter`, `CacheLockAdapter`, `CacheStore`, cache statistics/options and Redis command-client adapter types.
39
-
40
- Related guides: [Caching](caching.md), [Cache Platform v2](cache-platform-v2.md), [Application Platform](application-platform.md).
41
-
42
36
  ## `bcp/config`
43
37
 
44
- Typed BCP configuration, environment-schema validation and diagnostics APIs.
45
-
46
- Prepared npm packages resolve the production runtime to compiled `config.mjs`.
47
-
48
- Related guides: [Configuration](configuration.md), [Environment Validation](environment-validation.md), [Application Platform](application-platform.md).
38
+ Typed framework configuration, environment-schema validation and configuration diagnostics. Prepared packages expose compiled `config.mjs`.
49
39
 
50
40
  ## `bcp/validation`
51
41
 
52
- Typed validation primitives, parse helpers and `ValidationError`.
42
+ Typed validators, parse helpers and structured validation errors.
53
43
 
54
44
  ## `bcp/error`
55
45
 
56
- Structured HTTP error helpers and response classification.
46
+ Structured HTTP error creation, classification and response helpers.
57
47
 
58
48
  ## `bcp/database`
59
49
 
60
- Server-only provider-neutral SQL APIs for MySQL, PostgreSQL and SQLite.
61
-
62
- Core capabilities include query/execute, transactions, lifecycle and migrations.
63
-
64
- Related guides: [Database](database.md), [Database Migrations](database-migrations.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Application Platform](application-platform.md).
50
+ Server-only provider-neutral SQL APIs for MySQL, PostgreSQL and SQLite, including query/execute, transactions, lifecycle and migrations.
65
51
 
66
52
  ## `bcp/auth`
67
53
 
68
- Server-only Authentication Platform v2 and Authorization & Security v2 APIs.
69
-
70
- Capabilities include JWT-cookie sessions, optional server-side session stores, revocation, logout-all, idle timeout, role/permission guards, policies, same-origin protection and auth/guest guards.
71
-
72
- Prepared npm packages resolve the runtime to compiled `auth.mjs`.
54
+ Server-only authentication and authorization APIs including JWT cookie sessions, optional revocable session stores, role/permission guards, policies and auth/guest guards. Prepared packages expose compiled `auth.mjs`.
73
55
 
74
56
  ## `bcp/jobs`
75
57
 
76
- Server-only background jobs, scheduling and durable job APIs.
77
-
78
- Important exports:
58
+ Server-only background jobs, scheduling and durable queue APIs.
79
59
 
80
60
  ```text
81
61
  createJobQueue
@@ -88,26 +68,22 @@ nextCronTime
88
68
  nextScheduleTime
89
69
  ```
90
70
 
91
- Capabilities include delay, retry/backoff, worker concurrency, cancellation, visibility leases, heartbeat renewal, stale recovery, DLQ/requeue, retention cleanup, queue statistics and recurring interval/UTC cron schedules.
92
-
93
- Processing remains at-least-once; non-repeatable external side effects should use application-level idempotency.
71
+ Capabilities include delay, retry/backoff, concurrency, cancellation, visibility leases, heartbeat, stale recovery, DLQ/requeue, cleanup, statistics and recurring schedules.
94
72
 
95
73
  ## `bcp/workflow`
96
74
 
97
- Server-only Workflow Orchestration APIs.
75
+ Server-only persistent workflow orchestration.
98
76
 
99
77
  ```text
100
78
  createWorkflow
101
79
  createMemoryWorkflowStore
102
80
  ```
103
81
 
104
- Workflow controls include `start`, `run`, `get`, `list`, `resume`, `retry`, `cancel`, `compensate` and `close`.
105
-
106
- Capabilities include sequential/parallel steps, per-step retry, persisted delays, compensation, run leases and optional execution through `bcp/jobs`.
82
+ Supports sequential/parallel steps, retries, persisted delays, compensation, run leases and optional durable queue execution.
107
83
 
108
84
  ## `bcp/events`
109
85
 
110
- Server-only Transactional Outbox & Events APIs.
86
+ Server-only transactional outbox and event delivery APIs.
111
87
 
112
88
  ```text
113
89
  createTransactionalOutbox
@@ -118,11 +94,9 @@ createOutboxDispatcher
118
94
  createEventBus
119
95
  ```
120
96
 
121
- SQL outbox storage supports MySQL, PostgreSQL and SQLite. Dispatch supports batched claims, leases, stale recovery, retry/backoff, terminal failure, durable-job handoff and custom publishing.
122
-
123
97
  ## `bcp/realtime`
124
98
 
125
- Server-only realtime APIs for channels/rooms, broker delivery, presence, channel authorization, socket adapters, heartbeat and Server-Sent Events.
99
+ Server-only channels/rooms, broker delivery, presence, authorization, socket adapters, heartbeat and Server-Sent Events APIs.
126
100
 
127
101
  ```text
128
102
  createRealtime
@@ -131,11 +105,11 @@ createMemoryRealtimePresenceStore
131
105
  createRealtimeSseResponse
132
106
  ```
133
107
 
134
- BCP intentionally does not install a WebSocket server library. Applications adapt the selected provider through `RealtimeSocket`.
108
+ BCP does not require a WebSocket server library; applications adapt providers through `RealtimeSocket`.
135
109
 
136
110
  ## `bcp/testing`
137
111
 
138
- Server-only framework-native testing utilities. BCP does not require Jest or Vitest.
112
+ Server-only framework-native testing utilities without a Jest/Vitest requirement.
139
113
 
140
114
  Important APIs include:
141
115
 
@@ -171,24 +145,17 @@ createPluginServiceRegistry
171
145
  createPluginHookBus
172
146
  ```
173
147
 
174
- Capabilities include required/optional dependency ordering, setup/start/stop/dispose lifecycle, startup rollback, typed configuration parsing, shared services and awaited in-process hooks.
148
+ The Plugin Platform service registry remains supported for compatibility. For new typed application dependencies, prefer `bcp/container`.
175
149
 
176
150
  ## `bcp/observability`
177
151
 
178
- Server-only metrics, health and tracing APIs.
179
-
180
- Metrics/health APIs:
152
+ Server-only metrics, health and distributed tracing APIs.
181
153
 
182
154
  ```text
183
155
  createMetricsRegistry
184
156
  createMetricsResponse
185
157
  createRequestMetricsMiddleware
186
158
  createHealthRegistry
187
- ```
188
-
189
- Observability Platform v3 tracing APIs:
190
-
191
- ```text
192
159
  createTracer
193
160
  createRequestTracingMiddleware
194
161
  createTraceCarrier
@@ -205,154 +172,189 @@ createTraceMetricsExporter
205
172
  getTraceLogFields
206
173
  ```
207
174
 
208
- Important tracing contracts include `Tracer`, `TraceContext`, `TraceCarrier`, `TraceSpan`, `TraceSpanRecord`, `TraceSpanExporter`, `TraceSpanKind` and `TraceSpanStatus`.
175
+ Prepared packages expose compiled `observability.mjs`.
209
176
 
210
- Active trace context uses Node `AsyncLocalStorage`. W3C `traceparent`, optional `tracestate` and `x-correlation-id` can cross HTTP boundaries, while trace carriers can be stored in application-owned job/workflow/event/realtime payload metadata.
177
+ ## `bcp/deployment`
211
178
 
212
- Prepared npm packages expose compiled `observability.mjs`.
179
+ Server-only Deployment Platform lifecycle APIs.
213
180
 
214
- Related guides: [Observability Platform v2](observability.md), [Observability Platform v3](observability-v3.md), [Application Platform](application-platform.md).
181
+ ```text
182
+ createDeploymentRuntime
183
+ createDeploymentReadinessResponse
184
+ createDeploymentDiagnosticsResponse
185
+ ```
215
186
 
216
- ## `bcp/deployment`
187
+ Important types include `DeploymentRuntime`, `DeploymentResource`, `DeploymentReadinessReport`, `DeploymentDiagnosticsReport`, `DeploymentMetadata`, `DeploymentSignalOptions` and `DeploymentShutdownOptions`.
217
188
 
218
- Server-only Deployment Platform v2 lifecycle APIs.
189
+ Resources start in registration order and stop in reverse order. Startup failure rolls back already-started resources.
219
190
 
220
- Primary functions:
191
+ Prepared packages expose compiled `deployment.mjs`.
221
192
 
222
- ```ts
223
- import {
224
- createDeploymentDiagnosticsResponse,
225
- createDeploymentReadinessResponse,
226
- createDeploymentRuntime,
227
- } from "bcp/deployment";
228
- ```
193
+ ## `bcp/container`
194
+
195
+ Server-only Dependency Injection & Service Container APIs introduced in `0.3.1`.
229
196
 
230
- Important public types:
197
+ Primary exports:
231
198
 
232
199
  ```text
233
- DeploymentRuntime
234
- DeploymentRuntimeOptions
235
- DeploymentRuntimeState
236
- DeploymentResource
237
- DeploymentResourceContext
238
- DeploymentResourceStatus
239
- DeploymentReadinessResult
240
- DeploymentReadinessReport
241
- DeploymentReadinessItem
242
- DeploymentDiagnosticsReport
243
- DeploymentDiagnosticsResource
244
- DeploymentMetadata
245
- DeploymentSignalOptions
246
- DeploymentShutdownOptions
200
+ createServiceToken
201
+ createServiceContainer
202
+ provideValue
203
+ provideFactory
204
+ provideClass
205
+ ServiceNotFoundError
206
+ ServiceResolutionError
207
+ ServiceDisposalError
247
208
  ```
248
209
 
249
- Create a runtime:
210
+ Important types:
250
211
 
251
- ```ts
252
- const deployment =
253
- createDeploymentRuntime({
254
- serviceName: "orders-api",
255
- version: "1.0.0",
256
- });
212
+ ```text
213
+ ServiceToken<T>
214
+ ServiceTokenValue<TToken>
215
+ ServiceDependencyValues<TDependencies>
216
+ ServiceProvider<T>
217
+ ServiceProviderOptions<T>
218
+ ServiceFactoryContext
219
+ ServiceLifetime
220
+ ServiceContainer
221
+ ServiceContainerOptions
222
+ ServiceScope
223
+ ServiceScopeOptions
224
+ ServiceScopeState
225
+ ServiceGraphNode
257
226
  ```
258
227
 
259
- Register resources:
228
+ Create typed tokens:
260
229
 
261
230
  ```ts
262
- deployment.addResource({
263
- name: "database",
264
-
265
- async start() {
266
- await db.connect();
267
- },
268
-
269
- ready() {
270
- return true;
271
- },
231
+ import {
232
+ createServiceToken,
233
+ } from "bcp/container";
272
234
 
273
- async stop() {
274
- await db.close();
275
- },
276
- });
235
+ const configToken =
236
+ createServiceToken<{
237
+ apiUrl: string;
238
+ }>("config");
277
239
  ```
278
240
 
279
- Resources start in registration order and stop in reverse order. If startup fails, previously started resources are rolled back in reverse order.
241
+ Value provider:
280
242
 
281
- Runtime states:
282
-
283
- ```text
284
- idle
285
- starting
286
- ready
287
- draining
288
- stopped
289
- failed
243
+ ```ts
244
+ const configProvider =
245
+ provideValue(
246
+ configToken,
247
+ {
248
+ apiUrl: "https://api.example.com",
249
+ }
250
+ );
290
251
  ```
291
252
 
292
- Readiness:
253
+ Typed factory dependencies:
293
254
 
294
255
  ```ts
295
- const report =
296
- await deployment.readiness();
256
+ const repositoryProvider =
257
+ provideFactory(
258
+ repositoryToken,
259
+ [
260
+ configToken,
261
+ ] as const,
262
+ (_context, [config]) =>
263
+ createRepository(
264
+ config.apiUrl
265
+ )
266
+ );
297
267
  ```
298
268
 
299
- or:
269
+ Class provider:
300
270
 
301
271
  ```ts
302
- return createDeploymentReadinessResponse(
303
- deployment
272
+ provideClass(
273
+ serviceToken,
274
+ [
275
+ repositoryToken,
276
+ ] as const,
277
+ UserService
304
278
  );
305
279
  ```
306
280
 
307
- The response is `200` when the runtime and all resource checks are ready, otherwise `503`.
281
+ Supported lifetimes:
308
282
 
309
- Diagnostics:
283
+ ```text
284
+ singleton
285
+ scoped
286
+ transient
287
+ ```
288
+
289
+ The default is `singleton`.
290
+
291
+ Resolve services:
310
292
 
311
293
  ```ts
312
- const report =
313
- await deployment.diagnostics();
294
+ const container =
295
+ createServiceContainer({
296
+ providers: [
297
+ configProvider,
298
+ repositoryProvider,
299
+ ],
300
+ });
301
+
302
+ const repository =
303
+ await container.resolve(
304
+ repositoryToken
305
+ );
314
306
  ```
315
307
 
316
- or:
308
+ Optional dependencies:
317
309
 
318
310
  ```ts
319
- return createDeploymentDiagnosticsResponse(
320
- deployment
321
- );
311
+ const value =
312
+ await container.optional(
313
+ optionalToken
314
+ );
322
315
  ```
323
316
 
324
- Metadata includes service/deployment identity, process ID, Node version, platform, architecture and startup time. Optional environment-backed identity fields use:
317
+ Child/request scopes:
325
318
 
326
- ```text
327
- BCP_DEPLOYMENT_ID
328
- BCP_INSTANCE_ID
329
- BCP_RELEASE
330
- NODE_ENV
319
+ ```ts
320
+ const requestScope =
321
+ container.createScope({
322
+ name: "request:123",
323
+ });
331
324
  ```
332
325
 
333
- Install process signal handlers:
326
+ Testing overrides:
334
327
 
335
328
  ```ts
336
- const remove =
337
- deployment.installSignalHandlers();
329
+ const testScope =
330
+ container.createScope({
331
+ name: "test",
332
+ overrides: [
333
+ provideValue(
334
+ mailerToken,
335
+ fakeMailer
336
+ ),
337
+ ],
338
+ });
338
339
  ```
339
340
 
340
- Defaults are `SIGTERM` and `SIGINT`.
341
+ `graph()` exposes effective provider descriptions, lifetimes, dependencies and override state. Circular dependency paths throw `ServiceResolutionError`.
341
342
 
342
- Integrate with the framework shutdown-hook registry:
343
+ Providers may define `dispose(value)`. The container disposes children first and resolved services in reverse creation order. Multiple disposal failures are collected in `ServiceDisposalError`.
343
344
 
344
- ```ts
345
- const unregister =
346
- deployment.registerShutdownHook();
347
- ```
345
+ Prepared npm contract:
348
346
 
349
- Prepared npm packages expose compiled `deployment.mjs`.
347
+ ```text
348
+ types -> packages/client/src/container.ts
349
+ default -> packages/client/src/container.mjs
350
+ browser -> packages/client/src/server-only.browser.mjs
351
+ ```
350
352
 
351
- Related guides: [Deployment Platform v2](deployment-platform-v2.md), [Application Packaging](application-packaging.md), [Production Hardening](production-hardening.md), [Observability Platform v3](observability-v3.md), [Application Platform](application-platform.md).
353
+ Related guide: [Dependency Injection & Service Container](service-container.md).
352
354
 
353
355
  ## `bcp/application`
354
356
 
355
- Server-only BCP Application Platform composition APIs introduced in `0.3.0`.
357
+ Server-only Application Platform composition root.
356
358
 
357
359
  Primary exports:
358
360
 
@@ -362,7 +364,7 @@ createApp
362
364
  ApplicationLifecycleError
363
365
  ```
364
366
 
365
- Important public types:
367
+ Important types:
366
368
 
367
369
  ```text
368
370
  Application
@@ -373,80 +375,77 @@ ApplicationConfigSchema
373
375
  ApplicationConfigParser
374
376
  ```
375
377
 
376
- Create an application:
377
-
378
- ```ts
379
- import {
380
- createApp,
381
- } from "bcp/application";
382
-
383
- const app =
384
- createApp({
385
- name: "orders-api",
386
- version: "1.0.0",
387
- });
388
- ```
389
-
390
- The application exposes the existing Plugin and Deployment platform objects:
378
+ `0.3.1` application roots expose both the typed DI container and the legacy Plugin Platform service registry:
391
379
 
392
380
  ```text
381
+ app.config
382
+ app.container
393
383
  app.services
394
384
  app.hooks
395
385
  app.plugins
396
386
  app.deployment
397
387
  ```
398
388
 
399
- Register a shared service before startup:
389
+ Define DI providers with the application:
400
390
 
401
391
  ```ts
402
- app.provide(
403
- "database",
404
- database
405
- );
392
+ const app =
393
+ createApp({
394
+ name: "orders-api",
395
+ providers: [
396
+ configProvider,
397
+ repositoryProvider,
398
+ ],
399
+ });
406
400
  ```
407
401
 
408
- Register an infrastructure resource:
402
+ Resolve from lifecycle hooks:
409
403
 
410
404
  ```ts
411
- app.addResource({
412
- name: "database",
413
- start: () => database.connect(),
414
- ready: () => database.ready,
415
- stop: () => database.close(),
416
- });
405
+ const app =
406
+ createApp({
407
+ name: "orders-api",
408
+ providers: [
409
+ repositoryProvider,
410
+ ],
411
+ async setup(context) {
412
+ const repository =
413
+ await context.container.resolve(
414
+ repositoryToken
415
+ );
416
+ },
417
+ });
417
418
  ```
418
419
 
419
- Application lifecycle order:
420
+ Additional container integration:
420
421
 
421
422
  ```text
422
- application.setup
423
- plugins start
424
- resources start
425
- application.start
423
+ app.register(provider)
424
+ app.createScope(options)
426
425
  ```
427
426
 
428
- Shutdown runs the inverse dependency order:
427
+ `register()` follows the application mutation rule and is allowed only before `start()`.
428
+
429
+ Application deployment order:
429
430
 
430
431
  ```text
431
- application.stop
432
- resources stop in reverse order
433
- plugins stop/dispose
434
- application.dispose
432
+ bcp:container
433
+ bcp:plugins
434
+ application resources
435
+ bcp:application
435
436
  ```
436
437
 
437
- `readiness()` and `diagnostics()` delegate to the integrated Deployment Platform. `installSignalHandlers()` and `registerShutdownHook()` expose the same graceful-shutdown capabilities through the application root.
438
+ Shutdown reverses this order. The container remains active while application resources/plugins stop, then disposes injected services before `application.dispose()` finishes the application lifecycle.
438
439
 
439
- The runtime is terminal after `stop()`/`shutdown()`/`close()` and rejects service/plugin/resource registration after startup begins.
440
+ `readiness()` and `diagnostics()` delegate to Deployment Platform. `installSignalHandlers()` and `registerShutdownHook()` perform full application shutdown.
440
441
 
441
- Prepared npm packages expose compiled `application.mjs`, and the entrypoint is blocked from browser/page dependency graphs.
442
+ Prepared packages expose compiled `application.mjs` and block the entrypoint from browser/page graphs.
442
443
 
443
- Related guides: [Application Platform](application-platform.md), [Migrating to 0.3.0](migration-0.3.md), [Plugin & Module Platform](plugin-module-platform.md), [Deployment Platform v2](deployment-platform-v2.md).
444
+ Related guides: [Application Platform](application-platform.md), [Service Container](service-container.md), [Migrating to 0.3.x](migration-0.3.md).
444
445
 
445
446
  ## `bcp/server`
446
447
 
447
- Server request/runtime APIs including request context, cookies, CSRF/same-origin protection, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
448
-
449
- Prepared npm packages resolve this runtime to compiled `server.mjs`.
448
+ Server request/runtime APIs including request context, cookies, CSRF/same-origin protection, logging, graceful shutdown hooks, uploads, storage, response helpers and low-level session primitives. Prepared packages expose compiled `server.mjs`.
450
449
 
451
450
  ## `bcp/server-only`
452
451
 
@@ -458,13 +457,11 @@ import "bcp/server-only";
458
457
 
459
458
  ## `bcp/middleware`
460
459
 
461
- Middleware System v2 request/response pipeline types and helpers.
462
-
463
- Prepared npm packages resolve this runtime to compiled `middleware.mjs`.
460
+ Middleware System v2 request/response pipeline types and helpers. Prepared packages expose compiled `middleware.mjs`.
464
461
 
465
462
  ## Prepared server runtime map
466
463
 
467
- For `0.3.0`, the prepared npm package uses compiled ESM runtime defaults for:
464
+ For `0.3.1`, prepared npm packages use compiled ESM runtime defaults for:
468
465
 
469
466
  ```text
470
467
  bcp/cache -> cache.mjs
@@ -479,15 +476,16 @@ bcp/testing -> testing.mjs
479
476
  bcp/plugins -> plugins.mjs
480
477
  bcp/observability -> observability.mjs
481
478
  bcp/deployment -> deployment.mjs
479
+ bcp/container -> container.mjs
482
480
  bcp/application -> application.mjs
483
481
  bcp/server -> server.mjs
484
482
  bcp/middleware -> middleware.mjs
485
483
  ```
486
484
 
487
- Types remain sourced from the TypeScript public entrypoint files.
485
+ Types remain sourced from public TypeScript entrypoint files.
488
486
 
489
487
  ## Stability
490
488
 
491
- Only entrypoints listed in both `docs/platform-manifest.json` and `docs/api-manifest.json` are part of the documented platform surface.
489
+ Only entrypoints listed in both `docs/platform-manifest.json` and `docs/api-manifest.json` are supported public platform modules.
492
490
 
493
- The reviewed `docs/api-freeze-snapshot.json` records the current package/CLI/API baseline. Files under internal `packages/*` paths remain implementation details unless re-exported through a documented public package entrypoint.
491
+ `docs/api-freeze-snapshot.json` records the current reviewed package/CLI/API baseline. Internal `packages/*` files remain implementation details unless exposed through a documented public entrypoint.