@chidchanun/bcp 0.2.7 → 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.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # BCP Framework
2
2
 
3
- BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, authorization, database access, observability, validation, uploads, storage and standalone Node.js production deployment.
3
+ BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, authorization, database access, background jobs, recurring scheduling, observability, validation, uploads, storage and standalone Node.js production deployment.
4
4
 
5
- > **Development target:** `0.2.7Observability Platform v2`
5
+ > **Development target:** `0.2.9Job Scheduling Platform`
6
6
  >
7
- > `0.2.7` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.9` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
8
8
 
9
9
  ## 0.2 platform
10
10
 
11
- `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, `0.2.5` added Authentication Platform v2, `0.2.6` added Authorization & Security v2, and `0.2.7` adds dependency-free metrics, Prometheus exposition, request metrics and health/readiness checks without intentionally changing the existing application model.
11
+ `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, `0.2.5` added Authentication Platform v2, `0.2.6` added Authorization & Security v2, `0.2.7` added Observability Platform v2, `0.2.8` added Background Jobs Platform, and `0.2.9` adds recurring interval/UTC-cron scheduling with lease-aware shared-store contracts.
12
12
 
13
13
  Machine-readable platform contracts:
14
14
 
@@ -35,6 +35,8 @@ docs/api-manifest.json
35
35
  | Authorization | Auth/guest/role/permission route guards, flat permissions and resource-aware policies |
36
36
  | Request security | Same-origin validation and signed CSRF tokens for unsafe mutations |
37
37
  | Middleware | Middleware System v2 with onion execution |
38
+ | Background jobs | Adapter contract, in-memory queue, delayed jobs, retries/backoff, cancellation and concurrent workers |
39
+ | Scheduling | Recurring interval jobs, UTC cron, schedule-store leases and deterministic scheduled run IDs |
38
40
  | Observability | Structured logs, counters/gauges/histograms, Prometheus output, request metrics and health/readiness checks |
39
41
  | Validation | Typed validators and structured validation errors |
40
42
  | Error handling | HTTP error helpers and consistent error responses |
@@ -273,24 +275,6 @@ import {
273
275
  authorize,
274
276
  defineAuthorizationPolicy,
275
277
  } from "bcp/auth";
276
-
277
- const updateProject =
278
- defineAuthorizationPolicy(
279
- ({
280
- user,
281
- resource,
282
- }) =>
283
- resource.ownerId ===
284
- user.id
285
- );
286
-
287
- await authorize(
288
- updateProject,
289
- {
290
- user,
291
- resource: project,
292
- }
293
- );
294
278
  ```
295
279
 
296
280
  Request-security helpers are exposed from `bcp/server`:
@@ -307,89 +291,136 @@ Read more: [Authorization & Security v2](docs/authorization-security.md)
307
291
 
308
292
  ## Observability Platform v2 — 0.2.7
309
293
 
310
- Create one application metrics registry:
311
-
312
294
  ```ts
313
295
  import {
296
+ createHealthRegistry,
314
297
  createMetricsRegistry,
298
+ createMetricsResponse,
315
299
  } from "bcp/observability";
316
-
317
- export const metrics =
318
- createMetricsRegistry();
319
300
  ```
320
301
 
321
- Supported metric types:
302
+ Read more: [Observability Platform v2](docs/observability.md)
322
303
 
323
- ```text
324
- counter
325
- gauge
326
- histogram
327
- ```
304
+ ## Background Jobs Platform — 0.2.8
328
305
 
329
- Expose Prometheus-compatible text:
306
+ Create a server-side queue:
330
307
 
331
308
  ```ts
332
309
  import {
333
- createMetricsResponse,
334
- } from "bcp/observability";
310
+ createJobQueue,
311
+ } from "bcp/jobs";
335
312
 
336
- export function GET() {
337
- return createMetricsResponse(
338
- metrics
339
- );
340
- }
313
+ export const jobs =
314
+ createJobQueue();
341
315
  ```
342
316
 
343
- Instrument HTTP requests through Middleware System v2:
317
+ Register a handler:
344
318
 
345
319
  ```ts
346
- import {
347
- createRequestMetricsMiddleware,
348
- } from "bcp/observability";
320
+ jobs.register<{
321
+ userId: number;
322
+ }>(
323
+ "email.welcome",
324
+ async ({ payload }) => {
325
+ await sendWelcomeEmail(
326
+ payload.userId
327
+ );
328
+ }
329
+ );
330
+ ```
331
+
332
+ Enqueue immediately or with a delay:
349
333
 
