@chidchanun/bcp 0.2.8 → 0.2.10

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.
@@ -8,26 +8,7 @@ The machine-readable source for this page is `docs/api-manifest.json`.
8
8
 
9
9
  Universal React application APIs.
10
10
 
11
- Common exports include:
12
-
13
- ```ts
14
- import {
15
- Form,
16
- Link,
17
- createIsland,
18
- navigate,
19
- notFound,
20
- useActionData,
21
- useActionError,
22
- useFormStatus,
23
- useGuardData,
24
- useLoaderData,
25
- useNavigation,
26
- useRouter,
27
- } from "bcp";
28
- ```
29
-
30
- Use this entrypoint for page/client-facing framework APIs, routing, forms, loader/guard data, islands and metadata types.
11
+ Common exports include `Form`, `Link`, `createIsland`, `navigate`, `notFound`, loader/action/guard hooks and router/navigation APIs.
31
12
 
32
13
  Related guides: [Routing](routing.md), [Server Data Loaders](server-data-loaders.md), [Route Guards](route-guards.md), [Form Actions](form-actions.md).
33
14
 
@@ -45,18 +26,7 @@ Related guide: [Hydration](hydration.md).
45
26
 
46
27
  ## `bcp/cache`
47
28
 
48
- Caching and revalidation APIs.
49
-
50
- ```ts
51
- import {
52
- cache,
53
- clearCache,
54
- dedupe,
55
- getCacheStats,
56
- revalidatePath,
57
- revalidateTag,
58
- } from "bcp/cache";
59
- ```
29
+ Caching, deduplication, statistics and path/tag revalidation primitives.
60
30
 
61
31
  Related guide: [Caching](caching.md).
62
32
 
@@ -64,67 +34,17 @@ Related guide: [Caching](caching.md).
64
34
 
65
35
  Typed framework configuration, application environment-schema validation and diagnostics APIs.
66
36
 
67
- ```ts
68
- import {
69
- applyEnvironmentDefaults,
70
- defineConfig,
71
- defineEnvironment,
72
- diagnoseBcpConfiguration,
73
- getEnvironmentSchemaFileNames,
74
- loadBcpEnvironmentSchema,
75
- readResolvedBcpConfig,
76
- resolveBcpConfig,
77
- validateEnvironment,
78
- } from "bcp/config";
79
- ```
80
-
81
- Use `defineConfig()` for framework runtime/build settings and `defineEnvironment()` for the optional `bcp.environment.*` application-variable schema.
82
-
83
- `validateEnvironment()` returns parsed declared values and structured issues. `applyEnvironmentDefaults()` fills only missing environment keys and does not overwrite values already supplied by the environment/runtime.
84
-
85
37
  Related guides: [Configuration](configuration.md), [Environment Validation](environment-validation.md).
86
38
 
87
39
  ## `bcp/validation`
88
40
 
89
- Typed validation primitives and `ValidationError`.
90
-
91
- ```ts
92
- import {
93
- array,
94
- boolean,
95
- literal,
96
- nullable,
97
- number,
98
- object,
99
- optional,
100
- parse,
101
- safeParse,
102
- string,
103
- union,
104
- } from "bcp/validation";
105
- ```
41
+ Typed validation primitives, parse helpers and `ValidationError`.
106
42
 
107
43
  Related guide: [Validation](validation.md).
108
44
 
109
45
  ## `bcp/error`
110
46
 
111
- Structured HTTP error helpers.
112
-
113
- ```ts
114
- import {
115
- HttpError,
116
- badRequest,
117
- conflict,
118
- forbidden,
119
- internalServerError,
120
- isHttpError,
121
- serviceUnavailable,
122
- throwHttpError,
123
- tooManyRequests,
124
- unauthorized,
125
- unprocessableEntity,
126
- } from "bcp/error";
127
- ```
47
+ Structured HTTP error helpers and response classification.
128
48
 
