Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move files into logical folders #2813

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict'

const Client = require('./lib/client')
const Dispatcher = require('./lib/dispatcher')
const Client = require('./lib/dispatcher/client')
const Dispatcher = require('./lib/dispatcher/dispatcher')
const Pool = require('./lib/dispatcher/pool')
const BalancedPool = require('./lib/dispatcher/balanced-pool')
const Agent = require('./lib/dispatcher/agent')
const ProxyAgent = require('./lib/dispatcher/proxy-agent')
const RetryAgent = require('./lib/dispatcher/retry-agent')
const errors = require('./lib/core/errors')
const Pool = require('./lib/pool')
const BalancedPool = require('./lib/balanced-pool')
const Agent = require('./lib/agent')
const util = require('./lib/core/util')
const { InvalidArgumentError } = errors
const api = require('./lib/api')
Expand All @@ -14,8 +16,6 @@ const MockClient = require('./lib/mock/mock-client')
const MockAgent = require('./lib/mock/mock-agent')
const MockPool = require('./lib/mock/mock-pool')
const mockErrors = require('./lib/mock/mock-errors')
const ProxyAgent = require('./lib/proxy-agent')
const RetryAgent = require('./lib/retry-agent')
const RetryHandler = require('./lib/handler/RetryHandler')
const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
const DecoratorHandler = require('./lib/handler/DecoratorHandler')
Expand Down
8 changes: 4 additions & 4 deletions lib/agent.js → lib/dispatcher/agent.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const { InvalidArgumentError } = require('./core/errors')
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors } = require('./core/symbols')
const { InvalidArgumentError } = require('../core/errors')
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors } = require('../core/symbols')
const DispatcherBase = require('./dispatcher-base')
const Pool = require('./pool')
const Client = require('./client')
const util = require('./core/util')
const createRedirectInterceptor = require('./interceptor/redirectInterceptor')
const util = require('../core/util')
const createRedirectInterceptor = require('../interceptor/redirectInterceptor')