350
- export const requestMetrics =
351
- createRequestMetricsMiddleware(
352
- metrics
353
- );
334
+ ```ts
335
+ await jobs.enqueue(
336
+ "email.welcome",
337
+ {
338
+ userId: 42,
339
+ },
340
+ {
341
+ delayMs: 5_000,
342
+ maxAttempts: 5,
343
+ }
344
+ );
354
345
  ```
355
346
 
356
- Default request metrics use only bounded labels:
347
+ Start concurrent workers:
357
348
 
358
- ```text
359
- bcp_http_requests_total{method,status}
360
- bcp_http_request_duration_seconds{method,status}
349
+ ```ts
350
+ const worker =
351
+ jobs.startWorker({
352
+ concurrency: 4,
353
+ pollIntervalMs: 250,
354
+ });
361
355
  ```
362
356
 
363
- Raw paths are not attached by default.
357
+ The default memory adapter is process-local. Durable multi-process deployments should implement `JobQueueAdapter` against shared infrastructure.
358
+
359
+ Read more: [Background Jobs Platform](docs/background-jobs.md)
360
+
361
+ ## Job Scheduling Platform — 0.2.9
364
362
 
365
- Health/readiness registry:
363
+ Create a scheduler on top of the same queue:
366
364
 
367
365
  ```ts
368
366
  import {
369
- createHealthRegistry,
370
- } from "bcp/observability";
367
+ createJobScheduler,
368
+ } from "bcp/jobs";
371
369
 
372
- export const health =
373
- createHealthRegistry();
370
+ export const scheduler =
371
+ createJobScheduler({
372
+ queue: jobs,
373
+ });
374
+ ```
375
+
376
+ Interval schedule:
374
377
 
375
- health.register(
376
- "database",
377
- async () => {
378
- await db.query("SELECT 1");
379
- return true;
378
+ ```ts
379
+ await scheduler.schedule(
380
+ "cache.cleanup",
381
+ {},
382
+ {
383
+ id: "cache-cleanup",
384
+ everyMs: 5 * 60 * 1000,
380
385
  }
381
386
  );
382
387
  ```
383
388
 
384
- Use:
389
+ UTC cron schedule:
385
390
 
386
391
  ```ts
387
- return health.response();
392
+ await scheduler.schedule(
393
+ "report.weekday",
394
+ {},
395
+ {
396
+ cron: "30 9 * * 1-5",
397
+ }
398
+ );
388
399
  ```
389
400
 
390
- Health responses return `200` when every check passes and `503` when any registered dependency is unhealthy or times out.
401
+ Supported cron shape:
391
402
 
392
- Read more: [Observability Platform v2](docs/observability.md)
403
+ ```text
404
+ minute hour day-of-month month day-of-week
405
+ ```
406
+
407
+ The scheduler runner polls due schedules and enqueues normal BCP jobs:
408
+
409
+ ```ts
410
+ const scheduleRunner =
411
+ scheduler.start({
412
+ pollIntervalMs: 1_000,
413
+ leaseMs: 30_000,
414
+ });
415
+
416
+ // graceful shutdown
417
+ await scheduleRunner.stop();
418
+ await scheduler.close();
419
+ ```
420
+
421
+ The built-in `createMemoryJobScheduleStore()` is process-local. Multi-instance production deployments should implement a shared `JobScheduleStore` whose `acquireDue()` operation atomically claims schedules with lease ownership/expiry. Scheduled occurrences also use deterministic queue ids for duplicate protection.
422
+
423
+ Read more: [Job Scheduling Platform](docs/job-scheduling.md)
393
424
 
394
425
  ## Public entrypoints
395
426
 
@@ -404,6 +435,7 @@ bcp/validation
404
435
  bcp/error
405
436
  bcp/database
406
437
  bcp/auth
438
+ bcp/jobs
407
439
  bcp/observability
408
440
  bcp/server
409
441
  bcp/server-only
@@ -469,7 +501,7 @@ React SSR
469
501
  Hydration / SPA navigation
470
502
 
471
503
  Operational side channels:
472
- structured logs + metrics + health/readiness
504
+ background jobs + scheduler + structured logs + metrics + health/readiness
473
505
  ```
474
506
 
475
507
  ## Production build
