@chidchanun/bcp 0.2.12 → 0.2.14

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.
@@ -10,7 +10,7 @@ Universal React application APIs.
10
10
 
11
11
  Common exports include `Form`, `Link`, `createIsland`, `navigate`, `notFound`, loader/action/guard hooks and router/navigation APIs.
12
12
 
13
- Related guides: [Routing](routing.md), [Server Data Loaders](server-data-loaders.md), [Route Guards](route-guards.md), [Form Actions](form-actions.md).
13
+ Related guides: [Routing](routing.md), [Server Data Loaders](server-data-loaders.md), [Route Guards](route-guards.md), [Form Actions](form-actions.md), [Testing Platform](testing-platform.md).
14
14
 
15
15
  ## `bcp/island`
16
16
 
@@ -54,7 +54,7 @@ Server-only Database Platform v2 APIs.
54
54
 
55
55
  Built-in SQL providers are MySQL, PostgreSQL and SQLite. `BcpDatabase` instances expose lazy query/execute/transaction operations plus explicit `connect()`, `disconnect()` and backward-compatible `close()` lifecycle methods.
56
56
 
57
- Related guides: [Database](database.md), [Database Migrations](database-migrations.md), [Transactional Outbox & Events](transactional-outbox-events.md).
57
+ Related guides: [Database](database.md), [Database Migrations](database-migrations.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Testing Platform](testing-platform.md).
58
58
 
59
59
  ## `bcp/auth`
60
60
 
@@ -62,7 +62,7 @@ Server-only authentication and authorization APIs.
62
62
 
63
63
  The default authentication mode remains stateless signed JWT-cookie authentication. Applications may opt into server-side session stores, revocation, logout-all, idle timeout, role/permission guards and resource-aware authorization policies.
64
64
 
65
- Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [Authorization & Security v2](authorization-security.md), [JWT Sessions](session-auth.md).
65
+ Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [Authorization & Security v2](authorization-security.md), [JWT Sessions](session-auth.md), [Testing Platform](testing-platform.md).
66
66
 
67
67
  ## `bcp/jobs`
68
68
 
@@ -78,7 +78,7 @@ BCP does not install a Redis library and does not create the connection. Applica
78
78
 
79
79
  The processing model is at-least-once. Handlers that perform non-idempotent external side effects should use application-level idempotency protection.
80
80
 
