diff options
Diffstat (limited to 'src/js/thirdparty/undici.js')
-rw-r--r-- | src/js/thirdparty/undici.js | 76 |
1 files changed, 51 insertions, 25 deletions
diff --git a/src/js/thirdparty/undici.js b/src/js/thirdparty/undici.js index cf3968b58..579e33d1d 100644 --- a/src/js/thirdparty/undici.js +++ b/src/js/thirdparty/undici.js @@ -1,27 +1,27 @@ -// const { Object } = import.meta.primordials; -const { EventEmitter } = import.meta.require("events"); -const { - Readable, - [Symbol.for("::bunternal::")]: { _ReadableFromWeb }, -} = import.meta.require("node:stream"); +const { Object } = globalThis[Symbol.for("Bun.lazy")]("primordials"); +import { EventEmitter } from "events"; +import NodeStreamModule from "node:stream"; +import { Readable } from "node:stream"; + +const { _ReadableFromWebForUndici: ReadableFromWeb } = NodeStreamModule[Symbol.for("::bunternal::")]; const ObjectCreate = Object.create; const kEmptyObject = ObjectCreate(null); -export var fetch = Bun.fetch; -export var Response = globalThis.Response; -export var Headers = globalThis.Headers; -export var Request = globalThis.Request; -export var URLSearchParams = globalThis.URLSearchParams; -export var URL = globalThis.URL; -export class File extends Blob {} -export class FileReader extends EventTarget { +var fetch = Bun.fetch; +var Response = globalThis.Response; +var Headers = globalThis.Headers; +var Request = globalThis.Request; +var URLSearchParams = globalThis.URLSearchParams; +var URL = globalThis.URL; +class File extends Blob {} +class FileReader extends EventTarget { constructor() { throw new Error("Not implemented yet!"); } } -export var FormData = globalThis.FormData; +var FormData = globalThis.FormData; function notImplemented() { throw new Error("Not implemented in bun"); } @@ -45,7 +45,7 @@ function notImplemented() { * @typedef {import('events').EventEmitter} EventEmitter */ -class BodyReadable extends _ReadableFromWeb { +class BodyReadable extends ReadableFromWeb { #response; #bodyUsed; @@ -127,7 +127,7 @@ class BodyReadable extends _ReadableFromWeb { * context: Object<string, *>; * }} */ -export async function request( +async function request( url, options = { method: "GET", @@ -228,36 +228,36 @@ export async function request( return { statusCode, headers: headers.toJSON(), body, trailers, opaque: kEmptyObject, context: kEmptyObject }; } -export function stream() { +function stream() { throw new Error("Not implemented in bun"); } -export function pipeline() { +function pipeline() { throw new Error("Not implemented in bun"); } -export function connect() { +function connect() { throw new Error("Not implemented in bun"); } -export function upgrade() { +function upgrade() { throw new Error("Not implemented in bun"); } -export class MockClient { +class MockClient { constructor() { throw new Error("Not implemented in bun"); } } -export class MockPool { +class MockPool { constructor() { throw new Error("Not implemented in bun"); } } -export class MockAgent { +class MockAgent { constructor() { throw new Error("Not implemented in bun"); } } -export function mockErrors() { +function mockErrors() { throw new Error("Not implemented in bun"); } @@ -329,3 +329,29 @@ export default { Undici, [Symbol.for("CommonJS")]: 0, }; + +export { + fetch, + Response, + Headers, + Request, + URLSearchParams, + URL, + File, + FileReader, + FormData, + request, + stream, + pipeline, + connect, + upgrade, + MockClient, + MockPool, + MockAgent, + mockErrors, + Dispatcher, + Pool, + BalancedPool, + Client, + Agent, +}; |