@@ -515,7 +547,7 @@ npm run test:e2e
515
547
  npm run rc:check
516
548
  ```
517
549
 
518
- `0.2.7` adds Observability Platform v2 unit and prepared-package smoke checks covering metrics, Prometheus exposition, request timing, cardinality-safe default labels, health/readiness responses and timeout handling.
550
+ `0.2.9` adds Job Scheduling Platform unit and prepared-package smoke checks covering interval schedules, UTC cron parsing, standard day matching, schedule-store leases, deterministic scheduled run ids, retry propagation and lifecycle validation.
519
551
 
520
552
  Do not tag or publish until the final release commit passes the complete RC sequence.
521
553
 
@@ -537,12 +569,14 @@ Do not tag or publish until the final release commit passes the complete RC sequ
537
569
  | `0.2.5` | Authentication Platform v2 |
538
570
  | `0.2.6` | Authorization & Security v2 |
539
571
  | `0.2.7` | Observability Platform v2 |
572
+ | `0.2.8` | Background Jobs Platform |
573
+ | `0.2.9` | Job Scheduling Platform |
540
574
 
541
575
  ## Roadmap
542
576
 
543
- `0.2.7Observability Platform v2` establishes process-level metrics and health/readiness contracts on top of the existing structured logging and Middleware System v2 runtime.
577
+ `0.2.9Job Scheduling Platform` establishes recurring scheduling and the durable schedule-store contract on top of the provider-neutral queue introduced in `0.2.8`.
544
578
 
545
- Future `0.2.x` work can add distributed tracing or exporter integrations without changing the application metrics/health contract introduced here. Native `.exe`, desktop and mobile compilation remain later roadmap work.
579
+ Future work can add first-party durable queue/schedule adapters, dead-letter queues or workflow orchestration without changing the base queue and scheduler contracts. Native `.exe`, desktop and mobile compilation remain later roadmap work.
546
580
 
547
581
  ## License
548
582
 
package/docs/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `docs/` directory is the documentation source of truth for BCP Framework and is organized for **`bcp-docs-web`**.
4
4
 
5
- > **Documentation target:** BCP Framework `0.2.7Observability Platform v2`
5
+ > **Documentation target:** BCP Framework `0.2.9Job Scheduling Platform`
6
6
  >
7
7
  > **Release state:** unreleased development target until RC validation, tagging and npm publication complete.
8
8
 
@@ -21,24 +21,6 @@ docs/api-manifest.json
21
21
  -> public package entrypoints, source ownership and guide mapping
22
22
  ```
23
23
 
24
- Markdown files under `docs/` remain the authored documentation content.
25
-
26
- Recommended flow:
27
-
28
- ```text
29
- framework source/tests
30
-
31
- docs/
32
- ├─ Markdown content
33
- ├─ docs-web-manifest.json
34
- ├─ platform-manifest.json
35
- └─ api-manifest.json
36
-
37
- manifest-driven sync
38
-
39
- bcp-docs-web
40
- ```
41
-
42
24
  Framework source and tests remain authoritative for runtime behavior.
43
25
 
44
26
  ## Current 0.2.x milestones
@@ -53,48 +35,53 @@ Framework source and tests remain authoritative for runtime behavior.
53
35
  | `0.2.5` | Authentication Platform v2 |
54
36
  | `0.2.6` | Authorization & Security v2 |
55
37
  | `0.2.7` | Observability Platform v2 |
38
+ | `0.2.8` | Background Jobs Platform |
39
+ | `0.2.9` | Job Scheduling Platform |
56
40
 
57
- ## 0.2.7Observability Platform v2
41
+ ## 0.2.9Job Scheduling Platform
58
42
 
59
- `0.2.7` adds a server-only observability layer without adding third-party runtime dependencies.
43
+ `0.2.9` extends `bcp/jobs` with recurring interval jobs, dependency-free UTC cron schedules, scheduler runners, deterministic scheduled occurrence IDs and a lease-aware `JobScheduleStore` contract.
60
44
 
61
45
  New/updated documentation sources:
62
46
 
63
47
  | Source | Purpose |
64
48
  | --- | --- |
