@pramen/server 0.0.19 → 0.0.20
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/dist/pramen.d.ts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +9 -2
- package/package.json +1 -1
- package/src/pramen.ts +1 -1
- package/src/worker.ts +8 -2
package/dist/pramen.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export type { Env, DoEnv };
|
|
|
47
47
|
* drains the D1 outbox (the DO path self-drains via an alarm) — wire it only if you
|
|
48
48
|
* use the D1 store with deferred tasks. */
|
|
49
49
|
export declare function createPramen(app: PramenApp): {
|
|
50
|
-
fetch: (request: Request, env: Env) => Promise<Response>;
|
|
50
|
+
fetch: (request: Request, env: Env, ctx: ExecutionContext) => Promise<Response>;
|
|
51
51
|
scheduled: (event: unknown, env: Env) => Promise<void>;
|
|
52
52
|
queue: (batch: QueueBatch, env: Env) => Promise<void>;
|
|
53
53
|
PramenDO: ReturnType<typeof pramenDO>;
|
package/dist/worker.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export declare function callPrivileged(env: Env, opts: {
|
|
|
73
73
|
/** Build the Worker fetch handler for an app. State (the JWKS cache, the D1
|
|
74
74
|
* compiled-ACL + one-time migration) is per-app, held in this closure. */
|
|
75
75
|
export declare function makeWorker(app: PramenApp): {
|
|
76
|
-
fetch(request: Request, env: Env): Promise<Response>;
|
|
76
|
+
fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
77
77
|
scheduled(_event: unknown, env: Env): Promise<void>;
|
|
78
78
|
queue(batch: QueueBatch, env: Env): Promise<void>;
|
|
79
79
|
};
|
package/dist/worker.js
CHANGED
|
@@ -172,7 +172,7 @@ export function makeWorker(app) {
|
|
|
172
172
|
return listTasks(driver, { status, limit });
|
|
173
173
|
};
|
|
174
174
|
return {
|
|
175
|
-
async fetch(request, env) {
|
|
175
|
+
async fetch(request, env, ctx) {
|
|
176
176
|
const url = new URL(request.url);
|
|
177
177
|
// File upload/download stream through the Worker (bytes never touch the DO),
|
|
178
178
|
// authorized purely by the HMAC token in the url — no JWT/tenant routing.
|
|
@@ -384,7 +384,14 @@ export function makeWorker(app) {
|
|
|
384
384
|
const envBag = env;
|
|
385
385
|
try {
|
|
386
386
|
await ensureD1Migrated(driver, env.PRAMEN_ALLOW_DESTRUCTIVE === "true");
|
|
387
|
-
const { result } = await dispatch(app.handlers, app.schema, driver, new Kv(env.KV), files, envBag, { acl: d1Acl, identity }, name, input);
|
|
387
|
+
const { result, enqueued } = await dispatch(app.handlers, app.schema, driver, new Kv(env.KV), files, envBag, { acl: d1Acl, identity }, name, input);
|
|
388
|
+
// Kick an immediate drain in the request tail when this handler enqueued tasks
|
|
389
|
+
// (e.g. sendMagicLinkEmail). Without this, tasks wait for the next Cron trigger
|
|
390
|
+
// — up to a full minute. `waitUntil` lets the response return now while the
|
|
391
|
+
// drain runs; the Cron trigger remains the safety net for delayed / retried
|
|
392
|
+
// tasks that no request happens to coincide with.
|
|
393
|
+
if (enqueued > 0)
|
|
394
|
+
ctx.waitUntil(drainD1(env));
|
|
388
395
|
const res = json({ ok: true, result });
|
|
389
396
|
// Thread the session's latest bookmark back so the client can read its own writes.
|
|
390
397
|
const bookmark = driver.getBookmark();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pramen/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "pramen server runtime — schema, ACL, ORM, live queries, files, and the createPramen(app) factory for Cloudflare Workers + Durable Objects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/pramen.ts
CHANGED
|
@@ -61,7 +61,7 @@ export type { Env, DoEnv };
|
|
|
61
61
|
* drains the D1 outbox (the DO path self-drains via an alarm) — wire it only if you
|
|
62
62
|
* use the D1 store with deferred tasks. */
|
|
63
63
|
export function createPramen(app: PramenApp): {
|
|
64
|
-
fetch: (request: Request, env: Env) => Promise<Response>;
|
|
64
|
+
fetch: (request: Request, env: Env, ctx: ExecutionContext) => Promise<Response>;
|
|
65
65
|
scheduled: (event: unknown, env: Env) => Promise<void>;
|
|
66
66
|
queue: (batch: QueueBatch, env: Env) => Promise<void>;
|
|
67
67
|
PramenDO: ReturnType<typeof pramenDO>;
|
package/src/worker.ts
CHANGED
|
@@ -236,7 +236,7 @@ export function makeWorker(app: PramenApp) {
|
|
|
236
236
|
};
|
|
237
237
|
|
|
238
238
|
return {
|
|
239
|
-
async fetch(request: Request, env: Env): Promise<Response> {
|
|
239
|
+
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
|
240
240
|
const url = new URL(request.url);
|
|
241
241
|
|
|
242
242
|
// File upload/download stream through the Worker (bytes never touch the DO),
|
|
@@ -458,7 +458,13 @@ export function makeWorker(app: PramenApp) {
|
|
|
458
458
|
const envBag = env as unknown as Record<string, unknown>;
|
|
459
459
|
try {
|
|
460
460
|
await ensureD1Migrated(driver, env.PRAMEN_ALLOW_DESTRUCTIVE === "true");
|
|
461
|
-
const { result } = await dispatch(app.handlers, app.schema, driver, new Kv(env.KV), files, envBag, { acl: d1Acl, identity }, name, input);
|
|
461
|
+
const { result, enqueued } = await dispatch(app.handlers, app.schema, driver, new Kv(env.KV), files, envBag, { acl: d1Acl, identity }, name, input);
|
|
462
|
+
// Kick an immediate drain in the request tail when this handler enqueued tasks
|
|
463
|
+
// (e.g. sendMagicLinkEmail). Without this, tasks wait for the next Cron trigger
|
|
464
|
+
// — up to a full minute. `waitUntil` lets the response return now while the
|
|
465
|
+
// drain runs; the Cron trigger remains the safety net for delayed / retried
|
|
466
|
+
// tasks that no request happens to coincide with.
|
|
467
|
+
if (enqueued > 0) ctx.waitUntil(drainD1(env));
|
|
462
468
|
const res = json({ ok: true, result });
|
|
463
469
|
// Thread the session's latest bookmark back so the client can read its own writes.
|
|
464
470
|
const bookmark = driver.getBookmark();
|