Skip to content

Commit a161c95

Browse files
authored
feat: migrate models to insomnia-data - p7 (#9743)
* add initial migration * remove use unused functions
1 parent 66f4547 commit a161c95

150 files changed

Lines changed: 1086 additions & 1032 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/insomnia-inso/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import orderedJSON from 'json-order';
2121
import { parseArgsStringToArgv } from 'string-argv';
2222
import { v4 as uuidv4 } from 'uuid';
2323

24+
import type { Workspace } from '~/insomnia-data';
2425
import { initServices } from '~/insomnia-data';
2526
import { servicesNodeImpl } from '~/insomnia-data/node';
26-
import type { Workspace } from '~/models/workspace';
2727

2828
import type { RequestTestResult } from '../../insomnia-scripting-environment/src/objects';
2929
import packageJson from '../package.json';

packages/insomnia-inso/src/commands/run-collection/result-report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import nodePath from 'node:path';
44
import type { Consola } from 'consola';
55
import { pick } from 'es-toolkit';
66

7+
import type { Workspace } from '~/insomnia-data';
78
import type { Environment, UserUploadEnvironment } from '~/models/environment';
89
import type { Request, RequestAuthentication, RequestHeader } from '~/models/request';
9-
import type { Workspace } from '~/models/workspace';
1010
import { typedKeys } from '~/utils';
1111

1212
import type { RequestTestResult } from '../../../../insomnia-scripting-environment/src/objects';

packages/insomnia/src/account/session.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { logout as logoutAPI, whoami } from 'insomnia-api';
22

3-
import type { GitRepository } from '~/insomnia-data';
3+
import type { GitRepository, WorkspaceMeta } from '~/insomnia-data';
44
import { services } from '~/insomnia-data';
55

66
import { AI_PLUGIN_NAME, LLM_BACKENDS } from '../common/constants';
77
import { database } from '../common/database';
88
import { project, workspaceMeta } from '../models';
99
import { EMPTY_GIT_PROJECT_ID, type Project } from '../models/project';
10-
import type { WorkspaceMeta } from '../models/workspace-meta';
1110
import * as crypt from './crypt';
1211

1312
export interface SessionData {
@@ -227,7 +226,7 @@ async function _removeGitRepository(repo: GitRepository) {
227226

228227
const workspaceMetas = await database.find<WorkspaceMeta>(workspaceMeta.type, { gitRepositoryId: repo._id });
229228
for (const wsMeta of workspaceMetas) {
230-
await workspaceMeta.update(wsMeta, { gitRepositoryId: null });
229+
await services.workspaceMeta.update(wsMeta, { gitRepositoryId: null });
231230
}
232231
await services.gitRepository.remove(repo);
233232
}

packages/insomnia/src/common/__tests__/har.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('export', () => {
2121

2222
describe('exportHar()', () => {
2323
it('exports single requests', async () => {
24-
const wrk = await models.workspace.create({
24+
const wrk = await services.workspace.create({
2525
_id: 'wrk_1',
2626
name: 'Workspace',
2727
});
@@ -145,7 +145,7 @@ describe('export', () => {
145145
});
146146

147147
it('exports multiple requests', async () => {
148-
const workspace = await models.workspace.create({
148+
const workspace = await services.workspace.create({
149149
_id: 'wrk_1',
150150
name: 'Workspace',
151151
});
@@ -394,7 +394,7 @@ describe('export', () => {
394394

395395
describe('exportHarWithRequest()', () => {
396396
it('renders does it correctly', async () => {
397-
const workspace = await models.workspace.create();
397+
const workspace = await services.workspace.create();
398398
const cookies: Cookie[] = [
399399
{
400400
id: '',
@@ -487,7 +487,7 @@ describe('export', () => {
487487
});
488488

489489
it('export multipart request with file', async () => {
490-
const workspace = await models.workspace.create();
490+
const workspace = await services.workspace.create();
491491
const request: Request = {
492492
...models.request.init(),
493493
_id: 'req_123',

packages/insomnia/src/common/__tests__/import.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import path from 'node:path';
44
import { describe, expect, it } from 'vitest';
55
import { parse } from 'yaml';
66

7-
import { environment, project, request, requestGroup, workspace } from '../../models';
7+
import { services } from '~/insomnia-data';
8+
9+
import { environment, project, request, requestGroup } from '../../models';
810
import { EnvironmentKvPairDataType } from '../../models/environment';
911
import * as importUtil from '../import';
1012
import { INSOMNIA_SCHEMA_VERSION } from '../insomnia-schema-migrations/schema-version';
@@ -159,8 +161,8 @@ describe('importRaw()', () => {
159161
projectId: projectToImportTo._id,
160162
});
161163

162-
const workspacesCount = await workspace.count();
163-
const projectWorkspaces = await workspace.findByParentId(projectToImportTo._id);
164+
const workspacesCount = await services.workspace.count();
165+
const projectWorkspaces = await services.workspace.findByParentId(projectToImportTo._id);
164166
const curlRequests = await request.findByParentId(projectWorkspaces[0]._id);
165167

166168
expect(workspacesCount).toBe(1);
@@ -176,7 +178,7 @@ describe('importRaw()', () => {
176178
const fixturePath = path.join(__dirname, '..', '__fixtures__', 'curl', 'complex-input.sh');
177179
const content = fs.readFileSync(fixturePath, 'utf8').toString();
178180

179-
const existingWorkspace = await workspace.create();
181+
const existingWorkspace = await services.workspace.create();
180182

181183
const scanResult = await importUtil.scanResources([
182184
{
@@ -217,7 +219,7 @@ describe('importRaw()', () => {
217219
projectId: projectToImportTo._id,
218220
});
219221

220-
const projectWorkspaces = await workspace.findByParentId(projectToImportTo._id);
222+
const projectWorkspaces = await services.workspace.findByParentId(projectToImportTo._id);
221223

222224
const requestGroups = await requestGroup.findByParentId(projectWorkspaces[0]._id);
223225
const requests = await request.findByParentId(requestGroups[0]._id);
@@ -231,7 +233,7 @@ describe('importRaw()', () => {
231233
const fixturePath = path.join(__dirname, '..', '__fixtures__', 'postman', 'aws-signature-auth-v2_0-input.json');
232234
const content = fs.readFileSync(fixturePath, 'utf8').toString();
233235

234-
const existingWorkspace = await workspace.create();
236+
const existingWorkspace = await services.workspace.create();
235237

236238
const scanResult = await importUtil.scanResources([
237239
{
@@ -295,7 +297,7 @@ describe('importRaw()', () => {
295297
projectId: projectToImportTo._id,
296298
});
297299

298-
const projectWorkspaces = await workspace.findByParentId(projectId);
300+
const projectWorkspaces = await services.workspace.findByParentId(projectId);
299301
const importedWorkspaceId = projectWorkspaces[0]._id;
300302
const requestBaseEnvironment = await environment.getByParentId(importedWorkspaceId);
301303

@@ -317,7 +319,7 @@ describe('importRaw()', () => {
317319
);
318320
const content = fs.readFileSync(fixturePath, 'utf8').toString();
319321

320-
const existingWorkspace = await workspace.create();
322+
const existingWorkspace = await services.workspace.create();
321323
const workspaceId = existingWorkspace._id;
322324
const baseEnvironment = await environment.getOrCreateForParentId(workspaceId);
323325
await environment.update(baseEnvironment, {
@@ -358,7 +360,7 @@ describe('importRaw()', () => {
358360
);
359361
const content = fs.readFileSync(fixturePath, 'utf8').toString();
360362

361-
const existingWorkspace = await workspace.create();
363+
const existingWorkspace = await services.workspace.create();
362364
const workspaceId = existingWorkspace._id;
363365
const baseEnvironmentPair = [
364366
{
@@ -421,7 +423,7 @@ describe('importRaw()', () => {
421423
);
422424
const content = fs.readFileSync(fixturePath, 'utf8').toString();
423425

424-
const existingWorkspace = await workspace.create();
426+
const existingWorkspace = await services.workspace.create();
425427
const workspaceId = existingWorkspace._id;
426428
const baseEnvironmentPair = [
427429
{

packages/insomnia/src/common/__tests__/insomnia-v5.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Insomnia v5 Import/Export - Comprehensive Tests', () => {
3434
name: 'Test Project',
3535
});
3636

37-
await models.workspace.create({
37+
await services.workspace.create({
3838
_id: 'wrk_test',
3939
name: 'Test Workspace',
4040
parentId: 'proj_test',
@@ -159,7 +159,7 @@ collection: []
159159

160160
describe('getInsomniaV5DataExport', () => {
161161
it('exports workspace with requests correctly', async () => {
162-
const workspace = await models.workspace.create({
162+
const workspace = await services.workspace.create({
163163
_id: 'wrk_export_test',
164164
name: 'Export Test Workspace',
165165
parentId: 'proj_test',
@@ -205,7 +205,7 @@ collection: []
205205
});
206206

207207
it('handles empty workspace gracefully', async () => {
208-
const workspace = await models.workspace.create({
208+
const workspace = await services.workspace.create({
209209
_id: 'wrk_empty_test',
210210
name: 'Empty Workspace',
211211
parentId: 'proj_test',
@@ -231,7 +231,7 @@ collection: []
231231
});
232232

233233
it('filters requests when requestIds are provided', async () => {
234-
const workspace = await models.workspace.create({
234+
const workspace = await services.workspace.create({
235235
_id: 'wrk_filter_test',
236236
name: 'Filter Workspace',
237237
parentId: 'proj_test',
@@ -273,7 +273,7 @@ collection: []
273273
});
274274

275275
it('handles design workspace correctly', async () => {
276-
const workspace = await models.workspace.create({
276+
const workspace = await services.workspace.create({
277277
_id: 'wrk_design_test',
278278
name: 'Design Workspace',
279279
parentId: 'proj_test',
@@ -304,14 +304,14 @@ collection: []
304304
});
305305

306306
it('handles mock server scope', async () => {
307-
const workspace = await models.workspace.create({
307+
const workspace = await services.workspace.create({
308308
_id: 'wrk_mock',
309309
name: 'Mock Workspace',
310310
parentId: 'proj_test',
311311
scope: 'mock-server',
312312
});
313313

314-
await models.mockServer.create({
314+
await services.mockServer.create({
315315
_id: 'mock_1',
316316
name: 'Test Server',
317317
parentId: workspace._id,
@@ -329,7 +329,7 @@ collection: []
329329
});
330330

331331
it('handles mcp client scope', async () => {
332-
const workspace = await models.workspace.create({
332+
const workspace = await services.workspace.create({
333333
_id: 'wrk_mcp',
334334
name: 'MCP Workspace',
335335
parentId: 'proj_test',

packages/insomnia/src/common/__tests__/render.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createBuilder } from '@develohpanda/fluent-builder';
22
import { beforeEach, describe, expect, it } from 'vitest';
33

4+
import type { Workspace } from '~/insomnia-data';
45
import { services } from '~/insomnia-data';
56

67
import * as models from '../../models';
78
import { environmentModelSchema, requestGroupModelSchema } from '../../models/__schemas__/model-schemas';
89
import type { Environment } from '../../models/environment';
9-
import type { Workspace } from '../../models/workspace';
1010
import * as renderUtils from '../render';
1111

1212
const envBuilder = createBuilder(environmentModelSchema);
@@ -625,15 +625,15 @@ describe('render tests', () => {
625625

626626
describe('getRenderedGrpcRequestMessage()', () => {
627627
it('renders only the body for a grpc request ', async () => {
628-
const w1 = await models.workspace.create();
628+
const w1 = await services.workspace.create();
629629
const env = await models.environment.create({
630630
parentId: w1._id,
631631
data: {
632632
foo: 'bar',
633633
host: 'testb.in:9000',
634634
},
635635
});
636-
const grpcRequest = await models.grpcRequest.create({
636+
const grpcRequest = await services.grpcRequest.create({
637637
parentId: w1._id,
638638
name: 'hi {{ foo }}',
639639
url: '{{ host }}',
@@ -656,7 +656,7 @@ describe('render tests', () => {
656656
let env: Environment;
657657

658658
beforeEach(async () => {
659-
w1 = await models.workspace.create();
659+
w1 = await services.workspace.create();
660660
env = await models.environment.create({
661661
parentId: w1._id,
662662
data: {
@@ -667,7 +667,7 @@ describe('render tests', () => {
667667
});
668668

669669
it('renders all grpc request properties', async () => {
670-
const grpcRequest = await models.grpcRequest.create({
670+
const grpcRequest = await services.grpcRequest.create({
671671
parentId: w1._id,
672672
name: 'hi {{ foo }}',
673673
url: '{{ host }}',
@@ -690,7 +690,7 @@ describe('render tests', () => {
690690
});
691691

692692
it('renders but ignores the body for a grpc request ', async () => {
693-
const grpcRequest = await models.grpcRequest.create({
693+
const grpcRequest = await services.grpcRequest.create({
694694
parentId: w1._id,
695695
name: 'hi {{ foo }}',
696696
url: '{{ host }}',
@@ -717,7 +717,7 @@ describe('render tests', () => {
717717
});
718718

719719
it('should still render with bad description', async () => {
720-
const grpcRequest = await models.grpcRequest.create({
720+
const grpcRequest = await services.grpcRequest.create({
721721
parentId: w1._id,
722722
name: 'hi {{ foo }}',
723723
url: '{{ host }}',
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { describe, expect, it } from 'vitest';
22

33
import * as models from '../../models';
4-
import { WorkspaceScopeKeys } from '../../models/workspace';
54
import { getWorkspaceLabel } from '../get-workspace-label';
65
import { strings } from '../strings';
76

87
describe('getWorkspaceLabel', () => {
98
it('should return document label', () => {
109
const w = models.workspace.init();
11-
w.scope = WorkspaceScopeKeys.design;
10+
w.scope = models.workspace.WorkspaceScopeKeys.design;
1211
expect(getWorkspaceLabel(w)).toBe(strings.document);
1312
});
1413

1514
it('should return collection label', () => {
1615
const w = models.workspace.init();
17-
w.scope = WorkspaceScopeKeys.collection;
16+
w.scope = models.workspace.WorkspaceScopeKeys.collection;
1817
expect(getWorkspaceLabel(w)).toBe(strings.collection);
1918
});
2019
});

packages/insomnia/src/common/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { MockServer } from '~/insomnia-data';
2+
13
import appConfig from '../../config/config.json';
24
import { version } from '../../package.json';
3-
import type { MockServer } from '../models/mock-server';
45
import { isLinux, isMac, isWindows, platform } from './platform';
56

67
// Vite is filtering out process.env variables that are not prefixed with VITE_.

packages/insomnia/src/common/get-workspace-label.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { IconProp } from '@fortawesome/fontawesome-svg-core';
22

3-
import { isDesign, isEnvironment, isMcp, isMockServer, type Workspace, type WorkspaceScope } from '../models/workspace';
3+
import type { Workspace, WorkspaceScope } from '~/insomnia-data';
4+
import { models } from '~/insomnia-data';
5+
46
import { strings } from './strings';
57

68
export type ProjectScopeKeys = WorkspaceScope | 'unsynced';
@@ -45,19 +47,19 @@ export const scopeToTextColorMap: Record<ProjectScopeKeys, string> = {
4547
};
4648

4749
export const getWorkspaceLabel = (workspace: Workspace) => {
48-
if (isDesign(workspace)) {
50+
if (models.workspace.isDesign(workspace)) {
4951
return strings.document;
5052
}
5153

52-
if (isMockServer(workspace)) {
54+
if (models.workspace.isMockServer(workspace)) {
5355
return strings.mock;
5456
}
5557

56-
if (isEnvironment(workspace)) {
58+
if (models.workspace.isEnvironment(workspace)) {
5759
return strings.environment;
5860
}
5961

60-
if (isMcp(workspace)) {
62+
if (models.workspace.isMcp(workspace)) {
6163
return strings.mcp;
6264
}
6365

0 commit comments

Comments
 (0)