65
- | `observability.md` | Metrics registry, Prometheus output, request metrics and health/readiness checks |
66
- | `api-reference.md` | Public `bcp/observability` exports |
67
- | `platform-manifest.json` | Observability capability flags and new public entrypoint |
68
- | `api-manifest.json` | `bcp/observability` guide ownership |
69
- | `docs-web-manifest.json` | Observability navigation and `0.2.7` release route |
70
- | `releases/0.2.7.md` | Observability Platform v2 release notes |
49
+ | `background-jobs.md` | Base queue/worker contract from `0.2.8` |
50
+ | `job-scheduling.md` | Interval/cron schedules, leases and durable schedule-store guidance |
51
+ | `api-reference.md` | Public queue + scheduler APIs under `bcp/jobs` |
52
+ | `platform-manifest.json` | Job Scheduling capability flags |
53
+ | `api-manifest.json` | `bcp/jobs` guide ownership |
54
+ | `docs-web-manifest.json` | Scheduling navigation and `0.2.9` release route |
55
+ | `releases/0.2.9.md` | Job Scheduling Platform release notes |
71
56
 
72
- Primary APIs:
57
+ Primary scheduling APIs:
73
58
 
74
59
  ```ts
75
60
  import {
76
- createHealthRegistry,
77
- createMetricsRegistry,
78
- createMetricsResponse,
79
- createRequestMetricsMiddleware,
80
- } from "bcp/observability";
61
+ createJobScheduler,
62
+ createMemoryJobScheduleStore,
63
+ nextCronTime,
64
+ nextScheduleTime,
65
+ } from "bcp/jobs";
81
66
  ```
82
67
 
83
68
  Runtime model:
84
69
 
85
70
  ```text
86
- structured logs
87
- +
88
- process-local metrics
89
- +
90
- Prometheus exposition
91
- +
92
- health/readiness checks
71
+ recurring schedule
72
+ |
73
+ v
74
+ JobScheduleStore.acquireDue()
75
+ |
76
+ | lease + deterministic run id
77
+ v
78
+ JobQueueAdapter.enqueue()
79
+ |
80
+ v
81
+ queue worker(s)
93
82
  ```
94
83
 
95
- The request metrics middleware intentionally uses bounded `method` and `status` labels by default rather than raw paths.
96
-
97
- The built-in metrics registry is process-local; distributed aggregation remains deployment infrastructure or future exporter work.
84
+ The built-in schedule store and queue are process-local. Multi-process/container production deployments should implement shared durable `JobScheduleStore` and `JobQueueAdapter` contracts.
98
85
 
99
86
  ## Update rule
100
87
 
@@ -113,21 +100,6 @@ When framework behavior or public surface changes:
113
100
 
114
101
  `docs/docs-web-manifest.json` is the authoritative ordered navigation contract.
115
102
 
116
- Current sections:
117
-
118
- ```text
119
- Getting Started
120
- Routing & Data
121
- Authentication & Authorization
122
- Database
123
- Runtime & Infrastructure
124
- Storage & Uploads
125
- Developer Experience
126
- Platform & Compatibility
127
- API Reference
128
- Releases
129
- ```
130
-
131
103
  Important current routes:
132
104
 
133
105
  | Website route | Markdown source |
@@ -135,40 +107,18 @@ Important current routes:
135
107
  | `/docs/authentication` | `authentication.md` |
136
108
  | `/docs/authorization-security` | `authorization-security.md` |
137
109
  | `/docs/observability` | `observability.md` |
138
- | `/docs/development-logging` | `development-logging.md` |
110
+ | `/docs/background-jobs` | `background-jobs.md` |
111
+ | `/docs/job-scheduling` | `job-scheduling.md` |
139
112
  | `/docs/application-packaging` | `application-packaging.md` |
140
113
  | `/docs/database` | `database.md` |
141
114
  | `/docs/api-reference` | `api-reference.md` |
142
- | `/releases/0.2.7` | `releases/0.2.7.md` |
115
+ | `/releases/0.2.9` | `releases/0.2.9.md` |
143
116
 
144
117
  Every route/source pair is validated by unit tests.
145
118
 
146
- ## Platform manifest
147
-
148
- `docs/platform-manifest.json` describes:
149
-
150
- ```text
151
- framework version/release state
152
- Node/React/runtime baseline
153
- production build/package target
154
- public package entrypoints
155
- CLI command families
156
- capability flags
157
- previous-baseline compatibility intent
158
- documentation contract files
159
- ```
119
+ ## Public entrypoints
160
120
 
