MCPcopy
hub / github.com/di-sukharev/opencommit / mockDispatch

Function mockDispatch

out/cli.cjs:57308–57350  ·  view source on GitHub ↗
(opts, handler)

Source from the content-addressed store, hash-verified

57306 }
57307 async function getResponse(body) {
57308 const buffers = [];
57309 for await (const data of body) {
57310 buffers.push(data);
57311 }
57312 return Buffer.concat(buffers).toString("utf8");
57313 }
57314 function mockDispatch(opts, handler) {
57315 const key = buildKey(opts);
57316 const mockDispatch2 = getMockDispatch(this[kDispatches], key);
57317 mockDispatch2.timesInvoked++;
57318 if (mockDispatch2.data.callback) {
57319 mockDispatch2.data = { ...mockDispatch2.data, ...mockDispatch2.data.callback(opts) };
57320 }
57321 const { data: { statusCode, data, headers, trailers, error }, delay: delay3, persist } = mockDispatch2;
57322 const { timesInvoked, times } = mockDispatch2;
57323 mockDispatch2.consumed = !persist && timesInvoked >= times;
57324 mockDispatch2.pending = timesInvoked < times;
57325 if (error !== null) {
57326 deleteMockDispatch(this[kDispatches], key);
57327 handler.onError(error);
57328 return true;
57329 }
57330 if (typeof delay3 === "number" && delay3 > 0) {
57331 setTimeout(() => {
57332 handleReply(this[kDispatches]);
57333 }, delay3);
57334 } else {
57335 handleReply(this[kDispatches]);
57336 }
57337 function handleReply(mockDispatches, _data = data) {
57338 const optsHeaders = Array.isArray(opts.headers) ? buildHeadersFromArray(opts.headers) : opts.headers;
57339 const body = typeof _data === "function" ? _data({ ...opts, headers: optsHeaders }) : _data;
57340 if (isPromise(body)) {
57341 body.then((newData) => handleReply(mockDispatches, newData));
57342 return;
57343 }
57344 const responseData = getResponseData(body);
57345 const responseHeaders = generateKeyValues(headers);
57346 const responseTrailers = generateKeyValues(trailers);
57347 handler.abort = nop;
57348 handler.onHeaders(statusCode, responseHeaders, resume2, getStatusText(statusCode));
57349 handler.onData(Buffer.from(responseData));
57350 handler.onComplete(responseTrailers);
57351 deleteMockDispatch(mockDispatches, key);
57352 }
57353 function resume2() {

Callers

nothing calls this directly

Calls 7

buildKeyFunction · 0.85
getMockDispatchFunction · 0.85
deleteMockDispatchFunction · 0.85
setTimeoutFunction · 0.85
handleReplyFunction · 0.85
callbackMethod · 0.80
onErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…