@nubjs/types 0.9.3 → 0.9.5
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/common.d.ts +36 -0
- package/package.json +1 -1
package/common.d.ts
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
// script file. (Adding `export {}` turns this into a module and silently breaks
|
|
17
17
|
// the data-import wildcards.) Globals are declared bare (`declare function …`,
|
|
18
18
|
// `declare var …`, `declare namespace …`) for the same reason.
|
|
19
|
+
//
|
|
20
|
+
// An `export` INSIDE a `declare module "…"` block is not that top-level export and
|
|
21
|
+
// does not convert the file — only a top-level one does. That is what lets the
|
|
22
|
+
// handler section at the bottom publish a named type from this same script.
|
|
19
23
|
|
|
20
24
|
// ── Data-format module imports (Nub load hook) ──
|
|
21
25
|
// Default export ONLY — data modules expose no named exports (a named import
|
|
@@ -295,3 +299,35 @@ interface Uint8ArrayConstructor {
|
|
|
295
299
|
interface Date {
|
|
296
300
|
toTemporalInstant(): Temporal.Instant;
|
|
297
301
|
}
|
|
302
|
+
|
|
303
|
+
// ── Default-export `fetch` handler (runtime/fetch-serve.cjs) ──
|
|
304
|
+
// A file whose default export has a `fetch` method is served over HTTP by
|
|
305
|
+
// `nub <file>`. Nothing checks that shape today, so a misspelled key or a handler
|
|
306
|
+
// returning the wrong thing makes the program exit with no error and no port bound;
|
|
307
|
+
// `satisfies ExportedHandler` turns each into a compile error.
|
|
308
|
+
//
|
|
309
|
+
// MODULE-SCOPED ON PURPOSE, and this is the one declaration here that must not be a
|
|
310
|
+
// global. Cloudflare owns a global `ExportedHandler` — `@cloudflare/workers-types`
|
|
311
|
+
// and `wrangler types --include-runtime` both put it in the global scope — and a
|
|
312
|
+
// second global declaration of that name MERGES with it. Measured against
|
|
313
|
+
// workers-types 5.20260914.1: the `fetch` members collide (TS2717, reported inside
|
|
314
|
+
// Cloudflare's own file), and under `skipLibCheck: true` the error disappears while
|
|
315
|
+
// Nub's signature silently wins, so Cloudflare's three-argument handlers start
|
|
316
|
+
// failing in the user's own source. Nothing can detect Cloudflare's declaration to
|
|
317
|
+
// step aside from it the way `Worker` steps aside from lib.dom — workers-types
|
|
318
|
+
// declares its distinctive globals with `const`/`class`, which never reach
|
|
319
|
+
// `typeof globalThis`. A module-scoped type cannot merge with a global at all, so
|
|
320
|
+
// the name is safe to share here and a project may use both types in one file.
|
|
321
|
+
//
|
|
322
|
+
// ONE argument. `fetch(request)` is the intersection of Workers' `(request, env,
|
|
323
|
+
// ctx)`, Bun's `(request, server)` and Deno's `(request, info)`; a second stays
|
|
324
|
+
// additive for whenever WinterTC's http-server proposal settles what belongs in it.
|
|
325
|
+
// No other key is read — the listener's address comes from `PORT` and `HOST` — so a
|
|
326
|
+
// Bun-style `port` or `hostname` key fails to compile here instead of being
|
|
327
|
+
// silently ignored at run time.
|
|
328
|
+
declare module "@nubjs/types" {
|
|
329
|
+
export type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
330
|
+
export interface ExportedHandler {
|
|
331
|
+
fetch: FetchHandler;
|
|
332
|
+
}
|
|
333
|
+
}
|