@nubjs/types 0.7.5 → 0.8.0

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 CHANGED
@@ -17,7 +17,7 @@
17
17
  // the data-import wildcards.) Globals are declared bare (`declare function …`,
18
18
  // `declare var …`, `declare namespace …`) for the same reason.
19
19
 
20
- // ── Data-format module imports (Nub load hook; wiki/runtime/data-loaders.md) ──
20
+ // ── Data-format module imports (Nub load hook) ──
21
21
  // Default export ONLY — data modules expose no named exports (a named import
22
22
  // like `import { host } from "./c.yaml"` is a load-time error on nub, the same
23
23
  // as Node's JSON modules). The object formats default to `Record<string,
@@ -81,7 +81,7 @@ type __NubUseLibDomIfAvailable<GlobalThisKeyName extends PropertyKey, Otherwise>
81
81
  : Otherwise
82
82
  : Otherwise;
83
83
 
84
- // ── Browser-shape Worker global (runtime/worker-polyfill.mjs; wiki/runtime/web-worker.md) ──
84
+ // ── Browser-shape Worker global (runtime/worker-polyfill.mjs) ──
85
85
  // Nub ships the WHATWG/browser subset of `Worker` over node:worker_threads.Worker.
86
86
  // @types/node has NO global `Worker` (only node:worker_threads' class), so this is
87
87
  // the genuine gap. `MessageEvent`, `ErrorEvent`, and `MessagePort` are ALREADY
@@ -148,7 +148,7 @@ declare var Worker: __NubUseLibDomIfAvailable<
148
148
  }
149
149
  >;
150
150
 
151
- // ── import.meta.hot (Vite-compatible; wiki/runtime/hot-mode.md — v0.x, shape committed v0.1) ──
151
+ // ── import.meta.hot (Vite-compatible — v0.x, shape committed v0.1) ──
152
152
  // Forward-compat commitment: ships now so framework authors can code against the
153
153
  // shape. `import.meta.hot` is `undefined` unless `nub watch --hot` is active.
