@chidchanun/bcp 0.2.19 → 0.3.1

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).
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` in `0.2.18+`.
47
-
48
- Related guides: [Configuration](configuration.md), [Environment Validation](environment-validation.md), [Deployment Platform v2](deployment-platform-v2.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).
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` in `0.2.18+`.
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,156 +172,280 @@ 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`.
176
+
177
+ ## `bcp/deployment`
178
+
179
+ Server-only Deployment Platform lifecycle APIs.
209
180
 
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.
181
+ ```text
182
+ createDeploymentRuntime
183
+ createDeploymentReadinessResponse
184
+ createDeploymentDiagnosticsResponse
185
+ ```
211
186
 
212
- Prepared npm packages expose compiled `observability.mjs`.
187
+ Important types include `DeploymentRuntime`, `DeploymentResource`, `DeploymentReadinessReport`, `DeploymentDiagnosticsReport`, `DeploymentMetadata`, `DeploymentSignalOptions` and `DeploymentShutdownOptions`.
213
188
 
214
- Related guides: [Observability Platform v2](observability.md), [Observability Platform v3](observability-v3.md).
189
+ Resources start in registration order and stop in reverse order. Startup failure rolls back already-started resources.
215
190
 
216
- ## `bcp/deployment`
191
+ Prepared packages expose compiled `deployment.mjs`.
217
192
 
218
- Server-only Deployment Platform v2 lifecycle APIs introduced in `0.2.18`.
193
+ ## `bcp/container`
219
194
 
220
- Primary functions:
195
+ Server-only Dependency Injection & Service Container APIs introduced in `0.3.1`.
221
196
 
222
- ```ts
223
- import {
224
- createDeploymentDiagnosticsResponse,
225
- createDeploymentReadinessResponse,
226
- createDeploymentRuntime,
227
- } from "bcp/deployment";
197
+ Primary exports:
198
+
199
+ ```text
200
+ createServiceToken
201
+ createServiceContainer
202
+ provideValue
203
+ provideFactory
204
+ provideClass
205
+ ServiceNotFoundError
206
+ ServiceResolutionError
207
+ ServiceDisposalError
228
208
  ```
229
209
 
230
- Important public types:
210
+ Important types:
231
211
 
232
212
  ```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
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
247
226
  ```
248
227
 
249
- Create a runtime:
228
+ Create typed tokens:
250
229
 
251
230
  ```ts
252
- const deployment =
253
- createDeploymentRuntime({
254
- serviceName: "orders-api",
255
- version: "1.0.0",
256
- });
231
+ import {
232
+ createServiceToken,
233
+ } from "bcp/container";
234
+
235
+ const configToken =
236
+ createServiceToken<{
237
+ apiUrl: string;
238
+ }>("config");
257
239
  ```
258
240
 
259
- Register resources:
241
+ Value provider:
260
242
 
261
243
  ```ts
262
- deployment.addResource({
263
- name: "database",
264
-
265
- async start() {
266
- await db.connect();
267
- },
244
+ const configProvider =
245
+ provideValue(
246
+ configToken,
247
+ {
248
+ apiUrl: "https://api.example.com",
249
+ }
250
+ );
251
+ ```
268
252
 
269
- ready() {
270
- return true;
271
- },
253
+ Typed factory dependencies:
272
254
 
273
- async stop() {
274
- await db.close();
275
- },
276
- });
255
+ ```ts
256
+ const repositoryProvider =
257
+ provideFactory(
258
+ repositoryToken,
259
+ [
260
+ configToken,
261
+ ] as const,
262
+ (_context, [config]) =>
263
+ createRepository(
264
+ config.apiUrl
265
+ )
266
+ );
277
267
  ```
278
268
 
279
- Resources start in registration order and stop in reverse order. If startup fails, previously started resources are rolled back in reverse order.
269
+ Class provider:
270
+
271
+ ```ts
272
+ provideClass(
273
+ serviceToken,
274
+ [
275
+ repositoryToken,
276
+ ] as const,
277
+ UserService
278
+ );
279
+ ```
280
280
 
281
- Runtime states:
281
+ Supported lifetimes:
282
282
 
283
283
  ```text
284
- idle
285
- starting
286
- ready
287
- draining
288
- stopped
289
- failed
284
+ singleton
285
+ scoped
286
+ transient
290
287
  ```
291
288
 
292
- Readiness:
289
+ The default is `singleton`.
290
+
291
+ Resolve services:
293
292
 
294
293
  ```ts
295
- const report =
296
- await deployment.readiness();
294
+ const container =
295
+ createServiceContainer({
296
+ providers: [
297
+ configProvider,
298
+ repositoryProvider,
299
+ ],
300
+ });
301
+
302
+ const repository =
303
+ await container.resolve(
304
+ repositoryToken
305
+ );
297
306
  ```
298
307
 
299
- or:
308
+ Optional dependencies:
300
309
 
301
310
  ```ts
302
- return createDeploymentReadinessResponse(
303
- deployment
304
- );
311
+ const value =
312
+ await container.optional(
313
+ optionalToken
314
+ );
305
315
  ```
306
316
 
307
- The response is `200` when the runtime and all resource checks are ready, otherwise `503`.
308
-
309
- Diagnostics:
317
+ Child/request scopes:
310
318
 
311
319
  ```ts
312
- const report =
313
- await deployment.diagnostics();
320
+ const requestScope =
321
+ container.createScope({
322
+ name: "request:123",
323
+ });
314
324
  ```
315
325
 
316
- or:
326
+ Testing overrides:
317
327
 
