diff options
author | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-28 07:21:00 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-28 07:21:00 +0200 |
commit | dc04ca93060443a3ce6263a476f4dafc66afc6b3 (patch) | |
tree | b9c645cbe897af198ea0551509f901a249af35f2 /g4f/Provider/npm/node_modules/undici/lib/mock/mock-pool.js | |
parent | Update config supports_message_history (diff) | |
download | gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.gz gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.bz2 gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.lz gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.xz gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.zst gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.zip |
Diffstat (limited to 'g4f/Provider/npm/node_modules/undici/lib/mock/mock-pool.js')
-rw-r--r-- | g4f/Provider/npm/node_modules/undici/lib/mock/mock-pool.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/g4f/Provider/npm/node_modules/undici/lib/mock/mock-pool.js b/g4f/Provider/npm/node_modules/undici/lib/mock/mock-pool.js new file mode 100644 index 00000000..0a3a7cd3 --- /dev/null +++ b/g4f/Provider/npm/node_modules/undici/lib/mock/mock-pool.js @@ -0,0 +1,59 @@ +'use strict' + +const { promisify } = require('util') +const Pool = require('../pool') +const { buildMockDispatch } = require('./mock-utils') +const { + kDispatches, + kMockAgent, + kClose, + kOriginalClose, + kOrigin, + kOriginalDispatch, + kConnected +} = require('./mock-symbols') +const { MockInterceptor } = require('./mock-interceptor') +const Symbols = require('../core/symbols') +const { InvalidArgumentError } = require('../core/errors') + +/** + * MockPool provides an API that extends the Pool to influence the mockDispatches. + */ +class MockPool extends Pool { + constructor (origin, opts) { + super(origin, opts) + + if (!opts || !opts.agent || typeof opts.agent.dispatch !== 'function') { + throw new InvalidArgumentError('Argument opts.agent must implement Agent') + } + + this[kMockAgent] = opts.agent + this[kOrigin] = origin + this[kDispatches] = [] + this[kConnected] = 1 + this[kOriginalDispatch] = this.dispatch + this[kOriginalClose] = this.close.bind(this) + + this.dispatch = buildMockDispatch.call(this) + this.close = this[kClose] + } + + get [Symbols.kConnected] () { + return this[kConnected] + } + + /** + * Sets up the base interceptor for mocking replies from undici. + */ + intercept (opts) { + return new MockInterceptor(opts, this[kDispatches]) + } + + async [kClose] () { + await promisify(this[kOriginalClose])() + this[kConnected] = 0 + this[kMockAgent][Symbols.kClients].delete(this[kOrigin]) + } +} + +module.exports = MockPool |