154
154
  interface ImportMeta {
@@ -187,6 +187,60 @@ interface Math {
187
187
  sumPrecise(items: Iterable<number>): number;
188
188
  }
189
189
 
190
+ // Iterator.concat (Stage 4; native only on Node 26+, polyfilled below). TypeScript's
191
+ // iterator libraries declare `from` and the helpers on IteratorConstructor but not
192
+ // this, so no `reference lib` reaches it on any version. The sibling statics Nub also
193
+ // installs — `zip` and `zipKeyed` — are deliberately still absent: their element type
194
+ // depends on the `mode` option ("longest" pads with undefined), so declaring them
195
+ // honestly needs mode-discriminated overloads, which is its own change.
196
+ interface IteratorConstructor {
197
+ // The element type DISTRIBUTES over the sources — `concat<T>(...items:
198
+ // Iterable<T>[])` would bind T to the first argument and reject a differently
199
+ // typed second one, which the runtime accepts (it just delegates with `yield*`).
200
+ concat<T extends readonly Iterable<unknown>[]>(
201
+ ...items: T
202
+ ): IteratorObject<T[number] extends Iterable<infer U> ? U : never, undefined, unknown>;
203
+ }
204
+
205
+ // Polyfilled members declared HERE rather than reached through a `reference lib`,
206
+ // because no library spans every TypeScript this package serves. `escape` and
207
+ // `getOrInsert` have no library below TypeScript 6 at all. `isError` is the sharper
208
+ // case: `lib.esnext.error` does not exist before TypeScript 5.9, and an unknown lib
209
+ // name is a hard TS2726 that fails the consumer's WHOLE build — so referencing it
210
+ // from the `<=5.9` entry point broke every TypeScript 5.7/5.8 consumer outright.
211
+ // Declaring all three in this shared file covers both entry points at once, which
212
+ // is why neither references lib.es2025.regexp, lib.esnext.collection or
213
+ // lib.esnext.error. Signatures match TypeScript 6's exactly, so a 6+ consumer
214
+ // merges identical members rather than gaining a second, divergent overload.
215
+ interface RegExpConstructor {
216
+ escape(string: string): string;
217
+ }
218
+
219
+ interface ErrorConstructor {
220
+ isError(error: unknown): error is Error;
221
+ }
222
+
223
+ // `Promise.try` is the fourth: TypeScript 5.7 resolves `esnext.promise` to a library
224
+ // that predates it, so the reference is silently empty there rather than an error.
225
+ interface PromiseConstructor {
226
+ try<T, U extends unknown[]>(
227
+ callbackFn: (...args: U) => T | PromiseLike<T>,
228
+ ...args: U
229
+ ): Promise<Awaited<T>>;
230
+ }
231
+
232
+ // Nub installs both methods on BOTH constructors (runtime/polyfills.cjs
233
+ // `installMapGetOrInsert`), so both are declared; the proposal's original `upsert`
234
+ // name is deliberately absent, matching every runtime that shipped this.
235
+ interface Map<K, V> {
236
+ getOrInsert(key: K, defaultValue: V): V;
237
+ getOrInsertComputed(key: K, callback: (key: K) => V): V;
238
+ }
239
+ interface WeakMap<K extends WeakKey, V> {
240
+ getOrInsert(key: K, defaultValue: V): V;
241
+ getOrInsertComputed(key: K, callback: (key: K) => V): V;
242
+ }
243
+
190
244
  interface SymbolConstructor {
191
245
  readonly metadata: unique symbol;
192
246
  }
package/index.d.ts CHANGED
@@ -1,9 +1,27 @@
1
1
  // @nubjs/types — TypeScript 6+ entry point.
2
2
  //
3
- // TypeScript 6 ships the official Temporal declarations. Reference that focused
4
- // library even when a consumer targets ES2024, then layer Nub's additive runtime
5
- // augmentations from common.d.ts on top. Keeping this file a global script is
6
- // intentional; see common.d.ts for the data-import wildcard invariant.
3
+ // Every `reference lib` below names a library TypeScript already ships for a
4
+ // feature Nub GUARANTEES across its whole Node floor native where the running
5
+ // Node has it, polyfilled below (feature_matrix.rs gives the band per feature).
6
+ // Pulling the focused libraries in HERE is what lets a consumer keep
7
+ // `lib: ["es2024"]` — the target `nub init` scaffolds — and still type that
8
+ // surface, rather than raising `lib` to `esnext` and picking up features Nub does
9
+ // not provide at all. Nub then layers its additive runtime augmentations from
10
+ // common.d.ts on top. Keeping this file a global script is intentional; see
11
+ // common.d.ts for the data-import wildcard invariant.
12
+ //
13
+ // A library reference is only safe where the name resolves in EVERY TypeScript the
14
+ // entry point serves: an unknown one is a hard TS2726 that fails the consumer's
15
+ // whole build. TypeScript keeps a promoted library's old name working as an alias
16
+ // (7.0 ships no lib.esnext.array.d.ts yet still resolves `esnext.array`), so the
17
+ // risk is a name that does not exist YET, not one that has moved. Anything a
18
+ // supported TypeScript lacks is hand-declared in common.d.ts instead — which is
19
+ // also why nothing here references lib.es2025.regexp, lib.esnext.collection,
20
+ // lib.esnext.error or lib.es2025.promise: common.d.ts already carries their whole
21
+ // contents. `es2025.collection` is a different library from `esnext.collection` —
22
+ // it holds the Set methods, which common.d.ts does not declare.
7
23
  /// <reference lib="esnext.temporal" />
8
24
  /// <reference lib="es2025.iterator" />
25
+ /// <reference lib="es2025.collection" />
26
+ /// <reference lib="esnext.array" />
9
27
  /// <reference path="./common.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubjs/types",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
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",
package/ts5.9/index.d.ts CHANGED
@@ -1,8 +1,19 @@
1
1
  // TypeScript 5.9 fallback entry point for @nubjs/types.
2
- // Common Nub augmentations stay shared; only Temporal is version-routed because
2
+ // Common Nub augmentations stay shared; Temporal is version-routed because
3
3
  // TypeScript 6 added an official lib.esnext.temporal whose type aliases cannot merge.
4
+ // The library references cover the same features as index.d.ts. Two are spelled
5
+ // differently because TypeScript 5.9 has not yet moved the ratified ES2025 features
6
+ // out of `esnext.*`: `esnext.collection` here is TypeScript 6's `es2025.collection`,
7
+ // and `esnext.iterator` its `es2025.iterator`. Everything else is hand-declared in
8
+ // common.d.ts, which is what keeps both entry points describing ONE surface. That
9
+ // matters most for `Error.isError`: `lib.esnext.error` does not exist before
10
+ // TypeScript 5.9, and `typesVersions` routes every TypeScript at or below 5.9 here —
11
+ // so referencing it broke 5.7 and 5.8 consumers with a TS2726 that failed their
12
+ // whole build, which is why the package now declares that member by hand.
4
13
  /// <reference path="../common.d.ts" />
5
14
  /// <reference lib="esnext.iterator" />
15
+ /// <reference lib="esnext.array" />
16
+ /// <reference lib="esnext.collection" />
6
17
 
7
18
  // ── Temporal (vendored @js-temporal/polyfill@0.5.1; runtime/preload-common.cjs) ──
8
19
  // TypeScript <=5.9 has no official Temporal library. The namespace below is