@nubjs/types 0.9.3 → 0.9.6

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.
Files changed (2) hide show
  1. package/common.d.ts +44 -6
  2. 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
@@ -172,14 +176,16 @@ interface ImportMeta {
172
176
  // future standard lib adds them. The one property member (`Symbol.metadata`) is
173
177
  // byte-for-byte TypeScript's already-settled `lib.esnext.decorators` declaration.
174
178
 
175
- // Iterator chunking/includes/join. `IteratorObject` is in lib.es2015.iterable even
176
- // when the ES2025 Iterator constructor is not selected, so built-in iterators gain
177
- // these methods at the ES2024 target too. The versioned package entry point loads
178
- // TypeScript's own Iterator constructor and base-helper declarations.
179
+ // Iterator chunking/includes/join (Stage 4, 2026-09). `IteratorObject` is in
180
+ // lib.es2015.iterable even when the ES2025 Iterator constructor is not selected, so
181
+ // built-in iterators gain these methods at the ES2024 target too. The versioned
182
+ // package entry point loads TypeScript's own Iterator constructor and base-helper
183
+ // declarations. The sizes and skip count are not coerced at runtime: a non-integral
184
+ // number is a TypeError.
179
185
  interface IteratorObject<T, TReturn, TNext> {
180
186
  chunks(chunkSize: number): IteratorObject<T[], undefined, unknown>;
181
- windows(windowSize: number): IteratorObject<T[], undefined, unknown>;
182
- includes(searchElement: T): boolean;
187
+ windows(windowSize: number, undersized?: "only-full" | "allow-partial"): IteratorObject<T[], undefined, unknown>;
188
+ includes(searchElement: T, skippedElements?: number): boolean;
183
189
  join(separator?: string): string;
184
190
  }
185
191
 
@@ -295,3 +301,35 @@ interface Uint8ArrayConstructor {
295
301
  interface Date {
296
302
  toTemporalInstant(): Temporal.Instant;
297
303
  }
304
+
305
+ // ── Default-export `fetch` handler (runtime/fetch-serve.cjs) ──
306
+ // A file whose default export has a `fetch` method is served over HTTP by
307
+ // `nub <file>`. Nothing checks that shape today, so a misspelled key or a handler
308
+ // returning the wrong thing makes the program exit with no error and no port bound;
309
+ // `satisfies ExportedHandler` turns each into a compile error.
310
+ //
311
+ // MODULE-SCOPED ON PURPOSE, and this is the one declaration here that must not be a
312
+ // global. Cloudflare owns a global `ExportedHandler` — `@cloudflare/workers-types`
313
+ // and `wrangler types --include-runtime` both put it in the global scope — and a
314
+ // second global declaration of that name MERGES with it. Measured against
315
+ // workers-types 5.20260914.1: the `fetch` members collide (TS2717, reported inside
316
+ // Cloudflare's own file), and under `skipLibCheck: true` the error disappears while
317
+ // Nub's signature silently wins, so Cloudflare's three-argument handlers start
318
+ // failing in the user's own source. Nothing can detect Cloudflare's declaration to
319
+ // step aside from it the way `Worker` steps aside from lib.dom — workers-types
320
+ // declares its distinctive globals with `const`/`class`, which never reach
321
+ // `typeof globalThis`. A module-scoped type cannot merge with a global at all, so
322
+ // the name is safe to share here and a project may use both types in one file.
323
+ //
324
+ // ONE argument. `fetch(request)` is the intersection of Workers' `(request, env,
325
+ // ctx)`, Bun's `(request, server)` and Deno's `(request, info)`; a second stays
326
+ // additive for whenever WinterTC's http-server proposal settles what belongs in it.
327
+ // No other key is read — the listener's address comes from `PORT` and `HOST` — so a
328
+ // Bun-style `port` or `hostname` key fails to compile here instead of being
329
+ // silently ignored at run time.
330
+ declare module "@nubjs/types" {
331
+ export type FetchHandler = (request: Request) => Response | Promise<Response>;
332
+ export interface ExportedHandler {
333
+ fetch: FetchHandler;
334
+ }
335
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubjs/types",
3
- "version": "0.9.3",
3
+ "version": "0.9.6",
4
4
  "description": "TypeScript ambient declarations for code authored against the Nub runtime",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/nubjs/nub",