From 16338d44505d4791fc49b26723821f2d10870944 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 5 May 2022 20:47:35 +0200 Subject: [PATCH] fix: update http and add missing exports --- package.json | 3 +- pnpm-lock.yaml | 48 +---------------------------- src/runtime/node/http/_consts.ts | 2 ++ src/runtime/node/http/index.ts | 30 ++++++++++++++---- src/runtime/node/net/socket.ts | 11 +++---- src/runtime/node/stream/readable.ts | 5 ++- src/runtime/node/stream/writable.ts | 10 +++--- 7 files changed, 41 insertions(+), 68 deletions(-) diff --git a/package.json b/package.json index 706bcc90..33293a8c 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,7 @@ }, "devDependencies": { "@nuxtjs/eslint-config-typescript": "latest", - "@types/node": "latest", - "@types/node-fetch": "latest", + "@types/node": "^17.0.31", "consola": "latest", "eslint": "latest", "standard-version": "latest", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79a126f7..dd0f802f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,8 +2,7 @@ lockfileVersion: 5.4 specifiers: '@nuxtjs/eslint-config-typescript': latest - '@types/node': latest - '@types/node-fetch': latest + '@types/node': ^17.0.31 abort-controller: ^3.0.0 consola: latest defu: ^6.0.0 @@ -25,7 +24,6 @@ dependencies: devDependencies: '@nuxtjs/eslint-config-typescript': 10.0.0_t725usgvqspm5woeqpaxbfp2qu '@types/node': 17.0.31 - '@types/node-fetch': 2.6.1 consola: 2.15.3 eslint: 8.14.0 standard-version: 9.3.2 @@ -440,13 +438,6 @@ packages: resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} dev: true - /@types/node-fetch/2.6.1: - resolution: {integrity: sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==} - dependencies: - '@types/node': 17.0.31 - form-data: 3.0.1 - dev: true - /@types/node/17.0.31: resolution: {integrity: sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q==} dev: true @@ -686,10 +677,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /asynckit/0.4.0: - resolution: {integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k=} - dev: true - /balanced-match/1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true @@ -831,13 +818,6 @@ packages: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} dev: true - /combined-stream/1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - dev: true - /commondir/1.0.1: resolution: {integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=} dev: true @@ -1131,11 +1111,6 @@ packages: /defu/6.0.0: resolution: {integrity: sha512-t2MZGLf1V2rV4VBZbWIaXKdX/mUcYW0n2znQZoADBkGGxYL8EWqCuCZBmJPJ/Yy9fofJkyuuSuo5GSwo0XdEgw==} - /delayed-stream/1.0.0: - resolution: {integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk=} - engines: {node: '>=0.4.0'} - dev: true - /detect-indent/6.1.0: resolution: {integrity: sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==} engines: {node: '>=8'} @@ -2033,15 +2008,6 @@ packages: resolution: {integrity: sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==} dev: true - /form-data/3.0.1: - resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==} - engines: {node: '>= 6'} - dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.35 - dev: true - /formdata-polyfill/4.0.10: resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} engines: {node: '>=12.20.0'} @@ -2681,18 +2647,6 @@ packages: picomatch: 2.3.1 dev: true - /mime-db/1.52.0: - resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} - engines: {node: '>= 0.6'} - dev: true - - /mime-types/2.1.35: - resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.52.0 - dev: true - /mime/3.0.0: resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==} engines: {node: '>=10.0.0'} diff --git a/src/runtime/node/http/_consts.ts b/src/runtime/node/http/_consts.ts index 2df45852..84ede1d3 100644 --- a/src/runtime/node/http/_consts.ts +++ b/src/runtime/node/http/_consts.ts @@ -78,3 +78,5 @@ export const STATUS_CODES = { 510: 'Not Extended', 511: 'Network Authentication Required' } + +export const maxHeaderSize = 16384 diff --git a/src/runtime/node/http/index.ts b/src/runtime/node/http/index.ts index 540f61bc..06b60083 100644 --- a/src/runtime/node/http/index.ts +++ b/src/runtime/node/http/index.ts @@ -1,17 +1,35 @@ // https://nodejs.org/api/http.html -import type http from 'node:http' +import http from 'node:http' +import { notImplemented } from '../../_internal/utils' import * as consts from './_consts' -import * as request from './_request' -import * as response from './_response' +import { IncomingMessage } from './_request' +import { ServerResponse } from './_response' export * from './_consts' export * from './_request' export * from './_response' -// @ts-ignore +export const createServer: typeof http.createServer = notImplemented('http.createServer') +export const request: typeof http.request = notImplemented('http.request') +export const get: typeof http.get = notImplemented('http.get') + +export const Server: typeof http.Server = undefined as any as typeof http.Server +export const OutgoingMessage: typeof http.OutgoingMessage = undefined as any as typeof http.OutgoingMessage +export const ClientRequest: typeof http.ClientRequest = undefined as any as typeof http.ClientRequest +export const Agent: typeof http.Agent = undefined as any as typeof http.Agent +export const globalAgent: typeof http.globalAgent = undefined as any as typeof http.globalAgent + export default { ...consts, - ...request, - ...response + IncomingMessage: IncomingMessage as any as typeof http.IncomingMessage, + ServerResponse: ServerResponse as any as typeof http.ServerResponse, + createServer, + request, + get, + Server, + OutgoingMessage, + ClientRequest, + Agent, + globalAgent } diff --git a/src/runtime/node/net/socket.ts b/src/runtime/node/net/socket.ts index 883abcfe..6f7cf283 100644 --- a/src/runtime/node/net/socket.ts +++ b/src/runtime/node/net/socket.ts @@ -14,24 +14,23 @@ export class Socket extends Duplex implements net.Socket { readonly remoteAddress?: string = '' readonly remoteFamily?: string = '' readonly remotePort?: number = 0 + readonly readyState: net.SocketReadyState = 'readOnly' constructor (_options?: net.SocketConstructorOpts) { super() } - write (_buffer: Uint8Array | string, - _arg1?: BufferEncoding | Callback, + write (_buffer: Uint8Array | string, _arg1?: BufferEncoding | Callback, _arg2?: Callback): boolean { return false } - connect (_arg1: number | string | net.SocketConnectOpts, - _arg2?: string | Callback, _arg3?: Callback) { + connect (_arg1: number | string | net.SocketConnectOpts, _arg2?: string | Callback, _arg3?: Callback) { return this } - end (_arg1?: Callback | Uint8Array | string, - _arg2?: BufferEncoding | Callback, _arg3?: Callback): void { + end (_arg1?: Callback | Uint8Array | string, _arg2?: BufferEncoding | Callback, _arg3?: Callback) { + return this } setEncoding (_encoding?: BufferEncoding): this { diff --git a/src/runtime/node/stream/readable.ts b/src/runtime/node/stream/readable.ts index b57858fd..86d75945 100644 --- a/src/runtime/node/stream/readable.ts +++ b/src/runtime/node/stream/readable.ts @@ -12,6 +12,8 @@ export class Readable extends EventEmitter implements stream.Readable { readonly readableHighWaterMark: number = 0 readonly readableLength: number = 0 readonly readableObjectMode: boolean = false + readonly readableAborted: boolean = false + readonly readableDidRead: boolean = false readable: boolean = false destroyed: boolean = false @@ -67,7 +69,8 @@ export class Readable extends EventEmitter implements stream.Readable { destroy (error?: Error) { this.destroyed = true - return this._destroy(error) + this._destroy(error) + return this } pipe (_destenition: T, _options?: { end?: boolean }): T { diff --git a/src/runtime/node/stream/writable.ts b/src/runtime/node/stream/writable.ts index 23a37c1c..3d00924e 100644 --- a/src/runtime/node/stream/writable.ts +++ b/src/runtime/node/stream/writable.ts @@ -55,7 +55,7 @@ export class Writable extends EventEmitter implements stream.Writable { return this } - end (arg1: Callback | any, arg2?: Callback | BufferEncoding, arg3?: Callback): void { + end (arg1: Callback | any, arg2?: Callback | BufferEncoding, arg3?: Callback) { const cb = (typeof arg1 === 'function') ? arg1 : (typeof arg2 === 'function' ? arg2 : (typeof arg3 === 'function' ? arg3 : undefined)) const data = arg1 !== cb ? arg1 : undefined if (data) { @@ -66,8 +66,7 @@ export class Writable extends EventEmitter implements stream.Writable { this.writableFinished = true this.emit('close') this.emit('finish') - // TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57473 - return this as unknown as void + return this } cork (): void { @@ -76,11 +75,10 @@ export class Writable extends EventEmitter implements stream.Writable { uncork (): void { } - destroy (_error?: Error): void { + destroy (_error?: Error) { this.destroyed = true delete this._data this.removeAllListeners() - // TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57473 - return this as unknown as void + return this } }