129
49
  Related guide: [Error Handling](error-handling.md).
130
50
 
@@ -132,33 +52,7 @@ Related guide: [Error Handling](error-handling.md).
132
52
 
133
53
  Server-only Database Platform v2 APIs.
134
54
 
135
- ```ts
136
- import {
137
- createDatabase,
138
- db,
139
- resolveDatabaseOptions,
140
- type DatabaseAdapter,
141
- type DatabaseAdapterFactory,
142
- type DatabaseConnectionOptions,
143
- type DatabaseDriver,
144
- type DatabaseOptions,
145
- type DatabaseParameters,
146
- type ResolvedDatabaseOptions,
147
- type TransactionDatabase,
148
- } from "bcp/database";
149
- ```
150
-
151
- Built-in SQL providers are:
152
-
153
- ```text
154
- mysql
155
- postgresql
156
- sqlite
157
- ```
158
-
159
- `BcpDatabase` instances expose lazy query/execute/transaction operations plus explicit `connect()`, `disconnect()` and backward-compatible `close()` lifecycle methods.
160
-
161
- Use the public database helpers and adapter types instead of importing framework-internal provider/pool runtime modules.
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.
162
56
 
163
57
  Related guides: [Database](database.md), [Database Migrations](database-migrations.md).
164
58
 
@@ -166,172 +60,136 @@ Related guides: [Database](database.md), [Database Migrations](database-migratio
166
60
 
167
61
  Server-only authentication and authorization APIs.
168
62
 
169
- ```ts
170
- import {
171
- AuthorizationError,
172
- assertPermission,
173
- auth,
174
- authorize,
175
- can,
176
- cannot,
177
- createAuth,
178
- createAuthGuard,
179
- createGuestGuard,
180
- createMemoryAuthSessionStore,
181
- createPermissionGuard,
182
- createRoleGuard,
183
- defineAuthorizationPolicy,
184
- getGuardAuth,
185
- getSession,
186
- getUserPermissions,
187
- hasPermission,
188
- login,
189
- logout,
190
- logoutAll,
191
- requireAuth,
192
- requireGuest,
193
- requirePermission,
194
- requireRole,
195
- revokeSession,
196
- revokeUserSessions,
197
- rotateSession,
198
- type AuthApi,
199
- type AuthLoginOptions,
200
- type AuthOptions,
201
- type AuthSession,
202
- type AuthSessionStore,
203
- type AuthSessionStoreRecord,
204
- type AuthUser,
205
- type AuthorizationContext,
206
- type AuthorizationMatch,
207
- type AuthorizationPolicy,
208
- type MemoryAuthSessionStore,
209
- type PermissionCheckOptions,
210
- type PermissionRequirement,
211
- type RequirePermissionOptions,
212
- } from "bcp/auth";
213
- ```
214
-
215
- The default authentication mode remains stateless signed JWT-cookie authentication.
216
-
217
- Configure `AuthOptions.store` to enable server-side session revocation and `idleTimeout`. `createMemoryAuthSessionStore()` is provided for development/testing; production multi-instance applications should implement `AuthSessionStore` with shared durable storage.
218
-
219
- Authorization & Security v2 adds permission checks, permission route guards and resource-aware policy functions:
220
-
221
- - `hasPermission()` / `assertPermission()` for flat permission or scope fields,
222
- - `requirePermission()` / `createPermissionGuard()` for route protection,
223
- - `defineAuthorizationPolicy()` for application policy definitions,
224
- - `can()` / `cannot()` for policy checks,
225
- - `authorize()` for throwing `AuthorizationError` when a policy denies access.
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.
226
64
 
227
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).
228
66
 
229
67
  ## `bcp/jobs`
230
68
 
231
- Server-only Background Jobs Platform APIs.
69
+ Server-only Background Jobs, Job Scheduling and Durable Jobs APIs.
70
+
71
+ Core queue APIs:
232
72
 
