Skip to content

Commit

Permalink
chore(deps): update dependency typescript to v5.6.3 (#1644)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Arda TANRIKULU <[email protected]>
  • Loading branch information
renovate[bot] and ardatan authored Nov 2, 2024
1 parent 7513cd7 commit 637185f
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-lions-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/server': patch
---

Respect given fetchAPI
5 changes: 5 additions & 0 deletions .changeset/red-vans-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/node-fetch': minor
---

Support `IteratorObject<T>`
2 changes: 1 addition & 1 deletion e2e/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"esbuild": "0.24.0",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.5.4"
"typescript": "5.6.3"
}
}
2 changes: 1 addition & 1 deletion e2e/azure-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"esbuild": "0.24.0",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.5.4"
"typescript": "5.6.3"
}
}
2 changes: 1 addition & 1 deletion e2e/bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"bun-types": "1.1.34"
},
"devDependencies": {
"typescript": "5.5.4"
"typescript": "5.6.3"
}
}
2 changes: 1 addition & 1 deletion e2e/cloudflare-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@pulumi/pulumi": "3.137.0",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.5.4",
"typescript": "5.6.3",
"wrangler": "3.84.1"
}
}
2 changes: 1 addition & 1 deletion e2e/cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@pulumi/pulumi": "3.137.0",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.5.4",
"typescript": "5.6.3",
"wrangler": "3.84.1"
}
}
2 changes: 1 addition & 1 deletion e2e/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"eslint-config-next": "15.0.2",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.5.4"
"typescript": "5.6.3"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"prettier": "3.3.3",
"rimraf": "6.0.1",
"ts-jest": "29.2.5",
"typescript": "5.5.4"
"typescript": "5.6.3"
},
"resolutions": {
"@pulumi/pulumi": "3.137.0"
Expand Down
23 changes: 18 additions & 5 deletions packages/node-fetch/src/FormData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PonyfillBlob } from './Blob.js';
import { PonyfillFile } from './File.js';
import { PonyfillIteratorObject } from './IteratorObject.js';
import { PonyfillReadableStream } from './ReadableStream.js';