161
- The supported production target remains:
162
-
163
- ```text
164
- standalone-node
165
- ```
166
-
167
- ## API manifest
168
-
169
- `docs/api-manifest.json` describes public package entrypoints documentation tooling may present as supported APIs.
170
-
171
- Current entrypoints:
121
+ Current documented entrypoints:
172
122
 
173
123
  ```text
174
124
  bcp
@@ -179,6 +129,7 @@ bcp/validation
179
129
  bcp/error
180
130
  bcp/database
181
131
  bcp/auth
132
+ bcp/jobs
182
133
  bcp/observability
183
134
  bcp/server
184
135
  bcp/server-only
@@ -187,39 +138,9 @@ bcp/middleware
187
138
 
188
139
  The API-manifest entrypoint set must match the platform public-entrypoint set exactly.
189
140
 
190
- ## bcp-docs-web synchronization
191
-
192
- The docs website sync loads the manifests before Markdown content:
193
-
194
- ```text
195
- selected framework ref
196
-
197
- docs-web-manifest.json
198
- platform-manifest.json
199
- api-manifest.json
200
-
201
- validate version/release/API parity
202
-
203
- load referenced Markdown
204
-
205
- synchronize CMS/search/navigation
206
- ```
207
-
208
- ## Source conventions
209
-
210
- - one H1 per Markdown page,
211
- - stable heading hierarchy,
212
- - fenced code blocks with language tags,
213
- - relative links between docs,
214
- - exact public API names,
215
- - clear stable/RC/roadmap labels,
216
- - security limitations next to affected APIs,
217
- - no framework-internal module presented as public API,
218
- - no secrets/runtime `.env` values in public documentation metadata.
219
-
220
141
  ## Release validation
221
142
 
222
- Before publishing `0.2.7`:
143
+ Before publishing `0.2.9`:
223
144
 
224
145
  ```bash
225
146
  npm run typecheck
@@ -230,16 +151,16 @@ npm run test:e2e
230
151
  npm run rc:check
231
152
  ```
232
153
 
233
- Observability Platform v2 validation covers:
154
+ Job Scheduling Platform validation covers:
234
155
 
235
- - counter/gauge/histogram behavior,
236
- - Prometheus exposition,
237
- - metric definition validation,
238
- - request count and duration middleware,
239
- - cardinality-safe default request labels,
240
- - health/readiness response semantics,
241
- - health check timeout handling,
242
- - public `bcp/observability` exports,
156
+ - interval scheduling,
157
+ - five-field UTC cron parsing,
158
+ - standard day-of-month/day-of-week behavior,
159
+ - schedule-store leasing,
160
+ - deterministic scheduled run IDs,
161
+ - retry-limit propagation into queue jobs,
162
+ - schedule inspection/removal,
163
+ - scheduler configuration validation,
243
164
  - prepared npm package contents,
244
165
  - docs/platform/API version parity.
245
166
 
@@ -247,17 +168,4 @@ The final release tag must point to the exact commit that passed the complete RC
247
168
 
248
169
  ## Repository authority
249
170
 
250
- The framework repository remains authoritative for:
251
-
252
- ```text
253
- source
254
- public exports
255
- tests
256
- Markdown docs
257
- docs-web manifest
258
- platform manifest
259
- API manifest
260
- release notes
261
- ```
262
-
263
- `bcp-docs-web` remains the presentation/search/navigation layer for this content.
171
+ The framework repository remains authoritative for source, public exports, tests, Markdown docs, manifests and release notes. `bcp-docs-web` remains the presentation/search/navigation layer.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "version": "0.2.7",
4
+ "version": "0.2.9",
5
5
  "releaseState": "unreleased",
6
6
  "coverage": "public-entrypoints",
7
7
  "entrypoints": [
@@ -94,6 +94,18 @@
94
94
  "/docs/session-auth"
95
95
  ]
96
96
  },
97
+ {
98
+ "package": "bcp/jobs",
99
+ "source": "packages/client/src/jobs.ts",
100
+ "environment": "server",
101
+ "route": "/docs/api-reference#bcp-jobs",
102
+ "summary": "Background job queues plus recurring interval/cron scheduling, schedule-store leases and worker lifecycle APIs.",
103
+ "guides": [
104
+ "/docs/background-jobs",
105
+ "/docs/job-scheduling",
106
+ "/docs/observability"
107
+ ]
108
+ },
97
109
  {
98
110
  "package": "bcp/observability",
99
111
  "source": "packages/client/src/observability.ts",