insomnia/packages/insomnia-app/send-request/index.ts
Jack Kavanagh 80e5161a20
Fix: disabled native modules in the renderer (#4230)
* 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
2021-12-02 09:26:08 +00:00

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);
};
}