const kOnConnect = Symbol('onConnect')
const kOnDisconnect = Symbol('onDisconnect')
Expand Down
6 changes: 3 additions & 3 deletions lib/balanced-pool.js → lib/dispatcher/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {
BalancedPoolMissingUpstreamError,
InvalidArgumentError
} = require('./core/errors')
} = require('../core/errors')
const {
PoolBase,
kClients,
Expand All @@ -13,8 +13,8 @@ const {
kGetDispatcher
} = require('./pool-base')
const Pool = require('./pool')
const { kUrl, kInterceptors } = require('./core/symbols')
const { parseOrigin } = require('./core/util')
const { kUrl, kInterceptors } = require('../core/symbols')
const { parseOrigin } = require('../core/util')
const kFactory = Symbol('factory')

const kOptions = Symbol('options')
Expand Down
30 changes: 15 additions & 15 deletions lib/client.js → lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const assert = require('node:assert')
const net = require('node:net')
const http = require('node:http')
const { pipeline } = require('node:stream')
const util = require('./core/util')
const { channels } = require('./core/diagnostics')
const timers = require('./timers')
const Request = require('./core/request')
const util = require('../core/util.js')
const { channels } = require('../core/diagnostics.js')
const timers = require('../util/timers.js')
const Request = require('../core/request.js')
const DispatcherBase = require('./dispatcher-base')
const {
RequestContentLengthMismatchError,
Expand All @@ -26,8 +26,8 @@ const {
HTTPParserError,
ResponseExceededMaxSizeError,
ClientDestroyedError
} = require('./core/errors')
const buildConnector = require('./core/connect')
} = require('../core/errors.js')
const buildConnector = require('../core/connect.js')
const {
kUrl,
kReset,
Expand Down Expand Up @@ -79,7 +79,7 @@ const {
kHTTP2BuildRequest,
kHTTP2CopyHeaders,
kHTTP1BuildRequest
} = require('./core/symbols')
} = require('../core/symbols.js')

/** @type {import('http2')} */
let http2
Expand Down Expand Up @@ -112,13 +112,13 @@ const FastBuffer = Buffer[Symbol.species]
const kClosedResolve = Symbol('kClosedResolve')

/**
* @type {import('../types/client').default}
* @type {import('../../types/client.js').default}
*/
class Client extends DispatcherBase {
/**
*
* @param {string|URL} url
* @param {import('../types/client').Client.Options} options
* @param {import('../../types/client.js').Client.Options} options
*/
constructor (url, {
interceptors,
Expand Down Expand Up @@ -472,24 +472,24 @@ function onHTTP2GoAway (code) {
resume(client)
}

const constants = require('./llhttp/constants')
const createRedirectInterceptor = require('./interceptor/redirectInterceptor')
const constants = require('../llhttp/constants.js')
const createRedirectInterceptor = require('../interceptor/redirectInterceptor.js')
const EMPTY_BUF = Buffer.alloc(0)

async function lazyllhttp () {
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('./llhttp/llhttp-wasm.js') : undefined
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined

let mod
try {
mod = await WebAssembly.compile(require('./llhttp/llhttp_simd-wasm.js'))
mod = await WebAssembly.compile(require('../llhttp/llhttp_simd-wasm.js'))
} catch (e) {
/* istanbul ignore next */

// We could check if the error was caused by the simd option not
// being enabled, but the occurring of this other error
// * https://github.com/emscripten-core/emscripten/issues/11495
// got me to remove that check to avoid breaking Node 12.
mod = await WebAssembly.compile(llhttpWasmData || require('./llhttp/llhttp-wasm.js'))
mod = await WebAssembly.compile(llhttpWasmData || require('../llhttp/llhttp-wasm.js'))
}

return await WebAssembly.instantiate(mod, {
Expand Down Expand Up @@ -1500,7 +1500,7 @@ function write (client, request) {

if (util.isFormDataLike(body)) {
if (!extractBody) {
extractBody = require('./web/fetch/body.js').extractBody
extractBody = require('../web/fetch/body.js').extractBody
}

const [bodyStream, contentType] = extractBody(body)
Expand Down
4 changes: 2 additions & 2 deletions lib/dispatcher-base.js → lib/dispatcher/dispatcher-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const {
ClientDestroyedError,
ClientClosedError,
InvalidArgumentError
} = require('./core/errors')
const { kDestroy, kClose, kDispatch, kInterceptors } = require('./core/symbols')
} = require('../core/errors')
const { kDestroy, kClose, kDispatch, kInterceptors } = require('../core/symbols')

const kDestroyed = Symbol('destroyed')
const kClosed = Symbol('closed')
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/pool-base.js → lib/dispatcher/pool-base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const DispatcherBase = require('./dispatcher-base')
const FixedQueue = require('./node/fixed-queue')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('./core/symbols')
const FixedQueue = require('../node/fixed-queue')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
const PoolStats = require('./pool-stats')

const kClients = Symbol('clients')
Expand Down
2 changes: 1 addition & 1 deletion lib/pool-stats.js → lib/dispatcher/pool-stats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { kFree, kConnected, kPending, kQueued, kRunning, kSize } = require('./core/symbols')
const { kFree, kConnected, kPending, kQueued, kRunning, kSize } = require('../core/symbols')
const kPool = Symbol('pool')

class PoolStats {
Expand Down
8 changes: 4 additions & 4 deletions lib/pool.js → lib/dispatcher/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const {
const Client = require('./client')
const {
InvalidArgumentError
} = require('./core/errors')
const util = require('./core/util')
const { kUrl, kInterceptors } = require('./core/symbols')
const buildConnector = require('./core/connect')
} = require('../core/errors')
const util = require('../core/util')
const { kUrl, kInterceptors } = require('../core/symbols')
const buildConnector = require('../core/connect')

const kOptions = Symbol('options')
const kConnections = Symbol('connections')
Expand Down
6 changes: 3 additions & 3 deletions lib/proxy-agent.js → lib/dispatcher/proxy-agent.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const { kProxy, kClose, kDestroy, kInterceptors } = require('./core/symbols')
const { kProxy, kClose, kDestroy, kInterceptors } = require('../core/symbols')
const { URL } = require('node:url')
const Agent = require('./agent')
const Pool = require('./pool')
const DispatcherBase = require('./dispatcher-base')
const { InvalidArgumentError, RequestAbortedError } = require('./core/errors')
const buildConnector = require('./core/connect')
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
const buildConnector = require('../core/connect')

const kAgent = Symbol('proxy agent')
const kClient = Symbol('proxy client')
Expand Down
2 changes: 1 addition & 1 deletion lib/retry-agent.js → lib/dispatcher/retry-agent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Dispatcher = require('./dispatcher')
const RetryHandler = require('./handler/RetryHandler')
const RetryHandler = require('../handler/RetryHandler')

class RetryAgent extends Dispatcher {
#agent = null
Expand Down
2 changes: 1 addition & 1 deletion lib/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// this version number must be increased to avoid conflicts.
const globalDispatcher = Symbol.for('undici.globalDispatcher.1')
const { InvalidArgumentError } = require('./core/errors')
const Agent = require('./agent')
const Agent = require('./dispatcher/agent')

if (getGlobalDispatcher() === undefined) {
setGlobalDispatcher(new Agent())
Expand Down
4 changes: 2 additions & 2 deletions lib/mock/mock-agent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { kClients } = require('../core/symbols')
const Agent = require('../agent')
const Agent = require('../dispatcher/agent')
const {
kAgent,
kMockAgentSet,
Expand All @@ -17,7 +17,7 @@ const MockClient = require('./mock-client')
const MockPool = require('./mock-pool')
const { matchValue, buildMockOptions } = require('./mock-utils')
const { InvalidArgumentError, UndiciError } = require('../core/errors')
const Dispatcher = require('../dispatcher')
const Dispatcher = require('../dispatcher/dispatcher')
const Pluralizer = require('./pluralizer')
const PendingInterceptorsFormatter = require('./pending-interceptors-formatter')

Expand Down
2 changes: 1 addition & 1 deletion lib/mock/mock-client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { promisify } = require('node:util')
const Client = require('../client')
const Client = require('../dispatcher/client')
const { buildMockDispatch } = require('./mock-utils')
const {
kDispatches,
Expand Down
2 changes: 1 addition & 1 deletion lib/mock/mock-pool.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { promisify } = require('node:util')
const Pool = require('../pool')
const Pool = require('../dispatcher/pool')
const { buildMockDispatch } = require('./mock-utils')
const {
kDispatches,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/client-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { once } = require('node:events')
const { Client } = require('..')
const timers = require('../lib/timers')
const timers = require('../lib/util/timers')
const { kConnect } = require('../lib/core/symbols')
const { createServer } = require('node:net')
const http = require('node:http')
Expand Down
2 changes: 1 addition & 1 deletion test/client-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { once } = require('node:events')
const { Client } = require('..')
const { createServer } = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/timers')
const timers = require('../lib/util/timers')

test('multiple reconnect', async (t) => {
t = tspl(t, { plan: 5 })
Expand Down
2 changes: 1 addition & 1 deletion test/client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Client, errors } = require('..')
const { createServer } = require('node:http')
const { Readable } = require('node:stream')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/timers')
const timers = require('../lib/util/timers')

test('refresh timeout on pause', async (t) => {
t = tspl(t, { plan: 1 })
Expand Down
2 changes: 1 addition & 1 deletion test/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { tspl } = require('@matteo.collina/tspl')
const { test } = require('node:test')

const Dispatcher = require('../lib/dispatcher')
const Dispatcher = require('../lib/dispatcher/dispatcher')

class PoorImplementation extends Dispatcher {}

Expand Down
2 changes: 1 addition & 1 deletion test/fetch/fetch-timeouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { test } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')

const { fetch, Agent } = require('../..')
const timers = require('../../lib/timers')
const timers = require('../../lib/util/timers')
const { createServer } = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')
const { closeServerAsPromise } = require('../utils/node-http')
Expand Down
2 changes: 1 addition & 1 deletion test/mock-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { InvalidArgumentError, ClientDestroyedError } = require('../lib/core/erro
const MockClient = require('../lib/mock/mock-client')
const MockPool = require('../lib/mock/mock-pool')
const { kAgent } = require('../lib/mock/mock-symbols')
const Dispatcher = require('../lib/dispatcher')
const Dispatcher = require('../lib/dispatcher/dispatcher')
const { MockNotMatchedError } = require('../lib/mock/mock-errors')
const { fetch } = require('..')

Expand Down
2 changes: 1 addition & 1 deletion test/mock-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { kDispatches } = require('../lib/mock/mock-symbols')
const { InvalidArgumentError } = require('../lib/core/errors')
const { MockInterceptor } = require('../lib/mock/mock-interceptor')
const { getResponse } = require('../lib/mock/mock-utils')
const Dispatcher = require('../lib/dispatcher')
const Dispatcher = require('../lib/dispatcher/dispatcher')

describe('MockClient - constructor', () => {
test('fails if opts.agent does not implement `get` method', t => {
Expand Down
2 changes: 1 addition & 1 deletion test/mock-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { kDispatches } = require('../lib/mock/mock-symbols')
const { InvalidArgumentError } = require('../lib/core/errors')
const { MockInterceptor } = require('../lib/mock/mock-interceptor')
const { getResponse } = require('../lib/mock/mock-utils')
const Dispatcher = require('../lib/dispatcher')
const Dispatcher = require('../lib/dispatcher/dispatcher')
const { fetch } = require('..')

describe('MockPool - constructor', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ test('backpressure algorithm', async (t) => {
}
}

const Pool = proxyquire('../lib/pool', {
const Pool = proxyquire('../lib/dispatcher/pool', {
'./client': FakeClient
})

Expand Down
4 changes: 2 additions & 2 deletions test/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const { request, fetch, setGlobalDispatcher, getGlobalDispatcher } = require('..
const { InvalidArgumentError } = require('../lib/core/errors')
const { readFileSync } = require('node:fs')
const { join } = require('node:path')
const ProxyAgent = require('../lib/proxy-agent')
const Pool = require('../lib/pool')
const ProxyAgent = require('../lib/dispatcher/proxy-agent')
const Pool = require('../lib/dispatcher/pool')
const { createServer } = require('node:http')
const https = require('node:https')
const proxy = require('proxy')
Expand Down
2 changes: 1 addition & 1 deletion test/request-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, after } = require('node:test')
const { createReadStream, writeFileSync, unlinkSync } = require('node:fs')
const { Client, errors } = require('..')
const { kConnect } = require('../lib/core/symbols')
const timers = require('../lib/timers')
const timers = require('../lib/util/timers')
const { createServer } = require('node:http')
const EventEmitter = require('node:events')
const FakeTimers = require('@sinonjs/fake-timers')
Expand Down
2 changes: 1 addition & 1 deletion test/socket-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { Client, errors } = require('..')
const timers = require('../lib/timers')
const timers = require('../lib/util/timers')
const { createServer } = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')

Expand Down
Loading