From 9b1822eface9ec8bce808757b4bda15b6224a34b Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Wed, 6 Mar 2024 10:30:44 +0100 Subject: [PATCH] types --- packages/cli-repl/src/update-notification-manager.ts | 7 ++++++- packages/import-node-fetch/src/index.ts | 2 ++ packages/snippet-manager/src/snippet-manager.ts | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/cli-repl/src/update-notification-manager.ts b/packages/cli-repl/src/update-notification-manager.ts index 943e47cb83..762b8c3a4b 100644 --- a/packages/cli-repl/src/update-notification-manager.ts +++ b/packages/cli-repl/src/update-notification-manager.ts @@ -1,9 +1,14 @@ import semver from 'semver'; import { promises as fs } from 'fs'; import importNodeFetch from '@mongosh/import-node-fetch'; +import type { + RequestInfo, + RequestInit, + Response, +} from '@mongosh/import-node-fetch'; // 'http' is not supported in startup snapshots yet. -const fetch = async (url: any, init?: any): Promise => +const fetch = async (url: RequestInfo, init?: RequestInit): Promise => await (await importNodeFetch()).default(url, init); interface MongoshUpdateLocalFileContents { diff --git a/packages/import-node-fetch/src/index.ts b/packages/import-node-fetch/src/index.ts index 83d23cfddf..a871142ebb 100644 --- a/packages/import-node-fetch/src/index.ts +++ b/packages/import-node-fetch/src/index.ts @@ -1,5 +1,7 @@ // eslint-disable-next-line @typescript-eslint/consistent-type-imports export type TNodeFetch = typeof import('node-fetch'); +export type { Request, Response, RequestInfo, RequestInit } from 'node-fetch'; + export default async function importNodeFetch(): Promise { // Node-fetch is an ESM module from 3.x // Importing ESM modules to CommonJS is possible with a dynamic import. diff --git a/packages/snippet-manager/src/snippet-manager.ts b/packages/snippet-manager/src/snippet-manager.ts index 7c48209ad8..ade98c74c0 100644 --- a/packages/snippet-manager/src/snippet-manager.ts +++ b/packages/snippet-manager/src/snippet-manager.ts @@ -18,7 +18,7 @@ import zlib from 'zlib'; import bson from 'bson'; import joi from 'joi'; import importNodeFetch from '@mongosh/import-node-fetch'; -import type { TNodeFetch } from '@mongosh/import-node-fetch'; +import type { Response } from '@mongosh/import-node-fetch'; const pipeline = promisify(stream.pipeline); const brotliCompress = promisify(zlib.brotliCompress); const brotliDecompress = promisify(zlib.brotliDecompress); @@ -193,7 +193,7 @@ export class SnippetManager implements ShellPlugin { return this._instanceState.messageBus; } - async fetch(url: string): Promise> { + async fetch(url: string): Promise { // 'http' is not supported in startup snapshots yet. const fetch = await importNodeFetch(); return await fetch.default(url);