81
- Related guides: [Background Jobs Platform](background-jobs.md), [Job Scheduling Platform](job-scheduling.md), [Durable Jobs Platform](durable-jobs.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Observability Platform v2](observability.md).
81
+ Related guides: [Background Jobs Platform](background-jobs.md), [Job Scheduling Platform](job-scheduling.md), [Durable Jobs Platform](durable-jobs.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
82
82
 
83
83
  ## `bcp/workflow`
84
84
 
@@ -111,7 +111,7 @@ When an existing `BackgroundJobQueue` is supplied, workflow execution and delay
111
111
 
112
112
  `WorkflowStore.claim()` / `release()` form the run-level lease boundary for multi-instance stores.
113
113
 
114
- Related guides: [Workflow Orchestration](workflow-orchestration.md), [Durable Jobs Platform](durable-jobs.md), [Observability Platform v2](observability.md).
114
+ Related guides: [Workflow Orchestration](workflow-orchestration.md), [Durable Jobs Platform](durable-jobs.md), [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
115
115
 
116
116
  ## `bcp/events`
117
117
 
@@ -125,81 +125,188 @@ import {
125
125
  createOutboxMigrationSql,
126
126
  createSqlOutboxStore,
127
127
  createTransactionalOutbox,
128
- type ClaimOutboxEventsOptions,
129
- type CleanupOutboxOptions,
130
- type EventBus,
131
- type FailOutboxEventOptions,
132
- type MemoryOutboxStore,
133
- type OutboxDispatcher,
134
- type OutboxDispatcherOptions,
135
- type OutboxDispatcherRunner,
136
- type OutboxEventHandler,
137
- type OutboxEventHandlerContext,
138
- type OutboxEventRecord,
139
- type OutboxEventState,
140
- type OutboxRetryDelay,
141
- type OutboxStats,
142
- type OutboxStore,
143
- type PublishOutboxEventOptions,
144
- type SqlOutboxStore,
145
- type SqlOutboxStoreOptions,
146
- type TransactionalOutbox,
147
- type TransactionalOutboxOptions,
148
128
  } from "bcp/events";
149
129
  ```
150
130
 
151
- ### Transactional publishing
131
+ `createTransactionalOutbox()` writes an event through the same `TransactionDatabase` used by `db.transaction()`, allowing business rows and outbox rows to commit or roll back together.
152
132
 
153
- `createTransactionalOutbox()` exposes `publish(transaction, type, payload, options)`.
133
+ `createSqlOutboxStore()` supports MySQL, PostgreSQL and SQLite. `createOutboxMigrationSql()` generates the outbox table/index DDL.
154
134
 
155
- The supplied `TransactionDatabase` is the same object received inside `db.transaction()`, allowing the application row and outbox event row to commit or roll back together.
135
+ `createOutboxDispatcher()` supports batched claims, leases, stale recovery, retry/backoff, terminal failure, job-queue handoff, custom publishing, local event-bus delivery and runner lifecycle.
156
136
 
157
- ### SQL store
137
+ Delivery is at-least-once; consumers should use idempotency controls for non-repeatable side effects.
158
138
 
159
- `createSqlOutboxStore()` supports MySQL, PostgreSQL and SQLite through the existing BCP database abstraction.
139
+ Related guides: [Transactional Outbox & Events](transactional-outbox-events.md), [Database](database.md), [Durable Jobs Platform](durable-jobs.md), [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
160
140
 
161
- `createOutboxMigrationSql()` generates the outbox table/index DDL for those providers.
141
+ ## `bcp/realtime`
162
142
 
163
- The SQL store persists payload/metadata, correlation/causation/aggregate IDs, retry counts, state timestamps and dispatcher lease information.
143
+ Server-only Realtime Platform APIs added in `0.2.13`.
164
144
 
165
- ### Dispatcher
145
+ ```ts
146
+ import {
147
+ createMemoryRealtimeBroker,
148
+ createMemoryRealtimePresenceStore,
149
+ createRealtime,
150
+ createRealtimeSseResponse,
151
+ type RealtimeAuthenticate,
152
+ type RealtimeAuthorizeChannel,
153
+ type RealtimeBroker,
154
+ type RealtimeBroadcastOptions,
155
+ type RealtimeConnection,
156
+ type RealtimeEnvelope,
157
+ type RealtimeEventContext,
158
+ type RealtimeEventHandler,
159
+ type RealtimeHeartbeatOptions,
160
+ type RealtimeHeartbeatRunner,
161
+ type RealtimeHub,
162
+ type RealtimeJoinOptions,
163
+ type RealtimeOptions,
164
+ type RealtimePresenceMember,
165
+ type RealtimePresenceStore,
166
+ type RealtimeSocket,
167
+ type RealtimeSseOptions,
168
+ } from "bcp/realtime";
169
+ ```
166
170
 
167
- `createOutboxDispatcher()` supports:
171
+ `createRealtime()` creates a server-side hub. Connections can `join()`, `leave()`, `emit()`, `send()`, `touch()` and `disconnect()`.
168
172
 
169
- ```text
170
- batched claim
171
- dispatcher lease
172
- stale recovery
173
- retry/backoff
174
- terminal failure
175
- durable job queue handoff
176
- custom publisher callback
177
- in-process EventBus delivery
178
- runner lifecycle
173
+ `RealtimeBroker` is the cross-hub pub/sub boundary and `RealtimePresenceStore` is the channel-presence boundary. Built-in memory implementations are intended for tests/single-process use; shared deployments can supply provider adapters.
174
+
175
+ `RealtimeOptions.authenticate` can resolve identity from a Request/connection payload, while `authorizeChannel` runs before channel membership is accepted.
176
+
177
+ BCP does not install a WebSocket provider. `RealtimeSocket` defines the minimal transport surface consumed by `hub.attachSocket()`.
178
+
179
+ `hub.sse()` and `createRealtimeSseResponse()` expose Web-standard Server-Sent Events responses with abort, filtering, retry hint and keep-alive options.
180
+
181
+ Realtime delivery is transient. Use database/outbox/jobs/workflows for durable state and refetch durable state/history after reconnect when catch-up is required.
182
+
183
+ Related guides: [Realtime Platform](realtime-platform.md), [Authentication](authentication.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
184
+
185
+ ## `bcp/testing`
186
+
187
+ Server-only Testing Platform APIs added in `0.2.14`.
188
+
189
+ ```ts
190
+ import {
191
+ createFakeClock,
192
+ createJobTestHarness,
193
+ createOutboxTestHarness,
194
+ createRealtimeTestHarness,
195
+ createRealtimeTestSocket,
196
+ createRouteTestHandler,
197
+ createSequenceIdFactory,
198
+ createTestApp,
199
+ createTestAuthSession,
200
+ createTestFormData,
201
+ createWorkflowTestHarness,
202
+ expectResponse,
203
+ readSseEvents,
204
+ runTestMiddleware,
205
+ runTestPageAction,
206
+ runTestPageGuards,
207
+ runTestPageLoader,
208
+ withTestTransaction,
209
+ type CreateTestAuthSessionOptions,
210
+ type FakeClock,
211
+ type JobTestHarness,
212
+ type OutboxTestHarness,
213
+ type ParsedSseEvent,
214
+ type RealtimeTestConnection,
215
+ type RealtimeTestHarness,
216
+ type RealtimeTestSocket,
217
+ type TestApp,
218
+ type TestAppOptions,
219
+ type TestAuthSession,
220
+ type TestPageActionOptions,
221
+ type TestPageContextOptions,
222
+ type TestPageGuardOptions,
223
+ type TestRequestHandler,
224
+ type TestRequestOptions,
225
+ type TestResponseExpectation,
226
+ type TestRouteFunction,
227
+ type TestRouteHandlerOptions,
228
+ type TestRouteMethod,
229
+ type TestRouteModule,
230
+ type TestTransactionDatabase,
231
+ type WorkflowTestHarness,
232
+ } from "bcp/testing";
179
233
  ```
180
234
 
181
- With `queue` configured, event `order.created` is enqueued as `event.order.created` using stable job ID `outbox:<event-id>`.
235
+ ### Request application harness
236
+
237
+ `createTestApp()` runs a Web-standard `Request -> Response` handler with convenience methods for GET/POST/PUT/PATCH/DELETE, JSON bodies, mutable default headers and an in-memory cookie jar that consumes `Set-Cookie` responses.
238
+
239
+ ### API route module testing
240
+
241
+ `createRouteTestHandler()` adapts BCP-style method exports (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`) to a Request handler. Missing methods return 405 with an `Allow` header.
242
+
243
+ Return values are normalized for tests: Response is preserved, strings become text Responses, null/undefined become 204, and other values become JSON.
244
+
245
+ ### Page loader, guard and form action testing
246
+
247
+ `runTestPageGuards()` executes one or more guards through the production `executePageGuardFunctions()` path. Guard data is chained in order and redirect/other Response short-circuits are preserved.
182
248
 
183
- ### Stores
249
+ `runTestPageLoader()` invokes the production `executePageLoaderFunction()` path with test params, URL/search params and optional guard data. The returned value is the normal `PageLoaderExecution` contract.
184
250
 
185
- `OutboxStore` is the persistence and concurrency boundary.
251
+ `runTestPageAction()` invokes the production `executePageActionFunction()` path, including action-name/method validation, guard data, FormData and Response/data handling.
186
252
 
187
- `createMemoryOutboxStore()` is intended for tests and single-process development. It does not provide durable transactional persistence.
253
+ `createTestFormData()` creates a FormData object from string/Blob fields and supports repeated values.
188
254
 
189
- ### States
255
+ ### Response assertions
256
+
257
+ `expectResponse()` exposes lightweight runner-neutral assertions:
190
258
 
191
259
  ```text
192
- pending
193
- processing
194
- published
195
- failed
260
+ status()
261
+ header()
262
+ text()
263
+ json()
264
+ jsonMatches()
196
265
  ```
197
266
 
198
- `published` means the configured dispatcher destination accepted the event. It does not mean a downstream queued consumer has completed.
267
+ BCP does not require Jest/Vitest assertion APIs.
268
+
269
+ ### Auth testing
270
+
271
+ `createTestAuthSession()` uses the production `createSessionToken()` implementation, including HS256 signature, issuer/audience and expiration semantics. It can also register the matching server-side record in an `AuthSessionStore`.
272
+
273
+ This allows route/auth tests to use a real BCP session cookie instead of introducing a test-only identity header.
274
+
275
+ ### Database rollback testing
276
+
277
+ `withTestTransaction()` executes a callback in a real BCP database transaction and deliberately rejects the transaction with an internal rollback sentinel after the test callback succeeds. The callback result is returned to the test while the transaction is rolled back.
278
+
279
+ Application callback errors remain unchanged and are not swallowed.
280
+
281
+ ### Middleware testing
282
+
283
+ `runTestMiddleware()` invokes the actual Middleware System v2 onion pipeline through `executeMiddlewarePipeline()` and supports a custom downstream Request handler.
284
+
285
+ ### Deterministic utilities
286
+
287
+ `createFakeClock()` exposes `now()`, `set()`, `advance()` and `reset()` for time-sensitive queues/workflows/schedulers.
288
+
289
+ `createSequenceIdFactory()` creates deterministic IDs for stable assertions.
290
+
291
+ ### Infrastructure harnesses
292
+
293
+ `createJobTestHarness()` drains currently eligible work through the real `BackgroundJobQueue.processNext()` API and exposes record/count assertions.
294
+
295
+ `createWorkflowTestHarness()` can start/run workflows until terminal or waiting state and optionally force persisted delays to resume.
296
+
297
+ `createOutboxTestHarness()` dispatches through the actual `OutboxDispatcher` and exposes event/state/statistics helpers.
298
+
299
+ `createRealtimeTestSocket()` implements the `RealtimeSocket` adapter contract entirely in memory. `createRealtimeTestHarness()` connects that socket to a real `RealtimeHub` and can assert server-sent channel events.
300
+
301
+ `readSseEvents()` reads event-stream Responses, ignores comment/retry frames and JSON-decodes `data:` payloads when possible.
302
+
303
+ ### Runner neutrality and boundary
304
+
305
+ `bcp/testing` has no dependency on Jest or Vitest. BCP's own suite uses Node `node:test`, but the helpers can be called from another runner.
199
306
 
200
- Delivery is at-least-once; consumers should use idempotency controls for non-repeatable external side effects.
307
+ The package is server-only; the client boundary validator rejects `bcp/testing` from pages/client islands.
201
308
 
202
- Related guides: [Transactional Outbox & Events](transactional-outbox-events.md), [Database](database.md), [Durable Jobs Platform](durable-jobs.md), [Observability Platform v2](observability.md).
309
+ Related guides: [Testing Platform](testing-platform.md), [Authentication](authentication.md), [Database](database.md), [Durable Jobs](durable-jobs.md), [Workflow Orchestration](workflow-orchestration.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Realtime Platform](realtime-platform.md).
203
310
 
204
311
  ## `bcp/observability`
205
312
 
@@ -211,7 +318,7 @@ Related guides: [Observability Platform v2](observability.md), [Logging](develop
211
318
 
212
319
  Server request/runtime APIs including request context, cookies, CSRF and same-origin protection, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
213
320
 
214
- Related guides: [Server Request APIs](server-request-apis.md), [Authorization & Security v2](authorization-security.md), [File Upload](file-upload.md), [Storage](storage.md), [Storage Ecosystem](storage-ecosystem.md), [Production Hardening](production-hardening.md).
321
+ Related guides: [Server Request APIs](server-request-apis.md), [Authorization & Security v2](authorization-security.md), [File Upload](file-upload.md), [Storage](storage.md), [Storage Ecosystem](storage-ecosystem.md), [Production Hardening](production-hardening.md), [Testing Platform](testing-platform.md).
215
322
 
216
323
  ## `bcp/server-only`
217
324
 
@@ -227,7 +334,7 @@ Related guide: [Application Modules](application-modules.md).
227
334
 
228
335
  Middleware System v2 APIs and types.
229
336
 
230
- Related guide: [Middleware](middleware.md).
337
+ Related guides: [Middleware](middleware.md), [Testing Platform](testing-platform.md).
231
338
 
232
339
  ## Stability
233
340
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "versionTarget": "0.2.12",
4
+ "versionTarget": "0.2.14",
5
5
  "releaseState": "unreleased",
6
6
  "sections": [
7
7
  {
@@ -58,7 +58,7 @@
58
58
  {
59
59
  "id": "runtime",
60
60
  "title": "Runtime & Infrastructure",
61
- "description": "Middleware, durable background jobs, scheduling, workflow orchestration, event delivery, observability, logging, caching, security and production hardening.",
61
+ "description": "Middleware, jobs, scheduling, workflows, event delivery, realtime channels, observability, caching, security and production hardening.",
62
62
  "pages": [
63
63
  { "route": "/docs/middleware", "source": "middleware.md", "title": "Middleware" },
64
64
  { "route": "/docs/hydration", "source": "hydration.md", "title": "Hydration" },
@@ -68,6 +68,7 @@
68
68
  { "route": "/docs/job-scheduling", "source": "job-scheduling.md", "title": "Job Scheduling Platform" },
69
69
  { "route": "/docs/durable-jobs", "source": "durable-jobs.md", "title": "Durable Jobs Platform" },
70
70
  { "route": "/docs/workflow-orchestration", "source": "workflow-orchestration.md", "title": "Workflow Orchestration" },
71
+ { "route": "/docs/realtime-platform", "source": "realtime-platform.md", "title": "Realtime Platform" },
71
72
  { "route": "/docs/caching", "source": "caching.md", "title": "Caching" },
72
73
  { "route": "/docs/security", "source": "security.md", "title": "Security" },
73
74
  { "route": "/docs/production-hardening", "source": "production-hardening.md", "title": "Production Hardening" }
@@ -87,10 +88,11 @@
87
88
  {
88
89
  "id": "developer-experience",
89
90
  "title": "Developer Experience",
90
- "description": "Project generators, diagnostics, project metadata and framework maintenance tooling.",
91
+ "description": "Project generators, diagnostics, testing, project metadata and framework maintenance tooling.",
91
92
  "pages": [
92
93
  { "route": "/docs/generators", "source": "generators.md", "title": "Project Generators" },
93
- { "route": "/docs/developer-tools", "source": "developer-tools.md", "title": "Doctor & Inspect" }
94
+ { "route": "/docs/developer-tools", "source": "developer-tools.md", "title": "Doctor & Inspect" },
95
+ { "route": "/docs/testing-platform", "source": "testing-platform.md", "title": "Testing Platform" }
94
96
  ]
95
97
  },
96
98
  {
@@ -113,7 +115,9 @@
113
115
  }
114
116
  ],
115
117
  "releases": [
116
- { "route": "/releases/0.2.12", "source": "releases/0.2.12.md", "version": "0.2.12", "state": "unreleased" },
118
+ { "route": "/releases/0.2.14", "source": "releases/0.2.14.md", "version": "0.2.14", "state": "unreleased" },
119
+ { "route": "/releases/0.2.13", "source": "releases/0.2.13.md", "version": "0.2.13" },
120
+ { "route": "/releases/0.2.12", "source": "releases/0.2.12.md", "version": "0.2.12" },
117
121
  { "route": "/releases/0.2.11", "source": "releases/0.2.11.md", "version": "0.2.11" },
118
122
  { "route": "/releases/0.2.10", "source": "releases/0.2.10.md", "version": "0.2.10" },
119
123
  { "route": "/releases/0.2.9", "source": "releases/0.2.9.md", "version": "0.2.9" },
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "version": "0.2.12",
4
+ "version": "0.2.14",
5
5
  "releaseState": "unreleased",
6
- "baseline": "transactional-outbox-events",
6
+ "baseline": "testing-platform",
7
7
  "runtime": {
8
8
  "node": ">=24.11.0",
9
9
  "react": "19",
@@ -22,6 +22,8 @@
22
22
  "bcp/jobs",
23
23
  "bcp/workflow",
24
24
  "bcp/events",
25
+ "bcp/realtime",
26
+ "bcp/testing",
25
27
  "bcp/observability",
26
28
  "bcp/server",
27
29
  "bcp/server-only",
@@ -111,6 +113,31 @@
111
113
  "outboxStatistics": true,
112
114
  "eventBus": true,
113
115
  "outboxJobDelivery": true,
116
+ "realtimePlatform": true,
117
+ "realtimeBrokerContract": true,
118
+ "realtimePresenceStore": true,
119
+ "realtimeChannels": true,
120
+ "realtimeChannelAuthorization": true,
121
+ "realtimeSocketAdapter": true,
122
+ "realtimeServerSentEvents": true,
123
+ "realtimeHeartbeats": true,
124
+ "realtimeCrossHubBroadcast": true,
125
+ "testingPlatform": true,
126
+ "testRequestHarness": true,
127
+ "testRouteHandlers": true,
128
+ "testPageLoaders": true,
129
+ "testPageGuards": true,
130
+ "testFormActions": true,
131
+ "testResponseAssertions": true,
132
+ "testAuthSessions": true,
133
+ "testTransactionRollback": true,
134
+ "testMiddlewarePipeline": true,
135
+ "testJobHarness": true,
136
+ "testWorkflowHarness": true,
137
+ "testOutboxHarness": true,
138
+ "testRealtimeSocket": true,
139
+ "testSseReader": true,
140
+ "deterministicTestClock": true,
114
141
  "databaseMigrations": true,
115
142
  "databaseAdapterContract": true,
116
143
  "databasePostgresql": true,
@@ -150,7 +177,7 @@
150
177
  "s3-compatible"
151
178
  ],
152
179
  "compatibility": {
153
- "previousBaseline": "0.2.11",
180
+ "previousBaseline": "0.2.13",
154
181
  "intentionalBreakingChangesFromPreviousBaseline": false,
155
182
  "migrationGuide": "migration-0.2.md"
156
183
  },
@@ -172,7 +199,9 @@
172
199
  "durableJobs": "durable-jobs.md",
173
200
  "workflowOrchestration": "workflow-orchestration.md",
174
201
  "transactionalOutboxEvents": "transactional-outbox-events.md",
202
+ "realtimePlatform": "realtime-platform.md",
203
+ "testingPlatform": "testing-platform.md",
175
204
  "migrationGuide": "migration-0.2.md",
176
- "releaseNotes": "releases/0.2.12.md"
205
+ "releaseNotes": "releases/0.2.14.md"
177
206
  }
178
207
  }