refactor: extract insomnia-data into workspace package (#10010)

Move insomnia-data models, services, database code, and common utilities into a dedicated workspace package. Update consumers to import from the new package entrypoints and declare workspace dependencies for the extracted package.
This commit is contained in:
Bingbing
2026-06-02 09:49:10 +00:00
committed by GitHub
parent 1b755cb83e
commit b09cde814d
175 changed files with 232 additions and 95 deletions
+1 -2
View File
@@ -58,8 +58,6 @@ npm -v
`insomnia/` ← Main Electron app
`src/`
`common/` ← Shared utils, settings types
`models/` ← Data model definitions
`insomnia-data/` ← Model defaults, init(), NeDB db implementation, business logic
`routes/` ← React Router files (clientLoader/clientAction)
`ui/` ← React components, hooks, `insomnia-fetch.ts`
`main/` ← Electron IPC handlers, `preload.ts`
@@ -67,6 +65,7 @@ npm -v
`sync/` ← Git/VCS sync
`network/` ← Request execution engine
`templating/` ← Nunjucks rendering (Web Worker)
`insomnia-data/` ← Data models, services, NeDB implementation, shared data utilities
`insomnia-api/` ← Cloud API client
`insomnia-inso/` ← CLI tool
`insomnia-testing/` ← Test framework
+1 -1
View File
@@ -22,6 +22,7 @@ There are a few more technologies and tools worth mentioning:
Insomnia uses [`npm workspaces`](https://docs.npmjs.com/cli/v9/using-npm/workspaces?v=true) to manage multiple npm packages within a single repository. There are currently the following package locations:
- `/packages` contains related packages that are consumed by `insomnia` or externally.
- `/packages/insomnia-data` contains shared data models, model services, database adapters, and common data utilities used by the app and CLI.
Insomnia Inso CLI is built using a series of steps
@@ -61,7 +62,6 @@ There are a few notable directories inside it:
- `/src/ui` React components and styling.
- `/src/common` Utilities used across both main and render processes.
- `/src/plugins` Logic around installation and usage of plugins.
- `/src/insomnia-data` Data models, services and database for managing application state.
- `/src/network` Sending requests and performing auth (e.g. OAuth 2).
- `/src/templating` Nunjucks and rendering related code.
- `/src/sync` and `/src/account` Team sync and account stuff.
+1 -6
View File
@@ -23,16 +23,11 @@ const generalRestrictedImportPatterns = [
group: ['./**/insomnia-data', './**/insomnia-data/**', '../**/insomnia-data', '../**/insomnia-data/**'],
message: "Please use 'insomnia-data' instead of relative paths",
},
// Only allow insomnia-data and insomnia-data/node
// Only allow supported insomnia-data entrypoints
{
regex: '^insomnia-data/(?!node($|/)|common($|/)).+',
message: "Only 'insomnia-data', 'insomnia-data/node' and 'insomnia-data/common' are allowed",
},
// Only allow insomnia-data, not allow ~/insomnia-data anymore
{
regex: '^~/insomnia-data(/.*)?$',
message: "Please use 'insomnia-data' instead of '~/insomnia-data'",
},
];
const rendererNodeMigrationOffenders = [
'packages/insomnia/src/common/misc.ts',
+22 -1
View File
@@ -12,6 +12,7 @@
"workspaces": [
"packages/insomnia-testing",
"packages/insomnia",
"packages/insomnia-data",
"packages/insomnia-analytics",
"packages/insomnia-api",
"packages/insomnia-inso",
@@ -18399,6 +18400,10 @@
"resolved": "packages/insomnia-api",
"link": true
},
"node_modules/insomnia-data": {
"resolved": "packages/insomnia-data",
"link": true
},
"node_modules/insomnia-inso": {
"resolved": "packages/insomnia-inso",
"link": true
@@ -29163,7 +29168,6 @@
"@rjsf/core": "6.0.0-beta.15",
"@rjsf/utils": "6.0.0-beta.15",
"@rjsf/validator-ajv8": "6.0.0-beta.15",
"@seald-io/nedb": "^4.1.1",
"@sentry/electron": "^6.5.0",
"@stoplight/spectral-core": "^1.22.0",
"@stoplight/spectral-formats": "^1.8.2",
@@ -29330,6 +29334,23 @@
"@getinsomnia/insomnia-v3-fetch": "^1.0.1"
}
},
"packages/insomnia-data": {
"version": "12.5.1-alpha.0",
"license": "Apache-2.0",
"dependencies": {
"@seald-io/nedb": "^4.1.1",
"deep-equal": "2.2.3",
"graphql": "^16.10.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@getinsomnia/node-libcurl": "3.2.2",
"@modelcontextprotocol/sdk": "^1.17.5",
"@types/deep-equal": "^1.0.4",
"mocha": "^11.7.5",
"type-fest": "^4.40.0"
}
},
"packages/insomnia-inso": {
"version": "12.5.1-alpha.0",
"license": "Apache-2.0",
+1
View File
@@ -17,6 +17,7 @@
"workspaces": [
"packages/insomnia-testing",
"packages/insomnia",
"packages/insomnia-data",
"packages/insomnia-analytics",
"packages/insomnia-api",
"packages/insomnia-inso",
@@ -4,8 +4,15 @@ interface INodeProcess {
platform: string;
}
declare const window: {
app?: {
process: INodeProcess;
};
};
let nodeProcess: INodeProcess | undefined;
if (
// eslint-disable-next-line unicorn/no-typeof-undefined
typeof window !== 'undefined' &&
window.app?.process !== undefined &&
typeof window.app.process.platform === 'string'
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023", "WebWorker"],
"types": []
},
"include": ["./**/*.ts"]
}
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023", "WebWorker"],
"types": ["node"]
},
"include": ["./**/*.ts"]
}
+49
View File
@@ -0,0 +1,49 @@
{
"private": true,
"name": "insomnia-data",
"license": "Apache-2.0",
"version": "12.5.1-alpha.0",
"author": "Kong <[email protected]>",
"description": "Insomnia data functionalities",
"repository": {
"type": "git",
"url": "git+https://github.com/Kong/insomnia.git",
"directory": "packages/insomnia-data"
},
"bugs": {
"url": "https://github.com/kong/insomnia/issues"
},
"homepage": "https://github.com/Kong/insomnia#readme",
"exports": {
".": {
"import": "./src/index.ts",
"types": "./src/index.ts"
},
"./node": {
"import": "./node-src/index.ts",
"types": "./node-src/index.ts"
},
"./common": {
"import": "./common-src/index.ts",
"types": "./common-src/index.ts"
}
},
"scripts": {
"lint": "eslint . --ext .ts,.tsx --cache",
"type-check": "tsc -p src/tsconfig.json && tsc -p common-src/tsconfig.json && tsc -p node-src/tsconfig.json && tsc -p tsconfig.test.json",
"test": "vitest run"
},
"dependencies": {
"@seald-io/nedb": "^4.1.1",
"deep-equal": "2.2.3",
"graphql": "^16.10.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@getinsomnia/node-libcurl": "3.2.2",
"@modelcontextprotocol/sdk": "^1.17.5",
"@types/deep-equal": "^1.0.4",
"mocha": "^11.7.5",
"type-fest": "^4.40.0"
}
}
+13
View File
@@ -0,0 +1,13 @@
import { initDatabase, initServices } from 'insomnia-data';
import { createNedbDatabase, servicesNodeImpl } from 'insomnia-data/node';
import { vi } from 'vitest';
const database = createNedbDatabase();
await initDatabase(database, { inMemoryOnly: true }, true);
await initServices(servicesNodeImpl);
import { v4Mock } from './__mocks__/uuid';
vi.mock('uuid', () => ({
v4: () => v4Mock(),
}));

Some files were not shown because too many files have changed in this diff Show More