@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 +106 -72
- package/docs/README.md +47 -139
- package/docs/api-manifest.json +13 -1
- package/docs/api-reference.md +55 -235
- package/docs/background-jobs.md +356 -0
- package/docs/docs-web-manifest.json +7 -3
- package/docs/job-scheduling.md +357 -0
- package/docs/platform-manifest.json +21 -4
- package/docs/releases/0.2.8.md +150 -0
- package/docs/releases/0.2.9.md +162 -0
- package/package.json +6 -1
- package/packages/bundler/src/client-boundary.ts +1 -0
- package/packages/client/src/jobs.mjs +1040 -0
- package/packages/client/src/jobs.ts +33 -0
- package/packages/server/src/job-scheduler.ts +1144 -0
- package/packages/server/src/jobs.ts +822 -0
package/docs/api-reference.md
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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,141 +60,75 @@ Related guides: [Database](database.md), [Database Migrations](database-migratio
|
|
|
166
60
|
|
|
167
61
|
Server-only authentication and authorization APIs.
|
|
168
62
|
|
|
169
|
-
|
|
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.
|
|
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.
|
|
216
64
|
|
|
217
|
-
|
|
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).
|
|
218
66
|
|
|
219
|
-
|
|
67
|
+
## `bcp/jobs`
|
|
220
68
|
|
|
221
|
-
-
|
|
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.
|
|
69
|
+
Server-only Background Jobs and Job Scheduling APIs.
|
|
226
70
|
|
|
227
|
-
|
|
71
|
+
Queue APIs:
|
|
228
72
|
|
|
229
|
-
|
|
73
|
+
```ts
|
|
74
|
+
import {
|
|
75
|
+
createJobQueue,
|
|
76
|
+
createMemoryJobQueueAdapter,
|
|
77
|
+
type BackgroundJobQueue,
|
|
78
|
+
type EnqueueJobOptions,
|
|
79
|
+
type JobHandler,
|
|
80
|
+
type JobHandlerContext,
|
|
81
|
+
type JobQueueAdapter,
|
|
82
|
+
type JobQueueOptions,
|
|
83
|
+
type JobRecord,
|
|
84
|
+
type JobRetryDelay,
|
|
85
|
+
type JobState,
|
|
86
|
+
type JobWorker,
|
|
87
|
+
type MemoryJobQueueAdapter,
|
|
88
|
+
type StartJobWorkerOptions,
|
|
89
|
+
} from "bcp/jobs";
|
|
90
|
+
```
|
|
230
91
|
|
|
231
|
-
|
|
92
|
+
Scheduling APIs added in `0.2.9`:
|
|
232
93
|
|
|
233
94
|
```ts
|
|
234
95
|
import {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
type
|
|
240
|
-
type
|
|
241
|
-
type
|
|
242
|
-
type
|
|
243
|
-
type
|
|
244
|
-
type
|
|
245
|
-
type
|
|
246
|
-
type
|
|
247
|
-
type
|
|
248
|
-
type
|
|
249
|
-
|
|
250
|
-
type MetricLabels,
|
|
251
|
-
type MetricLabelValue,
|
|
252
|
-
type MetricsRegistry,
|
|
253
|
-
type RequestMetricsOptions,
|
|
254
|
-
} 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";
|
|
255
111
|
```
|
|
256
112
|
|
|
257
|
-
`
|
|
113
|
+
`createJobQueue()` provides delayed enqueueing, retry/backoff, cancellation, manual `processNext()` execution and concurrent workers.
|
|
258
114
|
|
|
259
|
-
`
|
|
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.
|
|
260
116
|
|
|
261
|
-
The built-in
|
|
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.
|
|
262
118
|
|
|
263
|
-
|
|
119
|
+
Cron evaluation in `0.2.9` uses UTC. `nextCronTime()` and `nextScheduleTime()` are available for tooling and tests.
|
|
264
120
|
|
|
265
|
-
|
|
121
|
+
Related guides: [Background Jobs Platform](background-jobs.md), [Job Scheduling Platform](job-scheduling.md), [Observability Platform v2](observability.md).
|
|
266
122
|
|
|
267
|
-
|
|
123
|
+
## `bcp/observability`
|
|
268
124
|
|
|
269
|
-
|
|
125
|
+
Server-only Observability Platform v2 APIs for process-local counters, gauges, histograms, Prometheus exposition, request metrics middleware and health/readiness checks.
|
|
270
126
|
|
|
271
|
-
|
|
272
|
-
import {
|
|
273
|
-
clientIp,
|
|
274
|
-
cookies,
|
|
275
|
-
createCsrfToken,
|
|
276
|
-
createLocalStorage,
|
|
277
|
-
createLogger,
|
|
278
|
-
createS3Storage,
|
|
279
|
-
createStorageResponse,
|
|
280
|
-
destroyCsrfToken,
|
|
281
|
-
getProductionHardeningConfig,
|
|
282
|
-
headers,
|
|
283
|
-
isSafeHttpMethod,
|
|
284
|
-
isSameOriginRequest,
|
|
285
|
-
json,
|
|
286
|
-
redirect,
|
|
287
|
-
registerShutdownHook,
|
|
288
|
-
requestId,
|
|
289
|
-
requestMethod,
|
|
290
|
-
requestUrl,
|
|
291
|
-
requireCsrfRequest,
|
|
292
|
-
requireSameOriginRequest,
|
|
293
|
-
storeMultipartFile,
|
|
294
|
-
verifyCsrfRequest,
|
|
295
|
-
verifyCsrfToken,
|
|
296
|
-
RequestSecurityError,
|
|
297
|
-
type CsrfTokenOptions,
|
|
298
|
-
type SameOriginOptions,
|
|
299
|
-
type VerifyCsrfRequestOptions,
|
|
300
|
-
} from "bcp/server";
|
|
301
|
-
```
|
|
127
|
+
Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
|
|
302
128
|
|
|
303
|
-
|
|
129
|
+
## `bcp/server`
|
|
130
|
+
|
|
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.
|
|
304
132
|
|
|
305
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).
|
|
306
134
|
|
|
@@ -312,20 +140,12 @@ Server-only module boundary marker.
|
|
|
312
140
|
import "bcp/server-only";
|
|
313
141
|
```
|
|
314
142
|
|
|
315
|
-
Place this import in application modules that must never enter a browser bundle.
|
|
316
|
-
|
|
317
143
|
Related guide: [Application Modules](application-modules.md).
|
|
318
144
|
|
|
319
145
|
## `bcp/middleware`
|
|
320
146
|
|
|
321
147
|
Middleware System v2 APIs and types.
|
|
322
148
|
|
|
323
|
-
```ts
|
|
324
|
-
import type {
|
|
325
|
-
MiddlewarePipelineHandler,
|
|
326
|
-
} from "bcp/middleware";
|
|
327
|
-
```
|
|
328
|
-
|
|
329
149
|
Related guide: [Middleware](middleware.md).
|
|
330
150
|
|
|
331
151
|
## Stability
|