233
73
  ```ts
234
74
  import {
235
75
  createJobQueue,
236
76
  createMemoryJobQueueAdapter,
237
77
  type BackgroundJobQueue,
78
+ type CleanupJobsOptions,
79
+ type DeadLetterJobRecord,
238
80
  type EnqueueJobOptions,
81
+ type HeartbeatJobOptions,
239
82
  type JobHandler,
240
83
  type JobHandlerContext,
241
84
  type JobQueueAdapter,
242
85
  type JobQueueOptions,
86
+ type JobQueueStats,
243
87
  type JobRecord,
244
88
  type JobRetryDelay,
245
89
  type JobState,
246
90
  type JobWorker,
247
91
  type MemoryJobQueueAdapter,
92
+ type ProcessNextJobOptions,
93
+ type RecoverStaleJobsOptions,
94
+ type RequeueDeadLetterOptions,
95
+ type ReserveJobOptions,
248
96
  type StartJobWorkerOptions,
249
97
  } from "bcp/jobs";
250
98
  ```
251
99
 
252
- `createJobQueue()` provides delayed enqueueing, retry/backoff, cancellation, manual `processNext()` execution and concurrent workers. The default adapter is process-local memory storage and is intended for development, tests and single-process prototypes.
100
+ Scheduling APIs:
253
101
 
254
- Production applications that require durable processing should implement `JobQueueAdapter` against shared infrastructure. Adapter `reserve()` must atomically claim one eligible queued job so multiple workers cannot process the same reservation concurrently.
102
+ ```ts
103
+ import {
104
+ createJobScheduler,
105
+ createMemoryJobScheduleStore,
106
+ nextCronTime,
107
+ nextScheduleTime,
108
+ type JobSchedule,
109
+ type JobScheduleRecord,
110
+ type JobScheduleStore,
111
+ type JobScheduler,
112
+ type JobSchedulerOptions,
113
+ type JobSchedulerRunner,
114
+ type MemoryJobScheduleStore,
115
+ type RunDueSchedulesOptions,
116
+ type ScheduleJobOptions,
117
+ type StartJobSchedulerOptions,
118
+ } from "bcp/jobs";
119
+ ```
255
120
 
256
- The queue contract is designed for practical at-least-once processing; handlers should be idempotent when duplicate side effects are unsafe.
121
+ Durable Redis-compatible APIs added in `0.2.10`:
257
122
 
258
- Related guides: [Background Jobs Platform](background-jobs.md), [Observability Platform v2](observability.md).
123
+ ```ts
124
+ import {
125
+ createRedisJobQueueAdapter,
126
+ createRedisJobScheduleStore,
127
+ type RedisCommandClient,
128
+ type RedisJobQueueAdapter,
129
+ type RedisJobsAdapterOptions,
130
+ type RedisJobScheduleStore,
131
+ } from "bcp/jobs";
132
+ ```
259
133
 
260
- ## `bcp/observability`
134
+ ### Queue lifecycle
261
135
 
262
- Server-only Observability Platform v2 APIs.
136
+ `createJobQueue()` supports:
263
137
 
