mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-29 10:33:04 -04:00
feat: make insomnia-data as a package
This commit is contained in:
@@ -156,13 +156,13 @@ export default defineConfig([
|
||||
},
|
||||
// Block relative paths to insomnia-data
|
||||
{
|
||||
group: ['./**/insomnia-data', './**/insomnia-data/**', '../**/insomnia-data', '../**/insomnia-data/**'],
|
||||
message: "Please use '~/insomnia-data' instead of relative paths",
|
||||
group: ['**/*/insomnia-data/**'],
|
||||
message: "Please use 'insomnia-data' instead of relative paths",
|
||||
},
|
||||
// Only allow ~/insomnia-data, ~/insomnia-data/node and ~/insomnia-data/common
|
||||
// Only allow insomnia-data, insomnia-data/node and insomnia-data/common
|
||||
{
|
||||
regex: '^~/insomnia-data/(?!node($|/)|common($|/)).+',
|
||||
message: "Only '~/insomnia-data', '~/insomnia-data/node' and '~/insomnia-data/common' are allowed",
|
||||
regex: '^insomnia-data/(?!node($|/)|common($|/)).+',
|
||||
message: "Only 'insomnia-data', 'insomnia-data/node' and 'insomnia-data/common' are allowed",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -11,8 +11,8 @@
|
||||
"license": "Apache-2.0",
|
||||
"workspaces": [
|
||||
"packages/insomnia-testing",
|
||||
"packages/insomnia-common",
|
||||
"packages/insomnia",
|
||||
"packages/insomnia-data",
|
||||
"packages/insomnia-api",
|
||||
"packages/insomnia-inso",
|
||||
"packages/insomnia-smoke-test",
|
||||
@@ -20239,8 +20239,8 @@
|
||||
"resolved": "packages/insomnia-api",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/insomnia-common": {
|
||||
"resolved": "packages/insomnia-common",
|
||||
"node_modules/insomnia-data": {
|
||||
"resolved": "packages/insomnia-data",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/insomnia-inso": {
|
||||
@@ -31407,6 +31407,11 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"packages/insomnia-common": {
|
||||
"version": "12.4.0",
|
||||
"extraneous": true,
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"packages/insomnia-data": {
|
||||
"version": "12.4.0",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"workspaces": [
|
||||
"packages/insomnia-testing",
|
||||
"packages/insomnia",
|
||||
"packages/insomnia-data",
|
||||
"packages/insomnia-api",
|
||||
"packages/insomnia-inso",
|
||||
"packages/insomnia-smoke-test",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"rootDirs": ["."],
|
||||
"lib": ["ES2023", "DOM"],
|
||||
"lib": ["ES2023", "WebWorker"],
|
||||
"types": [],
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
|
||||
@@ -95,9 +95,9 @@ Renderer services path:
|
||||
### Main
|
||||
|
||||
```ts
|
||||
import { initDatabase, initServices } from '~/insomnia-data';
|
||||
import { initDatabase, initServices } from 'insomnia-data';
|
||||
import { mainDatabase } from '~/main/database.main';
|
||||
import { servicesNodeImpl } from '~/insomnia-data/node';
|
||||
import { servicesNodeImpl } from 'insomnia-data/node';
|
||||
|
||||
await initDatabase(mainDatabase);
|
||||
initServices(servicesNodeImpl);
|
||||
@@ -106,7 +106,7 @@ initServices(servicesNodeImpl);
|
||||
### Renderer
|
||||
|
||||
```ts
|
||||
import { initDatabase, initServices } from '~/insomnia-data';
|
||||
import { initDatabase, initServices } from 'insomnia-data';
|
||||
import { clientDatabase } from '~/ui/database.client';
|
||||
|
||||
await initDatabase(clientDatabase);
|
||||
@@ -116,8 +116,8 @@ initServices(window._dataServices);
|
||||
### Inso / Node
|
||||
|
||||
```ts
|
||||
import { initDatabase, initServices } from '~/insomnia-data';
|
||||
import { createNedbDatabase, servicesNodeImpl } from '~/insomnia-data/node';
|
||||
import { initDatabase, initServices } from 'insomnia-data';
|
||||
import { createNedbDatabase, servicesNodeImpl } from 'insomnia-data/node';
|
||||
|
||||
await initDatabase(createNedbDatabase());
|
||||
initServices(servicesNodeImpl);
|
||||
@@ -126,7 +126,7 @@ initServices(servicesNodeImpl);
|
||||
### Consuming
|
||||
|
||||
```ts
|
||||
import { services, models, type Request } from '~/insomnia-data';
|
||||
import { services, models, type Request } from 'insomnia-data';
|
||||
|
||||
const mcpRequest = await services.mcpRequest.create({ url: 'http://localhost:3000' });
|
||||
const all = await services.mcpRequest.all();
|
||||
188
packages/insomnia-data/__mocks__/uuid.ts
Normal file
188
packages/insomnia-data/__mocks__/uuid.ts
Normal file
@@ -0,0 +1,188 @@
|
||||
let v4Counter = 0;
|
||||
|
||||
const v4UUIDs = [
|
||||
'cc1dd2ca-4275-747a-a881-99e8efd42403',
|
||||
'dd2ccc1a-2745-477a-881a-9e8ef9d42403',
|
||||
'e3e96e5f-dd68-4229-8b66-dee1f0940f3d',
|
||||
'a262d22b-5fa8-491c-9bd9-58fba03e301e',
|
||||
'2e7c2688-09ee-44b8-900d-5cbbaa7d3a19',
|
||||
'e7d698c4-c7d2-409c-90c6-22bcc94ba4ab',
|
||||
'fcef5ff8-4f78-4f16-bad4-9bdddc1c3daf',
|
||||
'7cc5b3e1-3333-4419-b370-6fcaa05c15ab',
|
||||
'd911be1d-69f6-4cb1-8312-2c3b7f0c647c',
|
||||
'ac47b0b9-aded-4968-b569-239598b7d7d1',
|
||||
'4093d252-02b6-464f-a723-494a35a7b862',
|
||||
'6d233089-e303-450b-9f1a-f6f6e6869e27',
|
||||
'874d55b5-2526-4476-8964-85f7cd685705',
|
||||
'e2a5848c-f908-4a0e-8b0a-727edbcafe89',
|
||||
'67884e55-155e-43fc-a7ad-97d23e853241',
|
||||
'130929e6-4953-45a5-9a25-b3df6fa8dca8',
|
||||
'd854aa77-5389-4690-be5e-52fd3c5c0551',
|
||||
'a5218a75-61c1-4f86-8f09-09c5c1831e7b',
|
||||
'5fd86b39-825e-4b12-a163-6dd5592b8172',
|
||||
'8c4b90c5-1cf7-4c28-a60b-ec156be97a7f',
|
||||
'3f913e38-c08e-4839-95f6-32788141951f',
|
||||
'884b5a86-5e6d-49ef-8bea-b5dcb7564cdc',
|
||||
'2fea36e5-4e92-4da6-8088-2821f580cf20',
|
||||
'1e310193-7209-430d-9ed2-f8d73ec932b5',
|
||||
'9996a7f7-ff6a-414e-9a75-2adadbde88a9',
|
||||
'562f0a86-0d2a-4137-b9c7-ff92b70939b4',
|
||||
'c62e98f8-def0-4560-bcb6-59ac1d64ac61',
|
||||
'548b6bbb-b224-408f-9f38-215b0c40bd71',
|
||||
'e2ee0259-98ca-4c0e-a7c4-3b29beae901c',
|
||||
'782c08cd-e725-4089-8023-ffce72d1c853',
|
||||
'9b176a7f-1e50-4ebd-8758-2d4c3197fb24',
|
||||
'e29ffcfc-d277-4302-92bf-d279e4b8d03f',
|
||||
'f6b81add-3e80-49dc-86ef-f2f43ad13f9d',
|
||||
'a5a9bb1e-67f4-4cfe-a3cd-cdf802378eb9',
|
||||
'95b2f335-87f7-4257-b069-197242408660',
|
||||
'9b5ad4fc-0b14-4d13-8d01-7e6fde1b48b7',
|
||||
'a37d9af3-1f60-47c0-a114-4ae345d3005c',
|
||||
'e5540caa-f250-42f7-b5a5-c4d60963569f',
|
||||
'7ea6be14-582f-4105-9905-a30f2be72ad8',
|
||||
'9fc10ee2-6135-454d-9aa8-b2a82b766c03',
|
||||
'40492eb7-a9c1-4d67-b49b-c7c6be8d9ccd',
|
||||
'c939099b-6b8c-4acd-9738-883c409b713c',
|
||||
'ed9adb1e-e27f-484c-9d32-3f351759c757',
|
||||
'73781cfd-6d55-47b2-8735-8e90ee8d8320',
|
||||
'd983abdb-ab5a-44f8-888a-2d98c123db54',
|
||||
'8acca410-43ec-4d75-b553-97ea0de8735f',
|
||||
'8a5a2550-1289-4bef-903c-9ce3c9c9d5c5',
|
||||
'041462ba-dbfc-4381-b34b-1d03c043f10e',
|
||||
'f7dd76f2-efd8-439b-a2d3-89f09570bea8',
|
||||
'9e4ccefd-5968-4dc2-83e3-b9a8e1815a1b',
|
||||
'9654696e-747c-4116-b197-94e31d2daaff',
|
||||
'eba603bc-a93c-4fa6-86d0-01a6dfccb3bd',
|
||||
'9d1b76df-8a02-4d86-ae0c-0423cf41e097',
|
||||
'38511ada-296b-4353-8fca-131b67283016',
|
||||
'f1a6d808-8b2b-4502-b42a-5ca4fcfa5b51',
|
||||
'a6d670f1-bbbd-45fa-8834-ffccb4292ee1',
|
||||
'c8a35834-c4a3-4950-915b-8ec0af8a957a',
|
||||
'23fcf651-d24e-4a5d-8631-f5f7d54143c5',
|
||||
'5d0dc5e0-a827-4b1a-b787-4050ab15deba',
|
||||
'32a1b905-15c5-48b3-b9a3-59c9f4f14b27',
|
||||
'97a340b2-91e3-4c9e-9040-e751291e533e',
|
||||
'c352d95b-c77a-4192-9e52-2b43e5d45c75',
|
||||
'65c46c7b-d7f9-4367-84af-51018a68beec',
|
||||
'304a7d57-9d08-4b8f-983f-14d69c49f8fe',
|
||||
'817124d8-e40b-400e-8165-ee6cb4459ffe',
|
||||
'033caad7-5765-426a-ac55-7d95f63550b6',
|
||||
'395177a1-b026-49c1-abf0-e95bcde88c3b',
|
||||
'af8642aa-ff28-4aca-b32e-02e6772d0399',
|
||||
'719fd155-a11b-415f-a042-6293c143793f',
|
||||
'46409dfc-a668-4922-8a6b-245588a363c6',
|
||||
'ff89d2bc-6781-4a09-a2fa-4c9fc9d8f539',
|
||||
'6d6e6070-c192-46dc-ae1a-4b819828fbae',
|
||||
'650345e6-73c5-49f1-92cc-b16f70dfabf0',
|
||||
'8d85d153-da68-4123-a3f8-03753be9c7e8',
|
||||
'185dc090-3fcc-44e3-8a17-4e2fa792f91a',
|
||||
'f8e9aae9-1e6f-45c3-923a-74af73f4091e',
|
||||
'73415a9e-2f83-48c6-814a-7aed39e54247',
|
||||
'f2e38b71-2a4a-41e2-bc90-162b0e2cc64f',
|
||||
'f8db47d9-cfac-4fd9-8ed0-f510ff0005d0',
|
||||
'aabeb013-7093-4d32-ba97-e4e281a7dffd',
|
||||
'57b034dd-7ac9-4e40-a5ff-9833c1d516fc',
|
||||
'93375f26-ada3-4490-af12-91f6858b64fc',
|
||||
'4e819358-b61e-42fa-aa05-286de238f2f6',
|
||||
'b61fe05c-a8c3-439e-8c78-7ee52e223e8a',
|
||||
'e558ea51-6f7f-4b0e-99d3-46df7ae61a84',
|
||||
'acd531c1-9f6c-44ff-ba1b-95f71a37e06b',
|
||||
'0b3c8769-6048-4dfd-9372-c96da8d10193',
|
||||
'2fe19a46-e764-4529-9ac4-e37c6b396e1e',
|
||||
'819a28c7-f967-45b8-b94f-59726d425270',
|
||||
'f0135da4-9d86-4eb8-8292-0405fa8cd2c4',
|
||||
'd72ac779-4874-48ec-af86-b409a0f8ef31',
|
||||
'108077e9-7b41-4169-aeed-34b145202efe',
|
||||
'7aa43e17-9a14-48dc-8c96-c4281abbb332',
|
||||
'1a509a8f-c213-484a-a85b-389ccb1be529',
|
||||
'5798513c-be4c-4deb-be4c-9cafa30f4ff8',
|
||||
'fac20481-0235-4af5-b2ae-fed135a5e1e2',
|
||||
'86ef9755-a5bb-4068-9273-a5ca4cef6912',
|
||||
'850bbe11-da72-407c-ac75-37ba7b9597e3',
|
||||
'433d68f7-c02f-49b1-9faa-6f40520b9dfe',
|
||||
'd14e8023-1bab-49be-b9fe-8b8987f7b489',
|
||||
'f78feb38-4aa3-4801-b56d-0e43a9361bfc',
|
||||
'd4a187c0-a41a-4ed6-8206-1982c85131d3',
|
||||
'0baf29de-0f22-47c3-8640-031411ac3acc',
|
||||
'7881ddc2-c254-4f42-8d8a-3ba546a725b2',
|
||||
'f52cb36f-36d2-4b7c-860a-8e8b2b8b1b2d',
|
||||
'618f9080-765e-44e4-8688-551e57335834',
|
||||
'a92a4561-55e7-4cae-b0ad-cfd88c3b8549',
|
||||
'5d7b9373-8fbf-427c-988b-ab70216eb1a3',
|
||||
'f2b2eb42-98fc-4d0c-b76c-82453e7a7ad4',
|
||||
'ae9ee599-0361-4a6c-9e28-33769683b91d',
|
||||
'eaeb7546-83f4-4364-8775-c5f8c925d152',
|
||||
'60546de5-bce0-4f1f-9572-3d5a24488126',
|
||||
'496b2a9b-8082-4a31-829b-9ddaea1b8d72',
|
||||
'e86f7fd3-5e55-476e-9d54-88999db045f1',
|
||||
'b4df19ab-cee5-400f-a9e1-3d9a1ca60ab4',
|
||||
'286c5332-3abe-49b4-a94a-b3f74c99a1aa',
|
||||
'81115d6d-643c-466a-b602-6b6a9e2af463',
|
||||
'b9c0d5cd-7b23-4a0f-910f-2d74cdccc46b',
|
||||
'088c5dc0-5d4c-4a90-840a-f1109013625d',
|
||||
'46cf7b21-b0f2-483a-a816-d88699f15724',
|
||||
'ac7c54c5-4f41-4878-957f-8f5680302ee5',
|
||||
'de61c088-b9e3-4975-a3bd-61401d0f34ea',
|
||||
'c898f4c8-3611-447f-a59d-c6dc57b20c6f',
|
||||
'054f8331-8e90-402f-b321-cd9817c9b872',
|
||||
'd1f97e08-e66d-4738-a549-7e5ce5684b89',
|
||||
'c43a794a-26c4-4de9-96bd-6570ae8901f2',
|
||||
'8d979e7a-5bb8-4daa-92c0-530c575592e8',
|
||||
'5ec098a9-b638-4f91-a69c-4c877801df45',
|
||||
'a4bdd1cf-9b8c-4914-a728-57a1f5245b2a',
|
||||
'dfd687ff-6bdf-4ae2-a364-8f1a8abd29d4',
|
||||
'b6324133-b493-45f4-8598-c8c70b0df90e',
|
||||
'057b64e9-3457-48d7-8368-d58760b6fc92',
|
||||
'1351c083-0b5a-4fe6-87d3-801239ac42a6',
|
||||
'c0292658-18b4-4273-aae3-5af6b523fc65',
|
||||
'3616f400-4431-423d-b905-1a70904be63d',
|
||||
'ae735815-4a74-4af4-bc82-045f43f3d1ca',
|
||||
'1fd9e4bb-f592-4e5d-829e-2910222ec8c9',
|
||||
'30f4e69c-40d3-4402-8075-c85a3a801a6a',
|
||||
'9f3ddbf3-168a-483a-bd9d-1ffade99e816',
|
||||
'c777722e-5e72-41bb-a7a5-bbbdfe67e630',
|
||||
'72a7b8c8-c342-4dd2-b413-1a09f24e70a8',
|
||||
'd09c92df-e933-4016-af2f-89a99ce314ac',
|
||||
'22789e02-6e3e-490b-9c41-5e8a9d161ebc',
|
||||
'8374dcad-f51d-4c3c-b6ec-04b32644379b',
|
||||
'a34c9403-ee6f-4251-a8d3-838df56c33c5',
|
||||
'1b5165df-40c0-4832-8f9e-b5bc2df40c37',
|
||||
'2594664b-0eb9-43a1-859f-2726f763b76d',
|
||||
'86b94bd5-920e-468b-81c8-90bf502b39bb',
|
||||
'b394e352-e825-4dd1-b8e4-f03db6f5178d',
|
||||
'7d7b18f0-279f-4fc6-8fdc-3636d1bb76c8',
|
||||
'7fe9cc76-513b-4272-b54c-bfd91710b92a',
|
||||
'0b3cd1d8-994b-4e17-9a0d-2d01462b7bac',
|
||||
'131123b5-6290-45cb-b0dc-f96d82031f2c',
|
||||
'20c61fcd-17a4-409e-b53c-d19053b7657c',
|
||||
'fe57563b-2817-45a0-a5a6-d6d852824341',
|
||||
'724cce37-0290-4bb4-a385-e97af88ff308',
|
||||
'9ed98b9a-4d51-49d2-bdd9-ff983a664bd8',
|
||||
'321ad5af-fa69-46ca-a1e6-38c43df6c4d1',
|
||||
'a7eced90-a8ce-4891-bb4d-6931d2e63c42',
|
||||
'002f4512-6ab4-4a67-afde-120263f719bf',
|
||||
'3d888a45-c790-443a-b299-79bdbf180ea9',
|
||||
'166028e4-4cfd-4749-a898-c452cb4e5e3c',
|
||||
'596dc54c-34cd-4474-85ca-50c7b2bb4dec',
|
||||
'837b2e19-2258-47b6-9dd5-44f1729b916b',
|
||||
'5f5407de-f1bf-4fcc-a8c4-cd48920c5aef',
|
||||
'b6f634ea-ffcd-4de1-9669-0031dc689d61',
|
||||
'4d7494dd-90b6-45e7-8412-2dd554e20ce7',
|
||||
'aabf6703-5cb1-4f6c-bda2-bbf9f2137628',
|
||||
'7d6664fc-cb45-49be-95c9-4642d9fd8e1b',
|
||||
'3b47c3fb-a0f4-4dbc-8f99-19ed905cadf3',
|
||||
'2d31a2db-7791-4270-94c6-1653a3775c1a',
|
||||
'90160273-9bef-442b-aa36-393bdb3fcf38',
|
||||
'4d02d9bc-d81b-41da-b1e0-2d1ffde96103',
|
||||
'f8be054e-651d-4542-a3e4-681a4a2ec9d0',
|
||||
'966e9995-938a-4a5e-813c-de3691dddb3a',
|
||||
];
|
||||
|
||||
export function v4Mock() {
|
||||
const uuid = v4UUIDs[v4Counter++];
|
||||
if (!uuid) {
|
||||
throw new Error('Not enough mocked v4 UUIDs to go around');
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
30
packages/insomnia-data/common-src/constants.ts
Normal file
30
packages/insomnia-data/common-src/constants.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export const CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded';
|
||||
export const CONTENT_TYPE_GRAPHQL = 'application/graphql';
|
||||
export const METHOD_GET = 'GET';
|
||||
export const CONTENT_TYPE_JSON = 'application/json';
|
||||
|
||||
export function getContentTypeFromHeaders(headers: any[], defaultValue: string | null = null) {
|
||||
if (!Array.isArray(headers)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const header = headers.find(({ name }) => name.toLowerCase() === 'content-type');
|
||||
return header ? header.value : defaultValue;
|
||||
}
|
||||
|
||||
// Vite is filtering out process.env variables that are not prefixed with VITE_.
|
||||
const ENV = 'env';
|
||||
|
||||
const env = process[ENV];
|
||||
|
||||
export const getMockServiceURL = () => env.INSOMNIA_MOCK_API_URL || 'https://mock.insomnia.run';
|
||||
|
||||
export type OAuth1SignatureMethod = 'HMAC-SHA1' | 'RSA-SHA1' | 'HMAC-SHA256' | 'PLAINTEXT';
|
||||
export const SIGNATURE_METHOD_HMAC_SHA1: OAuth1SignatureMethod = 'HMAC-SHA1';
|
||||
export const SIGNATURE_METHOD_HMAC_SHA256: OAuth1SignatureMethod = 'HMAC-SHA256';
|
||||
export const SIGNATURE_METHOD_RSA_SHA1: OAuth1SignatureMethod = 'RSA-SHA1';
|
||||
export const SIGNATURE_METHOD_PLAINTEXT: OAuth1SignatureMethod = 'PLAINTEXT';
|
||||
|
||||
export const getAppDefaultTheme = () => 'default';
|
||||
export const getAppDefaultLightTheme = () => 'studio-light';
|
||||
export const getAppDefaultDarkTheme = () => 'default';
|
||||
@@ -3,7 +3,7 @@ export * from './invariant';
|
||||
export * from './ndjson';
|
||||
export * from './type';
|
||||
export * from './misc';
|
||||
export * from './request';
|
||||
export * from './constants';
|
||||
export * from './preview-mode';
|
||||
export * from './platform';
|
||||
export * from './strings';
|
||||
@@ -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'
|
||||
8
packages/insomnia-data/common-src/tsconfig.json
Normal file
8
packages/insomnia-data/common-src/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2023", "WebWorker"],
|
||||
"types": []
|
||||
},
|
||||
"include": ["./**/*.ts"]
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import os from 'node:os';
|
||||
import fsPath from 'node:path';
|
||||
|
||||
import NeDB from '@seald-io/nedb';
|
||||
|
||||
import {
|
||||
type AllTypes,
|
||||
type ApiSpec,
|
||||
@@ -25,8 +24,8 @@ import {
|
||||
type Query,
|
||||
type Workspace,
|
||||
type WorkspaceMeta,
|
||||
} from '~/insomnia-data';
|
||||
import { generateId } from '~/insomnia-data/common';
|
||||
} from 'insomnia-data';
|
||||
import { generateId } from 'insomnia-data/common';
|
||||
|
||||
import { initModel } from '../utils';
|
||||
import { repairDatabase } from './repair-database';
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { BaseModel, ChangeBufferEvent, CookieJar, Environment, Request, Workspace } from 'insomnia-data';
|
||||
import { database as db, models, services } from 'insomnia-data';
|
||||
import { afterEach, assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { ChangeBufferEvent } from '../..';
|
||||
import { type BaseModel, models, services } from '../..';
|
||||
import { database as db } from '../..';
|
||||
import * as workspaceMigration from '../utils/migrate/workspace';
|
||||
import { repairDatabase } from './repair-database';
|
||||
|
||||
describe('init()', () => {
|
||||
@@ -26,14 +26,12 @@ describe('onChange()', () => {
|
||||
type: models.request.type,
|
||||
parentId: 'nothing',
|
||||
name: 'foo',
|
||||
};
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[] = [];
|
||||
} as const;
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[][] = [];
|
||||
|
||||
const callback = change => {
|
||||
db.onChange(change => {
|
||||
changesSeen.push(change);
|
||||
};
|
||||
|
||||
db.onChange(callback);
|
||||
});
|
||||
const newDoc = await services.request.create(doc);
|
||||
const updatedDoc = await services.request.update(newDoc, {
|
||||
name: 'bar',
|
||||
@@ -48,14 +46,12 @@ describe('bufferChanges()', () => {
|
||||
type: models.request.type,
|
||||
parentId: 'n/a',
|
||||
name: 'foo',
|
||||
};
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[] = [];
|
||||
} as const;
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[][] = [];
|
||||
|
||||
const callback = change => {
|
||||
db.onChange(change => {
|
||||
changesSeen.push(change);
|
||||
};
|
||||
|
||||
db.onChange(callback);
|
||||
});
|
||||
await db.bufferChanges();
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
@@ -85,14 +81,12 @@ describe('bufferChanges()', () => {
|
||||
type: models.request.type,
|
||||
parentId: 'n/a',
|
||||
name: 'foo',
|
||||
};
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[] = [];
|
||||
} as const;
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[][] = [];
|
||||
|
||||
const callback = change => {
|
||||
db.onChange(change => {
|
||||
changesSeen.push(change);
|
||||
};
|
||||
|
||||
db.onChange(callback);
|
||||
});
|
||||
await db.bufferChanges();
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
@@ -112,14 +106,12 @@ describe('bufferChanges()', () => {
|
||||
type: models.request.type,
|
||||
parentId: 'n/a',
|
||||
name: 'foo',
|
||||
};
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[] = [];
|
||||
} as const;
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[][] = [];
|
||||
|
||||
const callback = change => {
|
||||
db.onChange(change => {
|
||||
changesSeen.push(change);
|
||||
};
|
||||
|
||||
db.onChange(callback);
|
||||
});
|
||||
await db.bufferChanges(500);
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
@@ -140,14 +132,12 @@ describe('bufferChangesIndefinitely()', () => {
|
||||
type: models.request.type,
|
||||
parentId: 'n/a',
|
||||
name: 'foo',
|
||||
};
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[] = [];
|
||||
} as const;
|
||||
const changesSeen: ChangeBufferEvent<BaseModel>[][] = [];
|
||||
|
||||
const callback = change => {
|
||||
db.onChange(change => {
|
||||
changesSeen.push(change);
|
||||
};
|
||||
|
||||
db.onChange(callback);
|
||||
});
|
||||
await db.bufferChangesIndefinitely();
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
@@ -261,10 +251,10 @@ describe('_repairDatabase()', async () => {
|
||||
});
|
||||
// Make sure we have 6 environments and one workspace
|
||||
expect((await db.getWithDescendants(workspace)).length).toBe(7);
|
||||
const descendants = (await db.getWithDescendants(workspace)).map(d => ({
|
||||
const descendants = ((await db.getWithDescendants(workspace)) as (Workspace | Environment)[]).map(d => ({
|
||||
_id: d._id,
|
||||
parentId: d.parentId,
|
||||
data: d.data || null,
|
||||
data: 'data' in d ? d.data || null : null,
|
||||
}));
|
||||
expect(descendants).toEqual([
|
||||
{
|
||||
@@ -322,10 +312,10 @@ describe('_repairDatabase()', async () => {
|
||||
await repairDatabase();
|
||||
|
||||
// Make sure things get adjusted
|
||||
const descendants2 = (await db.getWithDescendants(workspace)).map(d => ({
|
||||
const descendants2 = ((await db.getWithDescendants(workspace)) as (Workspace | Environment)[]).map(d => ({
|
||||
_id: d._id,
|
||||
parentId: d.parentId,
|
||||
data: d.data || null,
|
||||
data: 'data' in d ? d.data || null : null,
|
||||
}));
|
||||
expect(descendants2).toEqual([
|
||||
{
|
||||
@@ -423,9 +413,9 @@ describe('_repairDatabase()', async () => {
|
||||
});
|
||||
// Make sure we have 2 cookie jars and one workspace
|
||||
expect((await db.getWithDescendants(workspace)).length).toBe(3);
|
||||
const descendants = (await db.getWithDescendants(workspace)).map(d => ({
|
||||
const descendants = ((await db.getWithDescendants(workspace)) as (Workspace | CookieJar)[]).map(d => ({
|
||||
_id: d._id,
|
||||
cookies: d.cookies || null,
|
||||
cookies: 'cookies' in d ? d.cookies || null : null,
|
||||
parentId: d.parentId,
|
||||
}));
|
||||
expect(descendants).toEqual([
|
||||
@@ -470,9 +460,9 @@ describe('_repairDatabase()', async () => {
|
||||
// Run the fix algorithm
|
||||
await repairDatabase();
|
||||
// Make sure things get adjusted
|
||||
const descendants2 = (await db.getWithDescendants(workspace)).map(d => ({
|
||||
const descendants2 = ((await db.getWithDescendants(workspace)) as (Workspace | CookieJar)[]).map(d => ({
|
||||
_id: d._id,
|
||||
cookies: d.cookies || null,
|
||||
cookies: 'cookies' in d ? d.cookies || null : null,
|
||||
parentId: d.parentId,
|
||||
}));
|
||||
expect(descendants2).toEqual([
|
||||
@@ -598,14 +588,13 @@ describe('duplicate()', () => {
|
||||
});
|
||||
expect(duplicated._id).not.toEqual(workspace._id);
|
||||
expect(duplicated._id).toMatch(/^wrk_[a-z0-9]{32}$/);
|
||||
delete workspace._id;
|
||||
delete duplicated._id;
|
||||
expect(duplicated).toEqual({
|
||||
...workspace,
|
||||
description: newDescription,
|
||||
modified: date,
|
||||
created: date,
|
||||
type: models.workspace.type,
|
||||
_id: expect.any(String),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -613,7 +602,7 @@ describe('duplicate()', () => {
|
||||
const workspace = await services.workspace.create({
|
||||
name: 'Test Workspace',
|
||||
});
|
||||
const spy = vi.spyOn(models.workspace, 'migrate');
|
||||
const spy = vi.spyOn(workspaceMigration, 'migrate');
|
||||
await db.duplicate(workspace);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -651,7 +640,7 @@ describe('duplicate()', () => {
|
||||
expect(dupReq2!.url).toContain("{% response 'body',");
|
||||
|
||||
// Original should be unchanged
|
||||
const originalReq2 = await db.findOne(models.request.type, { _id: req2._id });
|
||||
const originalReq2 = await db.findOne<Request>(models.request.type, { _id: req2._id });
|
||||
expect(originalReq2!.url).toContain(req1._id);
|
||||
});
|
||||
});
|
||||
@@ -660,7 +649,7 @@ describe('docCreate()', () => {
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
it('should call migrate when creating', async () => {
|
||||
const spy = vi.spyOn(models.workspace, 'migrate');
|
||||
const spy = vi.spyOn(workspaceMigration, 'migrate');
|
||||
await db.docCreate(models.workspace.type, {
|
||||
name: 'Test Workspace',
|
||||
});
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
models,
|
||||
services,
|
||||
type Workspace,
|
||||
} from '~/insomnia-data';
|
||||
} from 'insomnia-data';
|
||||
|
||||
/**
|
||||
* Run various database repair scripts
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type ApiSpec, database as db, models } from '~/insomnia-data';
|
||||
import { type ApiSpec, database as db, models } from 'insomnia-data';
|
||||
|
||||
const { type } = models.apiSpec;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CaCertificate } from '~/insomnia-data';
|
||||
import type { CaCertificate } from 'insomnia-data';
|
||||
|
||||
import { database as db } from '../../src/database';
|
||||
import { models } from '../../src/models';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type ClientCertificate, database as db, models } from '~/insomnia-data';
|
||||
import { type ClientCertificate, database as db, models } from 'insomnia-data';
|
||||
|
||||
const { type } = models.clientCertificate;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type CloudProviderCredential, type CloudProviderName, database as db, models } from '~/insomnia-data';
|
||||
import { type CloudProviderCredential, type CloudProviderName, database as db, models } from 'insomnia-data';
|
||||
|
||||
const { type } = models.cloudCredential;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
import { type BaseModel, type CookieJar, database as db, models } from '~/insomnia-data';
|
||||
import { type BaseModel, type CookieJar, database as db, models } from 'insomnia-data';
|
||||
|
||||
const { type, prefix } = models.cookieJar;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'node:crypto';
|
||||
|
||||
import { database as db, type Environment, models, type Project, type Workspace } from '~/insomnia-data';
|
||||
import { database as db, type Environment, models, type Project, type Workspace } from 'insomnia-data';
|
||||
|
||||
const { project, workspace } = models;
|
||||
const { type, prefix, EnvironmentType, vaultEnvironmentPath, EnvironmentKvPairDataType } = models.environment;
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
type GitCredentials,
|
||||
type GitCredentialsV2,
|
||||
models,
|
||||
} from '~/insomnia-data';
|
||||
} from 'insomnia-data';
|
||||
|
||||
const { type } = models.gitCredentials;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, type GitRepository, models } from '~/insomnia-data';
|
||||
import { database as db, type GitRepository, models } from 'insomnia-data';
|
||||
|
||||
const type = models.gitRepository.type;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, type GrpcRequestMeta, models } from '~/insomnia-data';
|
||||
import { database as db, type GrpcRequestMeta, models } from 'insomnia-data';
|
||||
|
||||
const { isGrpcRequestId } = models.grpcRequest;
|
||||
const { type } = models.grpcRequestMeta;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, type GrpcRequest, models } from '~/insomnia-data';
|
||||
import { database as db, type GrpcRequest, models } from 'insomnia-data';
|
||||
|
||||
const { type, name } = models.grpcRequest;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { type AllTypes, models } from 'insomnia-data';
|
||||
import { generateId } from 'insomnia-data/common';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { models } from '~/insomnia-data';
|
||||
import { generateId } from '~/insomnia-data/common';
|
||||
|
||||
const allTypes = models.types();
|
||||
const allPrefixes = models.all().map(model => model.prefix);
|
||||
|
||||
describe('isGrpcRequest', () => {
|
||||
const supported = [models.grpcRequest.type];
|
||||
const supported: AllTypes[] = [models.grpcRequest.type];
|
||||
const unsupported = allTypes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
@@ -28,7 +27,7 @@ describe('isGrpcRequest', () => {
|
||||
});
|
||||
|
||||
describe('isGrpcRequestId', () => {
|
||||
const supported = [models.grpcRequest.prefix];
|
||||
const supported: (typeof allPrefixes)[number][] = [models.grpcRequest.prefix];
|
||||
const unsupported = allPrefixes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true if id is prefixed by "%s_"', prefix => {
|
||||
@@ -41,7 +40,7 @@ describe('isGrpcRequestId', () => {
|
||||
});
|
||||
|
||||
describe('isRequest', () => {
|
||||
const supported = [models.request.type];
|
||||
const supported: AllTypes[] = [models.request.type];
|
||||
const unsupported = allTypes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
@@ -62,7 +61,7 @@ describe('isRequest', () => {
|
||||
});
|
||||
|
||||
describe('isRequestGroup', () => {
|
||||
const supported = [models.requestGroup.type];
|
||||
const supported: AllTypes[] = [models.requestGroup.type];
|
||||
const unsupported = allTypes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
@@ -83,7 +82,7 @@ describe('isRequestGroup', () => {
|
||||
});
|
||||
|
||||
describe('isProtoFile', () => {
|
||||
const supported = [models.protoFile.type];
|
||||
const supported: AllTypes[] = [models.protoFile.type];
|
||||
const unsupported = allTypes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
@@ -104,7 +103,7 @@ describe('isProtoFile', () => {
|
||||
});
|
||||
|
||||
describe('isProtoDirectory', () => {
|
||||
const supported = [models.protoDirectory.type];
|
||||
const supported: AllTypes[] = [models.protoDirectory.type];
|
||||
const unsupported = allTypes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
@@ -125,7 +124,7 @@ describe('isProtoDirectory', () => {
|
||||
});
|
||||
|
||||
describe('isWorkspace', () => {
|
||||
const supported = [models.workspace.type];
|
||||
const supported: AllTypes[] = [models.workspace.type];
|
||||
const unsupported = allTypes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
@@ -1,7 +1,6 @@
|
||||
import { models, services } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { models, services } from '~/insomnia-data';
|
||||
|
||||
import { queryAllWorkspaceUrls } from '../query-all-workspace-urls';
|
||||
|
||||
describe('queryAllWorkspaceUrls', () => {
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { GrpcRequest, models, Request } from '~/insomnia-data';
|
||||
import { database as db, services } from '~/insomnia-data';
|
||||
import { invariant } from '~/insomnia-data/common';
|
||||
import type { GrpcRequest, models, Request } from 'insomnia-data';
|
||||
import { database as db, services } from 'insomnia-data';
|
||||
import { invariant } from 'insomnia-data/common';
|
||||
|
||||
export const queryAllWorkspaceUrls = async (
|
||||
workspaceId: string,
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
type Request,
|
||||
type SocketIORequest,
|
||||
type WebSocketRequest,
|
||||
} from '~/insomnia-data';
|
||||
} from 'insomnia-data';
|
||||
|
||||
import * as grpcRequestServices from '../grpc-request';
|
||||
import * as mcpRequestServices from '../mcp-request';
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
services,
|
||||
type SocketIOResponse,
|
||||
type WebSocketResponse,
|
||||
} from '~/insomnia-data';
|
||||
import { deserializeNDJSON } from '~/insomnia-data/common';
|
||||
} from 'insomnia-data';
|
||||
import { deserializeNDJSON } from 'insomnia-data/common';
|
||||
|
||||
const { type: responseType, isResponse } = models.response;
|
||||
const { isSocketIORequestId } = models.socketIORequest;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invariant } from '~/insomnia-data/common';
|
||||
import { invariant } from 'insomnia-data/common';
|
||||
|
||||
import { database as db } from '../../src/database';
|
||||
import { models } from '../../src/models';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, type McpResponse, models } from '~/insomnia-data';
|
||||
import { database as db, type McpResponse, models } from 'insomnia-data';
|
||||
|
||||
import * as mcpRequestService from './mcp-request';
|
||||
import * as requestVersionService from './request-version';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, type MockRoute, models } from '~/insomnia-data';
|
||||
import { database as db, type MockRoute, models } from 'insomnia-data';
|
||||
|
||||
const { type } = models.mockRoute;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, type MockServer, models } from '~/insomnia-data';
|
||||
import { database as db, type MockServer, models } from 'insomnia-data';
|
||||
|
||||
import * as workspaceServices from './workspace';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type OAuth2Token } from '~/insomnia-data';
|
||||
import { database as db, models, type OAuth2Token } from 'insomnia-data';
|
||||
|
||||
const type = models.oAuth2Token.type;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type PluginData } from '~/insomnia-data';
|
||||
import { database as db, models, type PluginData } from 'insomnia-data';
|
||||
|
||||
const { type } = models.pluginData;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type Project } from '~/insomnia-data';
|
||||
import { database as db, models, type Project } from 'insomnia-data';
|
||||
|
||||
const { type } = models.project;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type ProtoDirectory } from '~/insomnia-data';
|
||||
import { database as db, models, type ProtoDirectory } from 'insomnia-data';
|
||||
|
||||
const { type } = models.protoDirectory;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type ProtoFile } from '~/insomnia-data';
|
||||
import { database as db, models, type ProtoFile } from 'insomnia-data';
|
||||
|
||||
const { type } = models.protoFile;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type RequestGroupMeta } from '~/insomnia-data';
|
||||
import { database as db, models, type RequestGroupMeta } from 'insomnia-data';
|
||||
|
||||
const { type } = models.requestGroupMeta;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type RequestGroup } from '~/insomnia-data';
|
||||
import { database as db, models, type RequestGroup } from 'insomnia-data';
|
||||
|
||||
const { type } = models.requestGroup;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type RequestMeta } from '~/insomnia-data';
|
||||
import { database as db, models, type RequestMeta } from 'insomnia-data';
|
||||
|
||||
const { type } = models.requestMeta;
|
||||
|
||||
@@ -2,7 +2,6 @@ import { promisify } from 'node:util';
|
||||
import zlib from 'node:zlib';
|
||||
|
||||
import deepEqual from 'deep-equal';
|
||||
|
||||
import {
|
||||
database as db,
|
||||
type GrpcRequest,
|
||||
@@ -12,7 +11,7 @@ import {
|
||||
type RequestVersion,
|
||||
type SocketIORequest,
|
||||
type WebSocketRequest,
|
||||
} from '~/insomnia-data';
|
||||
} from 'insomnia-data';
|
||||
|
||||
import * as requestHelpers from './helpers/request-operations';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type Request } from '~/insomnia-data';
|
||||
import { database as db, models, type Request } from 'insomnia-data';
|
||||
|
||||
const { type, name } = models.request;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type Response, services } from '~/insomnia-data';
|
||||
import { database as db, models, type Response, services } from 'insomnia-data';
|
||||
|
||||
import * as requestVersionOperations from './request-version';
|
||||
import * as settingsOperations from './settings';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type RunnerTestResult } from '~/insomnia-data';
|
||||
import { database as db, models, type RunnerTestResult } from 'insomnia-data';
|
||||
|
||||
const { type } = models.runnerTestResult;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type Settings } from '~/insomnia-data';
|
||||
import { database as db, models, type Settings } from 'insomnia-data';
|
||||
|
||||
const { type } = models.settings;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database, models, type SocketIOPayload } from '~/insomnia-data';
|
||||
import { database, models, type SocketIOPayload } from 'insomnia-data';
|
||||
|
||||
const { type, name } = models.socketIOPayload;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database, models, type SocketIORequest } from '~/insomnia-data';
|
||||
import { database, models, type SocketIORequest } from 'insomnia-data';
|
||||
|
||||
const { type, name } = models.socketIORequest;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type SocketIOResponse } from '~/insomnia-data';
|
||||
import { database as db, models, type SocketIOResponse } from 'insomnia-data';
|
||||
|
||||
import * as requestServices from './request';
|
||||
import * as requestVersionServices from './request-version';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type Project, type RequestGroup, type Stats, type Workspace } from '~/insomnia-data';
|
||||
import { database as db, models, type Project, type RequestGroup, type Stats, type Workspace } from 'insomnia-data';
|
||||
|
||||
const { type } = models.stats;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type UnitTestResult } from '~/insomnia-data';
|
||||
import { database as db, models, type UnitTestResult } from 'insomnia-data';
|
||||
|
||||
const { type } = models.unitTestResult;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type UnitTestSuite } from '~/insomnia-data';
|
||||
import { database as db, models, type UnitTestSuite } from 'insomnia-data';
|
||||
|
||||
const { type } = models.unitTestSuite;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type UnitTest } from '~/insomnia-data';
|
||||
import { database as db, models, type UnitTest } from 'insomnia-data';
|
||||
|
||||
const { type } = models.unitTest;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type UserSession } from '~/insomnia-data';
|
||||
import { database as db, models, type UserSession } from 'insomnia-data';
|
||||
|
||||
const { type } = models.userSession;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database, models, type WebSocketPayload } from '~/insomnia-data';
|
||||
import { database, models, type WebSocketPayload } from 'insomnia-data';
|
||||
|
||||
const { type, name } = models.webSocketPayload;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database, models, type WebSocketRequest } from '~/insomnia-data';
|
||||
import { database, models, type WebSocketRequest } from 'insomnia-data';
|
||||
|
||||
const { type, name } = models.webSocketRequest;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type WebSocketResponse } from '~/insomnia-data';
|
||||
import { database as db, models, type WebSocketResponse } from 'insomnia-data';
|
||||
|
||||
import * as requestServices from './request';
|
||||
import * as requestVersionServices from './request-version';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type WorkspaceMeta } from '~/insomnia-data';
|
||||
import { database as db, models, type WorkspaceMeta } from 'insomnia-data';
|
||||
|
||||
const { type } = models.workspaceMeta;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { database as db, models, type Workspace } from '~/insomnia-data';
|
||||
import { database as db, models, type Workspace } from 'insomnia-data';
|
||||
|
||||
const { isProjectId } = models.project;
|
||||
const { type } = models.workspace;
|
||||
8
packages/insomnia-data/node-src/tsconfig.json
Normal file
8
packages/insomnia-data/node-src/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2023", "WebWorker"],
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["./**/*.ts"]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AllTypes, BaseModel } from '~/insomnia-data';
|
||||
import { models } from '~/insomnia-data';
|
||||
import { generateId, typedKeys } from '~/insomnia-data/common';
|
||||
import type { AllTypes, BaseModel } from 'insomnia-data';
|
||||
import { models } from 'insomnia-data';
|
||||
import { generateId, typedKeys } from 'insomnia-data/common';
|
||||
|
||||
import { migrate as migrateRequest } from './migrate/request';
|
||||
import { migrate as migrateResponse } from './migrate/response';
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Request } from '~/insomnia-data';
|
||||
import type { Request } from 'insomnia-data';
|
||||
import {
|
||||
CONTENT_TYPE_FORM_URLENCODED,
|
||||
deconstructQueryStringToParams,
|
||||
getContentTypeFromHeaders,
|
||||
} from '~/insomnia-data/common';
|
||||
} from 'insomnia-data/common';
|
||||
|
||||
export function migrate(doc: Request): Request {
|
||||
try {
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Response } from '~/insomnia-data';
|
||||
import type { Response } from 'insomnia-data';
|
||||
|
||||
export function migrate(doc: Response) {
|
||||
try {
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Settings } from '~/insomnia-data';
|
||||
import type { Settings } from 'insomnia-data';
|
||||
|
||||
import * as hotkeys from '../../../common-src/hotkeys';
|
||||
import type { KeyboardShortcut } from '../../../common-src/settings';
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { Workspace } from 'insomnia-data';
|
||||
import { models } from 'insomnia-data';
|
||||
import type { Merge } from 'type-fest';
|
||||
|
||||
import type { Workspace } from '~/insomnia-data';
|
||||
import { models } from '~/insomnia-data';
|
||||
|
||||
import * as clientCertificateService from '../../services/client-certificate';
|
||||
|
||||
const { WorkspaceScopeKeys } = models.workspace;
|
||||
37
packages/insomnia-data/package.json
Normal file
37
packages/insomnia-data/package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "insomnia-data",
|
||||
"license": "Apache-2.0",
|
||||
"version": "12.4.0",
|
||||
"author": "Kong <office@konghq.com>",
|
||||
"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",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
12
packages/insomnia-data/setup-vitest.ts
Normal file
12
packages/insomnia-data/setup-vitest.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { initDatabase, initServices } from 'insomnia-data';
|
||||
import { createNedbDatabase, servicesNodeImpl } from 'insomnia-data/node';
|
||||
import { vi } from 'vitest';
|
||||
|
||||
import { v4Mock } from './__mocks__/uuid';
|
||||
|
||||
await initDatabase(createNedbDatabase(), { inMemoryOnly: true }, true);
|
||||
await initServices(servicesNodeImpl);
|
||||
|
||||
vi.mock('uuid', () => ({
|
||||
v4: () => v4Mock(),
|
||||
}));
|
||||
@@ -1,7 +1,6 @@
|
||||
import { type BaseGitCredentialsV2, models, services } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { type BaseGitCredentialsV2, models, services } from '..';
|
||||
|
||||
const { init, isGitCredentialsV2, supportsRenewal } = models.gitCredentials;
|
||||
|
||||
describe('init()', () => {
|
||||
@@ -1,7 +1,6 @@
|
||||
import { models, services } from 'insomnia-data';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { models, services } from '..';
|
||||
|
||||
describe('init()', () => {
|
||||
it('contains all required fields', async () => {
|
||||
expect(models.grpcRequestMeta.init()).toEqual({
|
||||
@@ -1,7 +1,6 @@
|
||||
import { models, services } from 'insomnia-data';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { models, services } from '..';
|
||||
|
||||
describe('init()', () => {
|
||||
it('contains all required fields', async () => {
|
||||
Date.now = vi.fn().mockReturnValue(1_478_795_580_200);
|
||||
@@ -1,7 +1,6 @@
|
||||
import { models } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { models } from '..';
|
||||
|
||||
const { getModel, mustGetModel } = models;
|
||||
|
||||
describe('index', () => {
|
||||
24
packages/insomnia-data/src/__tests__/project.test.ts
Normal file
24
packages/insomnia-data/src/__tests__/project.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { models, services } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const defaultOrgProject = await services.project.create({
|
||||
name: 'a',
|
||||
remoteId: 'proj_team_123456789345678987654',
|
||||
_id: 'not important',
|
||||
});
|
||||
|
||||
const remoteA = await services.project.create({ name: 'a', remoteId: 'notNull', _id: 'remoteA' });
|
||||
const remoteB = await services.project.create({ name: 'b', remoteId: 'notNull', _id: 'remoteB' });
|
||||
const remote0 = await services.project.create({ name: '0', remoteId: 'notNull', _id: 'remote0' });
|
||||
|
||||
const { sortProjects } = models.project;
|
||||
|
||||
describe('sortProjects', () => {
|
||||
it('sorts projects by default > local > remote > name', () => {
|
||||
const unSortedProjects = [remoteA, defaultOrgProject, remoteB, remote0];
|
||||
const result = sortProjects(unSortedProjects);
|
||||
|
||||
const sortedProjects = [defaultOrgProject, remote0, remoteA, remoteB];
|
||||
expect(result).toEqual(sortedProjects);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,6 @@
|
||||
import { models, services } from 'insomnia-data';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { models, services } from '..';
|
||||
|
||||
describe('init()', () => {
|
||||
it('contains all required fields', async () => {
|
||||
expect(models.protoFile.init()).toEqual({
|
||||
@@ -1,7 +1,6 @@
|
||||
import { services } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { services } from '..';
|
||||
|
||||
describe('create()', () => {
|
||||
it('fails when missing parentId', async () => {
|
||||
expect(() =>
|
||||
@@ -5,10 +5,10 @@
|
||||
* we added comments to in request.ts, ensuring they work correctly.
|
||||
*/
|
||||
|
||||
import { services } from 'insomnia-data';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { services } from '..';
|
||||
import type {
|
||||
AuthTypeAPIKey,
|
||||
AuthTypeAsap,
|
||||
@@ -25,7 +25,7 @@ import type {
|
||||
RequestBody,
|
||||
RequestHeader,
|
||||
RequestParameter,
|
||||
} from '../src/models/request';
|
||||
} from '../models/request';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('Request Model - Comprehensive Tests', () => {
|
||||
@@ -3,16 +3,15 @@ import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import zlib from 'node:zlib';
|
||||
|
||||
import { services } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { models, services } from '..';
|
||||
import { initModel } from '../node-src/utils';
|
||||
|
||||
describe('migrate()', () => {
|
||||
it('does it', async () => {
|
||||
const bodyPath = path.join(tmpdir(), 'foo.zip');
|
||||
fs.writeFileSync(bodyPath, zlib.gzipSync('Hello World!'));
|
||||
const response = await initModel(models.response.type, {
|
||||
const response = await services.response.create({
|
||||
parentId: 'pid',
|
||||
bodyPath,
|
||||
});
|
||||
const body = (await services.helpers.getResponseBodyBuffer(response)).toString();
|
||||
@@ -23,7 +22,8 @@ describe('migrate()', () => {
|
||||
it('migrates leaves bodyCompression for null', async () => {
|
||||
expect(
|
||||
(
|
||||
await initModel(models.response.type, {
|
||||
await services.response.create({
|
||||
parentId: 'pid',
|
||||
bodyPath: '/foo/bar',
|
||||
bodyCompression: null,
|
||||
})
|
||||
@@ -34,7 +34,8 @@ describe('migrate()', () => {
|
||||
it('migrates sets bodyCompression to zip if does not have one yet', async () => {
|
||||
expect(
|
||||
(
|
||||
await initModel(models.response.type, {
|
||||
await services.response.create({
|
||||
parentId: 'pid',
|
||||
bodyPath: '/foo/bar',
|
||||
})
|
||||
).bodyCompression,
|
||||
@@ -44,7 +45,8 @@ describe('migrate()', () => {
|
||||
it('migrates leaves bodyCompression if string', async () => {
|
||||
expect(
|
||||
(
|
||||
await initModel(models.response.type, {
|
||||
await services.response.create({
|
||||
parentId: 'pid',
|
||||
bodyPath: '/foo/bar',
|
||||
bodyCompression: 'zip',
|
||||
})
|
||||
@@ -1,7 +1,8 @@
|
||||
import { models, services } from 'insomnia-data';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { models, services } from '..';
|
||||
import { migrate } from '../node-src/utils/migrate/workspace';
|
||||
import { migrate } from '../../node-src/utils/migrate/workspace';
|
||||
|
||||
const { WorkspaceScopeKeys } = models.workspace;
|
||||
describe('migrate()', () => {
|
||||
it('migrates client certificates properly', async () => {
|
||||
@@ -21,14 +22,6 @@ describe('migrate()', () => {
|
||||
const migratedWorkspace = await migrate(workspace);
|
||||
const certs = await services.clientCertificate.findByParentId(workspace._id);
|
||||
|
||||
// Delete modified and created so we can assert them
|
||||
for (const cert of certs) {
|
||||
expect(typeof cert.modified).toBe('number');
|
||||
expect(typeof cert.created).toBe('number');
|
||||
delete cert.modified;
|
||||
delete cert.created;
|
||||
}
|
||||
|
||||
expect(certs.length).toBe(2);
|
||||
expect(certs.sort((c1, c2) => (c1._id > c2._id ? -1 : 1))).toEqual([
|
||||
{
|
||||
@@ -42,6 +35,8 @@ describe('migrate()', () => {
|
||||
passphrase: null,
|
||||
pfx: null,
|
||||
type: 'ClientCertificate',
|
||||
modified: expect.any(Number),
|
||||
created: expect.any(Number),
|
||||
},
|
||||
{
|
||||
_id: 'crt_dd2ccc1a2745477a881a9e8ef9d42403',
|
||||
@@ -54,6 +49,8 @@ describe('migrate()', () => {
|
||||
passphrase: 'mypass',
|
||||
pfx: null,
|
||||
type: 'ClientCertificate',
|
||||
modified: expect.any(Number),
|
||||
created: expect.any(Number),
|
||||
},
|
||||
]);
|
||||
expect(migratedWorkspace.certificates).toBeUndefined();
|
||||
@@ -65,15 +62,19 @@ describe('migrate()', () => {
|
||||
|
||||
it('translates the scope correctly', async () => {
|
||||
const specW = await services.workspace.create({
|
||||
// @ts-expect-error -- legacy migration test intentionally creates an old invalid scope
|
||||
scope: 'spec',
|
||||
});
|
||||
const debugW = await services.workspace.create({
|
||||
// @ts-expect-error -- legacy migration test intentionally creates an old invalid scope
|
||||
scope: 'debug',
|
||||
});
|
||||
const nullW = await services.workspace.create({
|
||||
// @ts-expect-error -- legacy migration test intentionally creates an old invalid scope
|
||||
scope: null,
|
||||
});
|
||||
const somethingElseW = await services.workspace.create({
|
||||
// @ts-expect-error -- legacy migration test intentionally creates an old invalid scope
|
||||
scope: 'something',
|
||||
});
|
||||
const designW = await services.workspace.create({
|
||||
@@ -24,7 +24,7 @@ export async function initDatabase(impl: IDatabase, config?: NeDB.DataStoreOptio
|
||||
* This is a getter that returns the initialized database instance.
|
||||
*
|
||||
* Usage:
|
||||
* - Import: `import { database } from '~/insomnia-data';`
|
||||
* - Import: `import { database } from 'insomnia-data';`
|
||||
* - Call methods directly: `await database.find(type, query);`
|
||||
*/
|
||||
export let database: IDatabase = new Proxy({} as IDatabase, {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { strings } from '~/insomnia-data/common';
|
||||
import { strings } from 'insomnia-data/common';
|
||||
|
||||
import type { BaseModel } from './base-types';
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user