@chidchanun/bcp 0.2.8 → 0.2.9

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,69 +60,15 @@ 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 and Job Scheduling APIs.
70
+
71
+ Queue APIs:
232
72
 
233
73
  ```ts
234
74
  import {
@@ -249,89 +89,46 @@ import {
249
89
  } from "bcp/jobs";
250
90
  ```
251
91
 
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.
253
-
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.
255
-
256
- The queue contract is designed for practical at-least-once processing; handlers should be idempotent when duplicate side effects are unsafe.
257
-
258
- Related guides: [Background Jobs Platform](background-jobs.md), [Observability Platform v2](observability.md).
259
-
260
- ## `bcp/observability`
261
-
262
- Server-only Observability Platform v2 APIs.
92
+ Scheduling APIs added in `0.2.9`:
263
93
 
264
94
  ```ts
265
95
  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";
96
+ createJobScheduler,
97
+ createMemoryJobScheduleStore,
98
+ nextCronTime,
99
+ nextScheduleTime,
100
+ type JobSchedule,
101
+ type JobScheduleRecord,
102
+ type JobScheduleStore,
103
+ type JobScheduler,
104
+ type JobSchedulerOptions,
105
+ type JobSchedulerRunner,
106
+ type MemoryJobScheduleStore,
107
+ type RunDueSchedulesOptions,
108
+ type ScheduleJobOptions,
109
+ type StartJobSchedulerOptions,
110
+ } from "bcp/jobs";
286
111
  ```
287
112
 
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.
113
+ `createJobQueue()` provides delayed enqueueing, retry/backoff, cancellation, manual `processNext()` execution and concurrent workers.
289
114
 
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.
115
+ `createJobScheduler()` adds recurring interval and UTC five-field cron schedules. The scheduler leases due records from `JobScheduleStore`, then enqueues normal queue jobs using deterministic occurrence ids.
291
116
 
292
- The built-in registry is process-local. Multi-instance deployments should scrape each process/container or aggregate through external monitoring infrastructure.
117
+ The built-in queue adapter and schedule store are process-local. Durable multi-instance deployments should implement both `JobQueueAdapter` and `JobScheduleStore` against shared infrastructure. `JobQueueAdapter.reserve()` and `JobScheduleStore.acquireDue()` are the respective atomic concurrency boundaries.
293
118
 
294
- Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
119
+ Cron evaluation in `0.2.9` uses UTC. `nextCronTime()` and `nextScheduleTime()` are available for tooling and tests.
295
120
 
296
- ## `bcp/server`
121
+ Related guides: [Background Jobs Platform](background-jobs.md), [Job Scheduling Platform](job-scheduling.md), [Observability Platform v2](observability.md).
297
122
 
298
- Server request/runtime APIs.
123
+ ## `bcp/observability`
299
124
 
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.
125
+ Server-only Observability Platform v2 APIs for process-local counters, gauges, histograms, Prometheus exposition, request metrics middleware and health/readiness checks.
301
126
 
302
- ```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";
332
- ```
127
+ Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
128
+
129
+ ## `bcp/server`
333
130
 
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`.
131
+ 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
132
 
336
133
  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
134
 
@@ -343,20 +140,12 @@ Server-only module boundary marker.
343
140
  import "bcp/server-only";
344
141
  ```
345
142
 
346
- Place this import in application modules that must never enter a browser bundle.
347
-
348
143
  Related guide: [Application Modules](application-modules.md).
349
144
 
350
145
  ## `bcp/middleware`
351
146
 
352
147
  Middleware System v2 APIs and types.
353
148
 
354
- ```ts
355
- import type {
356
- MiddlewarePipelineHandler,
357
- } from "bcp/middleware";
358
- ```
359
-
360
149
  Related guide: [Middleware](middleware.md).
361
150
 
362
151
  ## Stability
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "versionTarget": "0.2.8",
4
+ "versionTarget": "0.2.9",
5
5
  "releaseState": "unreleased",
6
6
  "sections": [
7
7
  {
@@ -57,13 +57,14 @@
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, 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" },
67
68
  { "route": "/docs/caching", "source": "caching.md", "title": "Caching" },
68
69
  { "route": "/docs/security", "source": "security.md", "title": "Security" },
69
70
  { "route": "/docs/production-hardening", "source": "production-hardening.md", "title": "Production Hardening" }
@@ -109,7 +110,8 @@
109
110
  }
110
111
  ],
111
112
  "releases": [
112
- { "route": "/releases/0.2.8", "source": "releases/0.2.8.md", "version": "0.2.8", "state": "unreleased" },
113
+ { "route": "/releases/0.2.9", "source": "releases/0.2.9.md", "version": "0.2.9", "state": "unreleased" },
114
+ { "route": "/releases/0.2.8", "source": "releases/0.2.8.md", "version": "0.2.8" },
113
115
  { "route": "/releases/0.2.7", "source": "releases/0.2.7.md", "version": "0.2.7" },
114
116
  { "route": "/releases/0.2.6", "source": "releases/0.2.6.md", "version": "0.2.6" },
115
117
  { "route": "/releases/0.2.5", "source": "releases/0.2.5.md", "version": "0.2.5" },