264
- ```ts
265
- import {
266
- createHealthRegistry,
267
- createMetricsRegistry,
268
- createMetricsResponse,
269
- createRequestMetricsMiddleware,
270
- type CounterMetric,
271
- type GaugeMetric,
272
- type HealthCheck,
273
- type HealthCheckOptions,
274
- type HealthCheckReportItem,
275
- type HealthCheckResult,
276
- type HealthRegistry,
277
- type HealthReport,
278
- type HistogramMetric,
279
- type HistogramOptions,
280
- type MetricDefinitionOptions,
281
- type MetricLabels,
282
- type MetricLabelValue,
283
- type MetricsRegistry,
284
- type RequestMetricsOptions,
285
- } from "bcp/observability";
138
+ ```text
139
+ immediate/delayed enqueue
140
+ retry/backoff
141
+ cancellation
142
+ manual processNext()
143
+ worker concurrency
144
+ visibility timeout
145
+ heartbeat lease renewal
146
+ stale-running recovery
147
+ DLQ inspection/requeue
148
+ terminal retention cleanup
149
+ queue statistics
286
150
  ```
287
151
 
288
- `createMetricsRegistry()` provides process-local counters, gauges and histograms. `createMetricsResponse()` renders Prometheus-compatible text exposition. `createRequestMetricsMiddleware()` measures HTTP request counts and duration using bounded `method` / `status` labels by default and intentionally does not label by raw path.
152
+ Durable adapter methods such as `heartbeat()`, `recoverStale()`, `listDeadLetters()`, `requeueDeadLetter()`, `cleanup()` and `stats()` are optional so earlier `JobQueueAdapter` implementations remain compatible.
289
153
 
290
- `createHealthRegistry()` registers synchronous or asynchronous liveness/readiness checks, applies per-check timeouts and produces JSON health responses with HTTP `200` when all checks pass or `503` when any check fails.
154
+ `reserve()` receives an optional second `ReserveJobOptions` argument containing `ownerId` and `visibilityTimeoutMs`. Production durable adapters should use it to create an atomic visibility lease.
291
155
 
292
- The built-in registry is process-local. Multi-instance deployments should scrape each process/container or aggregate through external monitoring infrastructure.
156
+ ### Scheduling
293
157
 
294
- Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
158
+ `createJobScheduler()` supports recurring interval and UTC five-field cron schedules.
295
159
 
296
- ## `bcp/server`
160
+ The scheduler leases due records from `JobScheduleStore`, then enqueues normal jobs using deterministic occurrence IDs. `nextCronTime()` and `nextScheduleTime()` are available for tooling and tests.
161
+
162
+ ### Redis-compatible durable adapters
297
163
 
298
- Server request/runtime APIs.
164
+ `createRedisJobQueueAdapter()` implements the queue contract on a shared Redis-compatible command client.
299
165
 
300
- This entrypoint includes 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.
166
+ `createRedisJobScheduleStore()` implements the schedule-store contract using the same minimal client shape:
301
167
 
302
168
  ```ts
303
- import {
304
- clientIp,
305
- cookies,
306
- createCsrfToken,
307
- createLocalStorage,
308
- createLogger,
309
- createS3Storage,
310
- createStorageResponse,
311
- destroyCsrfToken,
312
- getProductionHardeningConfig,
313
- headers,
314
- isSafeHttpMethod,
315
- isSameOriginRequest,
316
- json,
317
- redirect,
318
- registerShutdownHook,
319
- requestId,
320
- requestMethod,
321
- requestUrl,
322
- requireCsrfRequest,
323
- requireSameOriginRequest,
324
- storeMultipartFile,
325
- verifyCsrfRequest,
326
- verifyCsrfToken,
327
- RequestSecurityError,
328
- type CsrfTokenOptions,
329
- type SameOriginOptions,
330
- type VerifyCsrfRequestOptions,
331
- } from "bcp/server";
169
+ interface RedisCommandClient {
170
+ sendCommand(
171
+ command: string[]
172
+ ): Promise<unknown>;
173
+ }
332
174
  ```
333
175
 
334
- `requireSameOriginRequest()` protects unsafe cookie-authenticated mutations by validating `Origin`/`Referer`. `createCsrfToken()` and `requireCsrfRequest()` provide signed double-submit style CSRF protection. `BCP_CSRF_SECRET` is preferred when configured and falls back to `BCP_SESSION_SECRET`.
176
+ BCP does not install a Redis library and does not create the connection. Applications own authentication, TLS, Cluster/Sentinel configuration and connection shutdown.
177
+
178
+ The reference adapters use atomic Lua state transitions. The default namespace `bcp:{jobs}` uses a Redis Cluster hash tag so all job/schedule keys share one slot.
179
+
180
+ The processing model is at-least-once. Handlers that perform non-idempotent external side effects should use application-level idempotency protection.
181
+
182
+ Related guides: [Background Jobs Platform](background-jobs.md), [Job Scheduling Platform](job-scheduling.md), [Durable Jobs Platform](durable-jobs.md), [Observability Platform v2](observability.md).
183
+
184
+ ## `bcp/observability`
185
+
186
+ Server-only Observability Platform v2 APIs for process-local counters, gauges, histograms, Prometheus exposition, request metrics middleware and health/readiness checks.
187
+
188
+ Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
189
+
190
+ ## `bcp/server`
191
+
192
+ 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.
335
193
 
336
194
  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).
337
195
 
@@ -343,20 +201,12 @@ Server-only module boundary marker.
343
201
  import "bcp/server-only";
344
202
  ```
