mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
80e5161a20
* fix non-context-aware imports * extract _actuallySend to file * extract CLI unit test function from renderer * expose curl functions to the ipc renderer * use curl through ipcRenderer * feedback first pass make like grpc * feedback second pass remove duplicate * fix lint
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import 'core-js/stable';
|
|
import 'regenerator-runtime/runtime';
|
|
|
|
import { database } from '../app/common/database';
|
|
import { BaseModel, types as modelTypes } from '../app/models';
|
|
import * as models from '../app/models';
|
|
import { Settings } from '../app/models/settings';
|
|
import { _actuallySend } from '../app/network/curl';
|
|
import { sendAndTransform } from '../app/network/network';
|
|
|
|
// The network layer uses settings from the settings model
|
|
// We want to give consumers the ability to override certain settings
|
|
type SettingsOverride = Pick<Settings, 'validateSSL'>;
|
|
|
|
export async function getSendRequestCallbackMemDb(environmentId: string, memDB: any, settingsOverrides?: SettingsOverride) {
|
|
// Initialize the DB in-memory and fill it with data if we're given one
|
|
await database.init(
|
|
modelTypes(),
|
|
{
|
|
inMemoryOnly: true,
|
|
},
|
|
true,
|
|
() => { },
|
|
);
|
|
const docs: BaseModel[] = [];
|
|
|
|
const settings = await models.settings.getOrCreate();
|
|
docs.push({ ...settings, ...settingsOverrides });
|
|
|
|
for (const type of Object.keys(memDB)) {
|
|
for (const doc of memDB[type]) {
|
|
docs.push(doc);
|
|
}
|
|
}
|
|
|
|
await database.batchModifyDocs({
|
|
upsert: docs,
|
|
remove: [],
|
|
});
|
|
|
|
// Return callback helper to send requests
|
|
return async function sendRequest(requestId: string) {
|
|
return sendAndTransform(requestId, environmentId, _actuallySend);
|
|
};
|
|
}
|