318
328
  ```ts
319
- return createDeploymentDiagnosticsResponse(
320
- deployment
321
- );
329
+ const testScope =
330
+ container.createScope({
331
+ name: "test",
332
+ overrides: [
333
+ provideValue(
334
+ mailerToken,
335
+ fakeMailer
336
+ ),
337
+ ],
338
+ });
322
339
  ```
323
340
 
324
- Metadata includes service/deployment identity, process ID, Node version, platform, architecture and startup time. Optional environment-backed identity fields use:
341
+ `graph()` exposes effective provider descriptions, lifetimes, dependencies and override state. Circular dependency paths throw `ServiceResolutionError`.
342
+
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`.
344
+
345
+ Prepared npm contract:
325
346
 
326
347
  ```text
327
- BCP_DEPLOYMENT_ID
328
- BCP_INSTANCE_ID
329
- BCP_RELEASE
330
- NODE_ENV
348
+ types -> packages/client/src/container.ts
349
+ default -> packages/client/src/container.mjs
350
+ browser -> packages/client/src/server-only.browser.mjs
331
351
  ```
332
352
 
333
- Install process signal handlers:
353
+ Related guide: [Dependency Injection & Service Container](service-container.md).
334
354
 
335
- ```ts
336
- const remove =
337
- deployment.installSignalHandlers();
355
+ ## `bcp/application`
356
+
357
+ Server-only Application Platform composition root.
358
+
359
+ Primary exports:
360
+
361
+ ```text
362
+ defineApp
363
+ createApp
364
+ ApplicationLifecycleError
365
+ ```
366
+
367
+ Important types:
368
+
369
+ ```text
370
+ Application
371
+ ApplicationState
372
+ ApplicationDefinition
373
+ ApplicationContext
374
+ ApplicationConfigSchema
375
+ ApplicationConfigParser
338
376
  ```
339
377
 
340
- Defaults are `SIGTERM` and `SIGINT`.
378
+ `0.3.1` application roots expose both the typed DI container and the legacy Plugin Platform service registry:
379
+
380
+ ```text
381
+ app.config
382
+ app.container
383
+ app.services
384
+ app.hooks
385
+ app.plugins
386
+ app.deployment
387
+ ```
341
388
 
342
- Integrate with the framework shutdown-hook registry:
389
+ Define DI providers with the application:
343
390
 
344
391
  ```ts
345
- const unregister =
346
- deployment.registerShutdownHook();
392
+ const app =
393
+ createApp({
394
+ name: "orders-api",
395
+ providers: [
396
+ configProvider,
397
+ repositoryProvider,
398
+ ],
399
+ });
347
400
  ```
348
401
 
349
- Prepared npm packages expose compiled `deployment.mjs`.
402
+ Resolve from lifecycle hooks:
350
403
 
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).
404
+ ```ts
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
+ });
418
+ ```
352
419
 
353
- ## `bcp/server`
420
+ Additional container integration:
354
421
 
355
- 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.
422
+ ```text
423
+ app.register(provider)
424
+ app.createScope(options)
425
+ ```
426
+
427
+ `register()` follows the application mutation rule and is allowed only before `start()`.
356
428
 
357
- Prepared npm packages resolve this runtime to compiled `server.mjs` in `0.2.18+`.
429
+ Application deployment order:
430
+
431
+ ```text
432
+ bcp:container
433
+ bcp:plugins
434
+ application resources
435
+ bcp:application
436
+ ```
437
+
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.
439
+
440
+ `readiness()` and `diagnostics()` delegate to Deployment Platform. `installSignalHandlers()` and `registerShutdownHook()` perform full application shutdown.
441
+
442
+ Prepared packages expose compiled `application.mjs` and block the entrypoint from browser/page graphs.
443
+
444
+ Related guides: [Application Platform](application-platform.md), [Service Container](service-container.md), [Migrating to 0.3.x](migration-0.3.md).
445
+
446
+ ## `bcp/server`
447
+
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`.
358
449
 
359
450
  ## `bcp/server-only`
360
451
 
@@ -366,13 +457,11 @@ import "bcp/server-only";
366
457
 
367
458
  ## `bcp/middleware`
368
459
 
369
- Middleware System v2 request/response pipeline types and helpers.
370
-
371
- Prepared npm packages resolve this runtime to compiled `middleware.mjs` in `0.2.18+`.
460
+ Middleware System v2 request/response pipeline types and helpers. Prepared packages expose compiled `middleware.mjs`.
372
461
 
373
462
  ## Prepared server runtime map
374
463
 
375
- For `0.2.18`, the prepared npm package uses compiled ESM runtime defaults for:
464
+ For `0.3.1`, prepared npm packages use compiled ESM runtime defaults for:
376
465
 
377
466
  ```text
378
467
  bcp/cache -> cache.mjs
@@ -387,14 +476,16 @@ bcp/testing -> testing.mjs
387
476
  bcp/plugins -> plugins.mjs
388
477
  bcp/observability -> observability.mjs
389
478
  bcp/deployment -> deployment.mjs
479
+ bcp/container -> container.mjs
480
+ bcp/application -> application.mjs
390
481
  bcp/server -> server.mjs
391
482
  bcp/middleware -> middleware.mjs
392
483
  ```
393
484
 
394
- Types remain sourced from the TypeScript public entrypoint files.
485
+ Types remain sourced from public TypeScript entrypoint files.
395
486
 
396
487
  ## Stability
397
488
 
398
- 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.
399
490
 
400
- Files under internal `packages/*` paths are 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.