345
203
 
346
- Place this import in application modules that must never enter a browser bundle.
347
-
348
204
  Related guide: [Application Modules](application-modules.md).
349
205
 
350
206
  ## `bcp/middleware`
351
207
 
352
208
  Middleware System v2 APIs and types.
353
209
 
354
- ```ts
355
- import type {
356
- MiddlewarePipelineHandler,
357
- } from "bcp/middleware";
358
- ```
359
-
360
210
  Related guide: [Middleware](middleware.md).
361
211
 
362
212
  ## Stability
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "versionTarget": "0.2.8",
4
+ "versionTarget": "0.2.10",
5
5
  "releaseState": "unreleased",
6
6
  "sections": [
7
7
  {
@@ -57,13 +57,15 @@
57
57
  {
58
58
  "id": "runtime",
59
59
  "title": "Runtime & Infrastructure",
60
- "description": "Middleware, background jobs, observability, logging, caching, security and production hardening.",
60
+ "description": "Middleware, durable background jobs, scheduling, observability, logging, caching, security and production hardening.",
61
61
  "pages": [
62
62
  { "route": "/docs/middleware", "source": "middleware.md", "title": "Middleware" },
63
63
  { "route": "/docs/hydration", "source": "hydration.md", "title": "Hydration" },
64
64
  { "route": "/docs/development-logging", "source": "development-logging.md", "title": "Logging" },
65
65
  { "route": "/docs/observability", "source": "observability.md", "title": "Observability Platform v2" },
66
66
  { "route": "/docs/background-jobs", "source": "background-jobs.md", "title": "Background Jobs Platform" },
67
+ { "route": "/docs/job-scheduling", "source": "job-scheduling.md", "title": "Job Scheduling Platform" },
68
+ { "route": "/docs/durable-jobs", "source": "durable-jobs.md", "title": "Durable Jobs Platform" },
67
69
  { "route": "/docs/caching", "source": "caching.md", "title": "Caching" },
68
70
  { "route": "/docs/security", "source": "security.md", "title": "Security" },
69
71
  { "route": "/docs/production-hardening", "source": "production-hardening.md", "title": "Production Hardening" }
@@ -109,7 +111,9 @@
109
111
  }
110
112
  ],
111
113
  "releases": [
112
- { "route": "/releases/0.2.8", "source": "releases/0.2.8.md", "version": "0.2.8", "state": "unreleased" },
114
+ { "route": "/releases/0.2.10", "source": "releases/0.2.10.md", "version": "0.2.10", "state": "unreleased" },
115
+ { "route": "/releases/0.2.9", "source": "releases/0.2.9.md", "version": "0.2.9" },
116
+ { "route": "/releases/0.2.8", "source": "releases/0.2.8.md", "version": "0.2.8" },
113
117
  { "route": "/releases/0.2.7", "source": "releases/0.2.7.md", "version": "0.2.7" },
114
118
  { "route": "/releases/0.2.6", "source": "releases/0.2.6.md", "version": "0.2.6" },
115
119
  { "route": "/releases/0.2.5", "source": "releases/0.2.5.md", "version": "0.2.5" },