typenative 0.4.0 → 0.4.1

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 (44) hide show
  1. package/.github/workflows/ci.yml +2 -0
  2. package/CHANGELOG.md +201 -0
  3. package/CONTRIBUTION.md +1 -1
  4. package/bin/cli.js +1 -0
  5. package/bin/go/bridge.js +74 -14
  6. package/bin/go/convert.js +48 -0
  7. package/bin/go/metadata.js +13 -4
  8. package/bin/go/overrides.js +4 -6
  9. package/bin/go/stdlib.generated.js +2 -0
  10. package/bin/index.js +117 -0
  11. package/bin/main.js +1 -0
  12. package/bin/node/child_process.js +51 -3
  13. package/bin/node/cluster.js +41 -3
  14. package/bin/node/core.js +1 -1
  15. package/bin/node/crypto.js +205 -4
  16. package/bin/node/dgram.js +230 -6
  17. package/bin/node/dns.js +470 -7
  18. package/bin/node/errno_tables.js +445 -0
  19. package/bin/node/fs.js +21 -14
  20. package/bin/node/http.js +128 -30
  21. package/bin/node/http2.js +4 -1
  22. package/bin/node/module_v8.js +142 -0
  23. package/bin/node/net.js +9 -6
  24. package/bin/node/process.js +242 -0
  25. package/bin/node/readline.js +271 -0
  26. package/bin/node/registry.js +2 -1
  27. package/bin/node/sqlite.js +60 -12
  28. package/bin/node/stream.js +139 -7
  29. package/bin/node/test.js +311 -19
  30. package/bin/node/url.js +23 -5
  31. package/bin/node/util.js +18 -1
  32. package/bin/node/util_extra.js +6 -30
  33. package/bin/node/worker_threads.js +79 -19
  34. package/bin/transpiler.js +4019 -497
  35. package/bin/typecheck-node.js +1 -0
  36. package/bin/version.js +1 -1
  37. package/conformance.md +1025 -884
  38. package/examples/README.md +5 -5
  39. package/examples/json-server/README.md +31 -29
  40. package/examples/json-server/bench.mjs +130 -38
  41. package/package.json +1 -1
  42. package/types/typenative-go.d.ts +23 -0
  43. package/types/typenative-npm.d.ts +169 -5
  44. package/types/typenative.d.ts +185 -11
@@ -8,8 +8,11 @@ interface Boolean {}
8
8
 
9
9
  interface Function {
10
10
  readonly name: string;
11
+ readonly length: number;
11
12
  apply(thisArg: any, argArray?: any): any;
12
13
  call(thisArg: any, ...argArray: any[]): any;
14
+ /** `thisArg` is ignored for plain functions; the bound arguments are fixed */
15
+ bind(thisArg: any, ...argArray: any[]): any;
13
16
  }
14
17
 
15
18
  interface CallableFunction extends Function {}
@@ -24,6 +27,7 @@ interface Number {
24
27
  toString(radix?: number): string;
25
28
  toFixed(fractionDigits?: number): string;
26
29
  toPrecision(precision?: number): string;
30
+ toExponential(fractionDigits?: number): string;
27
31
  }
28
32
 
29
33
  interface Object {
@@ -61,7 +65,26 @@ interface IterableIterator<T, TReturn = any, TNext = undefined> extends Iterator
61
65
 
62
66
  interface Generator<T = any, TReturn = any, TNext = any> extends Iterator<T, TReturn, TNext> {
63
67
  [Symbol.iterator](): Generator<T, TReturn, TNext>;
64
- }
68
+ // ES2025 iterator helpers (lazy)
69
+ map<U>(callbackfn: (value: T, index: number) => U): Generator<U>;
70
+ filter(predicate: (value: T, index: number) => unknown): Generator<T>;
71
+ flatMap<U>(callback: (value: T, index: number) => U[]): Generator<U>;
72
+ take(limit: number): Generator<T>;
73
+ drop(count: number): Generator<T>;
74
+ toArray(): T[];
75
+ forEach(callbackfn: (value: T, index: number) => void): void;
76
+ some(predicate: (value: T, index: number) => unknown): boolean;
77
+ every(predicate: (value: T, index: number) => unknown): boolean;
78
+ find(predicate: (value: T, index: number) => unknown): T | undefined;
79
+ reduce<U>(callbackfn: (accumulator: U, value: T, index: number) => U, initialValue: U): U;
80
+ reduce(callbackfn: (accumulator: T, value: T, index: number) => T): T;
81
+ }
82
+
83
+ interface IteratorConstructor {
84
+ /** An iterator over an array or generator (with the iterator helpers) */
85
+ from<T>(source: T[] | Generator<T>): Generator<T>;
86
+ }
87
+ declare var Iterator: IteratorConstructor;
65
88
 