export class PonyfillFormData implements FormData {
Expand Down Expand Up @@ -45,30 +46,42 @@ export class PonyfillFormData implements FormData {
this.map.set(name, [entry]);
}

*[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]> {
[Symbol.iterator](): FormDataIterator<[string, FormDataEntryValue]> {
return this._entries();
}

*_entries(): FormDataIterator<[string, FormDataEntryValue]> {
for (const [key, values] of this.map) {
for (const value of values) {
yield [key, value];
}
}
}

entries(): IterableIterator<[string, FormDataEntryValue]> {
return this[Symbol.iterator]();
entries(): FormDataIterator<[string, FormDataEntryValue]> {
return new PonyfillIteratorObject(this._entries(), 'FormDataIterator');
}

keys(): IterableIterator<string> {
_keys(): IterableIterator<string> {
return this.map.keys();
}

*values(): IterableIterator<FormDataEntryValue> {
keys(): FormDataIterator<string> {
return new PonyfillIteratorObject(this._keys(), 'FormDataIterator');
}

*_values(): IterableIterator<FormDataEntryValue> {
for (const values of this.map.values()) {
for (const value of values) {
yield value;
}
}
}

values(): FormDataIterator<FormDataEntryValue> {
return new PonyfillIteratorObject(this._values(), 'FormDataIterator');
}

forEach(callback: (value: FormDataEntryValue, key: string, parent: this) => void): void {
for (const [key, value] of this) {
callback(value, key, this);
Expand Down
21 changes: 17 additions & 4 deletions packages/node-fetch/src/Headers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inspect } from 'util';
import { PonyfillIteratorObject } from './IteratorObject.js';

export type PonyfillHeadersInit = [string, string][] | Record<string, string> | Headers;

Expand Down Expand Up @@ -177,7 +178,7 @@ export class PonyfillHeaders implements Headers {
});
}

*keys(): IterableIterator<string> {
*_keys(): IterableIterator<string> {
if (this._setCookies.length) {
yield 'set-cookie';
}
Expand All @@ -198,7 +199,11 @@ export class PonyfillHeaders implements Headers {
yield* this.getMap().keys();
}

*values(): IterableIterator<string> {
keys(): HeadersIterator<string> {
return new PonyfillIteratorObject(this._keys(), 'HeadersIterator');
}

*_values(): IterableIterator<string> {
yield* this._setCookies;
if (!this._map) {
if (this.headersInit) {
Expand All @@ -217,7 +222,11 @@ export class PonyfillHeaders implements Headers {
yield* this.getMap().values();
}

*entries(): IterableIterator<[string, string]> {
values(): HeadersIterator<string> {
return new PonyfillIteratorObject(this._values(), 'HeadersIterator');
}

*_entries(): IterableIterator<[string, string]> {
yield* this._setCookies.map(cookie => ['set-cookie', cookie] as [string, string]);
if (!this._map) {
if (this.headersInit) {
Expand All @@ -236,11 +245,15 @@ export class PonyfillHeaders implements Headers {
yield* this.getMap().entries();
}

entries(): HeadersIterator<[string, string]> {
return new PonyfillIteratorObject(this._entries(), 'HeadersIterator');
}

getSetCookie() {
return this._setCookies;
}

[Symbol.iterator](): IterableIterator<[string, string]> {
[Symbol.iterator](): HeadersIterator<[string, string]> {
return this.entries();
}

Expand Down
155 changes: 155 additions & 0 deletions packages/node-fetch/src/IteratorObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { inspect } from 'node:util';
import { isIterable } from './utils.js';

export class PonyfillIteratorObject<T> implements IteratorObject<T, undefined, unknown> {
[Symbol.toStringTag] = 'IteratorObject';
constructor(
private iterableIterator: IterableIterator<T>,
className: string,
) {
this[Symbol.toStringTag] = className;
}

*map<U>(callbackfn: (value: T, index: number) => U) {
let index = 0;
for (const value of this.iterableIterator) {
yield callbackfn(value, index++);
}
return undefined;
}

*filter(callbackfn: (value: T, index: number) => boolean) {
let index = 0;
for (const value of this.iterableIterator) {
if (callbackfn(value, index++)) {
yield value;
}
}
return undefined;
}

reduce<U>(
callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U,
initialValue?: U,
) {
let index = 0;
let accumulator = initialValue as U;
for (const value of this.iterableIterator) {
accumulator = callbackfn(accumulator, value, index++);
}
return accumulator;
}

forEach(callbackfn: (value: T, index: number) => void): void {
let index = 0;
for (const value of this.iterableIterator) {
callbackfn(value, index++);
}
}

*take(limit: number) {
let index = 0;
for (const value of this.iterableIterator) {
if (index >= limit) {
break;
}
yield value;
index++;
}
return undefined;
}

*drop(count: number): IteratorObject<T, undefined, unknown> {
let index = 0;
for (const value of this.iterableIterator) {
if (index >= count) {
yield value;
}
index++;
}
return undefined;
}

*flatMap<U>(
callback: (
value: T,
index: number,
) => Iterator<U, unknown, undefined> | Iterable<U, unknown, undefined>,
): IteratorObject<U, undefined, unknown> {
let index = 0;
for (const value of this.iterableIterator) {
const iteratorOrIterable = callback(value, index++);
if (isIterable(iteratorOrIterable)) {
for (const innerValue of iteratorOrIterable) {
yield innerValue;
}
} else {
for (const innerValue of {
[Symbol.iterator]: () => iteratorOrIterable,
}) {
yield innerValue;
}
}
}
return undefined;
}

some(predicate: (value: T, index: number) => unknown): boolean {
let index = 0;
for (const value of this.iterableIterator) {
if (predicate(value, index++)) {
return true;
}
}
return false;
}

every(predicate: (value: T, index: number) => unknown): boolean {
let index = 0;
for (const value of this.iterableIterator) {
if (!predicate(value, index++)) {
return false;
}
}
return true;
}

find(predicate: (value: T, index: number) => unknown): T | undefined {
let index = 0;
for (const value of this.iterableIterator) {
if (predicate(value, index++)) {
return value;
}
}
return undefined;
}

toArray(): T[] {
return Array.from(this.iterableIterator);
}

[Symbol.dispose](): void {
if (typeof (this.iterableIterator as any).return === 'function') {
(this.iterableIterator as any).return();
}
}

next(...[value]: [] | [unknown]): IteratorResult<T, undefined> {
return this.iterableIterator.next(value);
}

[Symbol.iterator](): URLSearchParamsIterator<T> {
return this;
}

[Symbol.for('nodejs.util.inspect.custom')]() {
const record: Record<string, string[] | string> = {};
this.forEach((value, key) => {
const inspectedValue = inspect(value);
record[key] = inspectedValue.includes(',')
? inspectedValue.split(',').map(el => el.trim())
: inspectedValue;
});
return `${this[Symbol.toStringTag]} ${inspect(record)}`;
}
}
21 changes: 17 additions & 4 deletions packages/node-fetch/src/URLSearchParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FastQuerystring from 'fast-querystring';
import { PonyfillIteratorObject } from './IteratorObject.js';

function isURLSearchParams(value: any): value is URLSearchParams {
return value?.entries != null;
Expand Down Expand Up @@ -75,13 +76,17 @@ export class PonyfillURLSearchParams implements URLSearchParams {
return FastQuerystring.stringify(this.params);
}

*keys(): IterableIterator<string> {
*_keys(): IterableIterator<string> {
for (const key in this.params) {
yield key;
}
}

*entries(): IterableIterator<[string, string]> {
keys(): URLSearchParamsIterator<string> {
return new PonyfillIteratorObject(this._keys(), 'URLSearchParamsIterator');
}

*_entries(): IterableIterator<[string, string]> {
for (const key of this.keys()) {
const value = this.params[key];
if (Array.isArray(value)) {
Expand All @@ -94,13 +99,21 @@ export class PonyfillURLSearchParams implements URLSearchParams {
}
}

*values(): IterableIterator<string> {
entries(): URLSearchParamsIterator<[string, string]> {
return new PonyfillIteratorObject(this._entries(), 'URLSearchParamsIterator');
}

*_values(): IterableIterator<string> {
for (const [, value] of this) {
yield value;
}
}

[Symbol.iterator](): IterableIterator<[string, string]> {
values(): URLSearchParamsIterator<string> {
return new PonyfillIteratorObject(this._values(), 'URLSearchParamsIterator');
}

[Symbol.iterator](): URLSearchParamsIterator<[string, string]> {
return this.entries();
}

Expand Down
1 change: 1 addition & 0 deletions packages/node-fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export { PonyfillWritableStream as WritableStream } from './WritableStream.js';
export { PonyfillTransformStream as TransformStream } from './TransformStream.js';
export { PonyfillCompressionStream as CompressionStream } from './CompressionStream.js';
export { PonyfillDecompressionStream as DecompressionStream } from './DecompressionStream.js';
export { PonyfillIteratorObject as IteratorObject } from './IteratorObject.js';
Loading

0 comments on commit 637185f

Please sign in to comment.