66
89
  interface AsyncIterator<T, TReturn = any, TNext = any> {
67
90
  next(...[value]: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
@@ -140,6 +163,12 @@ interface RegExpExecArray extends Array<string> {
140
163
  readonly groups: Record<string, string> | undefined;
141
164
  }
142
165
 
166
+ // match() result: .index is set unless the regex is /g (that returns every match)
167
+ interface RegExpMatchArray extends Array<string> {
168
+ index?: number;
169
+ readonly groups?: Record<string, string> | undefined;
170
+ }
171
+
143
172
  interface RegExpConstructor {
144
173
  new (pattern: string | RegExp, flags?: string): RegExp;
145
174
  (pattern: string | RegExp, flags?: string): RegExp;
@@ -149,6 +178,14 @@ declare var RegExp: RegExpConstructor;
149
178
 
150
179
  // --- Array ---
151
180
 
181
+ /** import data from './data.json' with { type: 'json' } */
182
+ interface ImportAttributes {
183
+ [key: string]: string;
184
+ }
185
+
186
+ /** readonly T[] / ReadonlyArray<T> (mutating methods are not hidden) */
187
+ interface ReadonlyArray<T> extends Array<T> {}
188
+
152
189
  interface Array<T> extends IterableIterator<T> {
153
190
  /**
154
191
  * Gets or sets the length of the array. This is a number one higher than the highest index in the array.
@@ -308,6 +345,7 @@ interface ArrayConstructor {
308
345
  isArray(arg: any): arg is any[];
309
346
  from<T>(arrayLike: ArrayLike<T>): T[];
310
347
  from<T, U>(arrayLike: ArrayLike<T>, mapFn: (value: T, index: number) => U): U[];
348
+ of<T>(...items: T[]): T[];
311
349
  }
312
350
 
313
351
  declare var Array: ArrayConstructor;
@@ -324,7 +362,17 @@ interface String {
324
362
  /** Returns the position of the first occurrence of a substring. */
325
363
  indexOf(searchString: string, position?: number): number;
326
364
  /** Returns the position of the last occurrence of a substring. */
327
- lastIndexOf(searchString: string): number;
365
+ lastIndexOf(searchString: string, position?: number): number;
366
+ /** The code point at a (code point) index; NaN past the end */
367
+ codePointAt(pos: number): number;
368
+ /** Deprecated: `length` characters from `from` */
369
+ substr(from: number, length?: number): string;
370
+ trimLeft(): string;
371
+ trimRight(): string;
372
+ toLocaleUpperCase(locales?: string | string[]): string;
373
+ toLocaleLowerCase(locales?: string | string[]): string;
374
+ isWellFormed(): boolean;
375
+ toWellFormed(): string;
328
376
  /** Determines whether a string contains the specified substring. */
329
377
  includes(searchString: string): boolean;
330
378
  /** Determines whether a string begins with the specified characters. */
@@ -332,7 +380,7 @@ interface String {
332
380
  /** Determines whether a string ends with the specified characters. */
333
381
  endsWith(searchString: string): boolean;
334
382
  /** Splits a string into substrings using the specified separator. */
335
- split(separator: string | RegExp): string[];
383
+ split(separator: string | RegExp, limit?: number): string[];
336
384
  /** Removes whitespace from both ends of a string. */
337
385
  trim(): string;
338
386
  /** Removes whitespace from the beginning of a string. */
@@ -361,9 +409,9 @@ interface String {
361
409
  /** Pads the end of a string with another string to a total length. */
362
410
  padEnd(targetLength: number, padString?: string): string;
363
411
  /** Matches a string against a regex and returns the matches. */
364
- match(regexp: string | RegExp): string[] | null;
412
+ match(regexp: string | RegExp): RegExpMatchArray | null;
365
413
  /** Matches all occurrences of a regex. */
366
- matchAll(regexp: string | RegExp): string[][];
414
+ matchAll(regexp: string | RegExp): RegExpExecArray[];
367
415
  /** Searches for a match and returns the index. */
368
416
  search(regexp: string | RegExp): number;
369
417
  /** Returns the character at the given index (supports negative indices). */
@@ -382,6 +430,7 @@ interface String {
382
430
  interface StringConstructor {
383
431
  (value?: any): string;
384
432
  fromCharCode(...charCodes: number[]): string;
433
+ fromCodePoint(...codePoints: number[]): string;
385
434
  raw(strings: TemplateStringsArray, ...values: any[]): string;
386
435
  }
387
436
 
@@ -395,7 +444,12 @@ interface NumberConstructor {
395
444
  readonly MAX_SAFE_INTEGER: number;
396
445
  readonly MIN_SAFE_INTEGER: number;
397
446
  readonly MAX_VALUE: number;
447
+ readonly MIN_VALUE: number;
398
448
  readonly POSITIVE_INFINITY: number;
449
+ readonly NEGATIVE_INFINITY: number;
450
+ isSafeInteger(value: number): boolean;
451
+ parseInt(string: string, radix?: number): number;
452
+ parseFloat(string: string): number;
399
453
  readonly EPSILON: number;
400
454
  readonly NaN: number;
401
455
  }
@@ -459,6 +513,13 @@ interface Math {
459
513
  sinh(x: number): number;
460
514
  cosh(x: number): number;
461
515
  tanh(x: number): number;
516
+ asinh(x: number): number;
517
+ acosh(x: number): number;
518
+ atanh(x: number): number;
519
+ fround(x: number): number;
520
+ imul(a: number, b: number): number;
521
+ clz32(x: number): number;
522
+ sumPrecise(values: number[]): number;
462
523
  cbrt(x: number): number;
463
524
  hypot(...values: number[]): number;
464
525
  trunc(x: number): number;
@@ -503,12 +564,19 @@ declare function queueMicrotask(callback: () => void): void;
503
564
  // --- JSON / Object / process ---
504
565
 
505
566
  interface JSON {
506
- stringify(value: any, replacer?: any, space?: number | string): string;
507
- parse(text: string): any;
567
+ stringify(
568
+ value: any,
569
+ replacer?: ((key: string, value: any) => any) | (string | number)[] | null,
570
+ space?: number | string
571
+ ): string;
572
+ parse(text: string, reviver?: (key: string, value: any) => any): any;
508
573
  }
509
574
  declare var JSON: JSON;
510
575
 
511
576
  interface ObjectConstructor {
577
+ /** SameValue: NaN is NaN, +0 is not -0 */
578
+ is(a: any, b: any): boolean;
579
+ groupBy<T>(items: T[], keySelector: (item: T, index: number) => string | number): Record<string, T[]>;
512
580
  keys(obj: any): string[];
513
581
  values(obj: any): any[];
514
582
  entries(obj: any): [string, any][];
@@ -530,6 +598,15 @@ interface ObjectConstructor {
530
598
  }
531
599
  declare var Object: ObjectConstructor;
532
600
 
601
+ /** process.stdout / stderr terminal info: 0 columns and rows when not a terminal */
602
+ interface TnTtyOutput {
603
+ readonly isTTY?: boolean;
604
+ readonly columns: number;
605
+ readonly rows: number;
606
+ /** [columns, rows] */
607
+ getWindowSize(): [number, number];
608
+ }
609
+
533
610
  interface Process {
534
611
  argv: string[];
535
612
  readonly argv0: string;
@@ -585,9 +662,22 @@ interface Process {
585
662
  on(event: 'uncaughtException' | 'uncaughtExceptionMonitor', listener: (error: Error, origin: 'uncaughtException' | 'unhandledRejection') => void): this;
586
663
  on(event: 'unhandledRejection', listener: (reason: unknown, promise: Promise<unknown>) => void): this;
587
664
  on(event: 'beforeExit', listener: (code: number) => void): this;
588
- readonly stdout: import('node:stream').Writable & { readonly isTTY?: boolean; readonly fd: 1 };
589
- readonly stderr: import('node:stream').Writable & { readonly isTTY?: boolean; readonly fd: 2 };
590
- readonly stdin: import('node:stream').Readable & { readonly isTTY?: boolean; readonly fd: 0 };
665
+ readonly stdout: import('node:stream').Writable & TnTtyOutput & { readonly fd: 1 };
666
+ readonly stderr: import('node:stream').Writable & TnTtyOutput & { readonly fd: 2 };
667
+ readonly stdin: {
668
+ /** After readline.emitKeypressEvents(process.stdin) */
669
+ on(event: 'keypress', listener: (str: string, key: import('node:readline').Key) => void): import('node:stream').Readable;
670
+ once(event: 'keypress', listener: (str: string, key: import('node:readline').Key) => void): import('node:stream').Readable;
671
+ } & import('node:stream').Readable & {
672
+ readonly isTTY?: boolean;
673
+ readonly fd: 0;
674
+ /** Whether raw mode is on */
675
+ readonly isRaw: boolean;
676
+ /** Raw mode (no echo, no line buffering, Ctrl+C as a byte); throws when stdin is not a terminal */
677
+ setRawMode(mode: boolean): void;
678
+ };
679
+ /** The file mode creation mask; with an argument sets it and returns the previous one (0 on Windows) */
680
+ umask(mask?: number | string): number;
591
681
  on(event: 'exit', listener: (code: number) => void): this;
592
682
  on(event: string, listener: (...args: any[]) => void): this;
593
683
  once(event: 'exit', listener: (code: number) => void): this;
@@ -634,6 +724,17 @@ type TypeError = Error;
634
724
  type RangeError = Error;
635
725
  type SyntaxError = Error;
636
726
 
727
+ interface AggregateError extends Error {
728
+ errors: any[];
729
+ }
730
+
731
+ interface AggregateErrorConstructor {
732
+ new (errors: Iterable<any>, message?: string, options?: ErrorOptions): AggregateError;
733
+ (errors: Iterable<any>, message?: string, options?: ErrorOptions): AggregateError;
734
+ }
735
+
736
+ declare var AggregateError: AggregateErrorConstructor;
737
+
637
738
  interface Date {
638
739
  getTime(): number;
639
740
  valueOf(): number;
@@ -658,11 +759,45 @@ interface Date {
658
759
  toString(): string;
659
760
  toDateString(): string;
660
761
  toTimeString(): string;
762
+ toUTCString(): string;
763
+ toGMTString(): string;
764
+ /** en-US format; locales and options are ignored */
765
+ toLocaleDateString(locales?: string | string[], options?: any): string;
766
+ /** en-US format; locales and options are ignored */
767
+ toLocaleTimeString(locales?: string | string[], options?: any): string;
768
+ /** en-US format; locales and options are ignored */
769
+ toLocaleString(locales?: string | string[], options?: any): string;
770
+ getTimezoneOffset(): number;
771
+ setTime(time: number): number;
772
+ setFullYear(year: number, month?: number, date?: number): number;
773
+ setMonth(month: number, date?: number): number;
774
+ setDate(date: number): number;
775
+ setHours(hours: number, min?: number, sec?: number, ms?: number): number;
776
+ setMinutes(min: number, sec?: number, ms?: number): number;
777
+ setSeconds(sec: number, ms?: number): number;
778
+ setMilliseconds(ms: number): number;
779
+ setUTCFullYear(year: number, month?: number, date?: number): number;
780
+ setUTCMonth(month: number, date?: number): number;
781
+ setUTCDate(date: number): number;
782
+ setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number;
783
+ setUTCMinutes(min: number, sec?: number, ms?: number): number;
784
+ setUTCSeconds(sec: number, ms?: number): number;
785
+ setUTCMilliseconds(ms: number): number;
661
786
  }
662
787
 
663
788
  interface DateConstructor {
664
789
  new (): Date;
665
- new (ms: number): Date;
790
+ new (value: number | string | Date): Date;
791
+ new (
792
+ year: number,
793
+ monthIndex: number,
794
+ date?: number,
795
+ hours?: number,
796
+ minutes?: number,
797
+ seconds?: number,
798
+ ms?: number
799
+ ): Date;
800
+ parse(s: string): number;
666
801
  now(): number;
667
802
  UTC(
668
803
  year: number,
@@ -701,6 +836,28 @@ interface PromiseConstructor {
701
836
  race<T>(values: Promise<T>[]): Promise<T>;
702
837
  any<T>(values: Promise<T>[]): Promise<T>;
703
838
  allSettled<T>(values: Promise<T>[]): Promise<{ status: string; value?: T; reason?: any }[]>;
839
+ withResolvers<T>(): PromiseWithResolvers<T>;
840
+ try<T>(fn: (...args: any[]) => T | Promise<T>, ...args: any[]): Promise<T>;
841
+ }
842
+
843
+ interface WeakRef<T extends object> {
844
+ /** The target, or undefined once it was garbage-collected */
845
+ deref(): T | undefined;
846
+ }
847
+ declare var WeakRef: { new <T extends object>(target: T): WeakRef<T> };
848
+
849
+ interface FinalizationRegistry<T> {
850
+ register(target: object, heldValue: T, unregisterToken?: object): void;
851
+ unregister(unregisterToken: object): boolean;
852
+ }
853
+ declare var FinalizationRegistry: {
854
+ new <T>(cleanupCallback: (heldValue: T) => void): FinalizationRegistry<T>;
855
+ };
856
+
857
+ interface PromiseWithResolvers<T> {
858
+ promise: Promise<T>;
859
+ resolve: (value: T) => void;
860
+ reject: (reason?: any) => void;
704
861
  }
705
862
 
706
863
  declare var Promise: PromiseConstructor;
@@ -726,6 +883,8 @@ interface Map<K, V> {
726
883
  keys(): K[];
727
884
  /** The values, in insertion order. */
728
885
  values(): V[];
886
+ /** The [key, value] pairs, in insertion order. */
887
+ entries(): [K, V][];
729
888
  /** Iterates [key, value] pairs in insertion order. */
730
889
  [Symbol.iterator](): IterableIterator<[K, V]>;
731
890
  }
@@ -733,6 +892,7 @@ interface Map<K, V> {
733
892
  interface MapConstructor {
734
893
  new <K, V>(): Map<K, V>;
735
894
  new <K, V>(entries: [K, V][]): Map<K, V>;
895
+ groupBy<K, T>(items: T[], keySelector: (item: T, index: number) => K): Map<K, T[]>;
736
896
  }
737
897
 
738
898
  declare var Map: MapConstructor;
@@ -805,10 +965,16 @@ interface SymbolConstructor {
805
965
  readonly iterator: unique symbol;
806
966
  readonly asyncIterator: unique symbol;
807
967
  readonly dispose: unique symbol;
968
+ for(key: string): symbol;
969
+ keyFor(sym: symbol): string | undefined;
808
970
  }
809
971
 
810
972
  declare var Symbol: SymbolConstructor;
811
973
 
974
+ interface Symbol {
975
+ readonly description: string;
976
+ }
977
+
812
978
  // --- Decorators (class and class-method decorators are lowered) ---
813
979
 
814
980
  interface ClassDecoratorContext<Class extends abstract new (...args: any) => any = abstract new (...args: any) => any> {
@@ -837,6 +1003,14 @@ interface BigInt {
837
1003
  toString(radix?: number): string;
838
1004
  }
839
1005
 
1006
+ interface BigIntConstructor {
1007
+ (value: bigint | boolean | number | string): bigint;
1008
+ asIntN(bits: number, int: bigint): bigint;
1009
+ asUintN(bits: number, int: bigint): bigint;
1010
+ }
1011
+
1012
+ declare var BigInt: BigIntConstructor;
1013
+
840
1014
  // --- Node.js globals (Buffer, URL, TextEncoder, AbortController, performance, …) ---
841
1015
 
842
1016
  type BufferEncoding =