mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 22:40:26 +01:00
Update importers for folder environment and fix tests
This commit is contained in:
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@@ -72,12 +72,16 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# Some things (eg. WASM package) requires building before lint will work
|
||||||
- name: Run bootstrap
|
- name: Run bootstrap
|
||||||
run: npm run bootstrap
|
run: npm run bootstrap
|
||||||
|
|
||||||
- name: Run lint
|
- name: Run lint
|
||||||
run: npm run lint
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: npm test
|
||||||
|
|
||||||
- name: Set version
|
- name: Set version
|
||||||
run: npm run replace-version
|
run: npm run replace-version
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
"migration": "node scripts/create-migration.cjs",
|
"migration": "node scripts/create-migration.cjs",
|
||||||
"build": "npm run --workspaces --if-present build",
|
"build": "npm run --workspaces --if-present build",
|
||||||
"build-plugins": "npm run --workspaces --if-present build",
|
"build-plugins": "npm run --workspaces --if-present build",
|
||||||
|
"test": "npm run --workspaces --if-present test",
|
||||||
"icons": "run-p icons:*",
|
"icons": "run-p icons:*",
|
||||||
"icons:dev": "tauri icon src-tauri/icons/icon.png --output src-tauri/icons/release",
|
"icons:dev": "tauri icon src-tauri/icons/icon.png --output src-tauri/icons/release",
|
||||||
"icons:release": "tauri icon src-tauri/icons/icon-dev.png --output src-tauri/icons/dev",
|
"icons:release": "tauri icon src-tauri/icons/icon-dev.png --output src-tauri/icons/dev",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"shell-quote": "^1.8.1"
|
"shell-quote": "^1.8.1"
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"yaml": "^2.4.2"
|
"yaml": "^2.4.2"
|
||||||
|
|||||||
@@ -30,18 +30,25 @@ export function convertInsomniaV5(parsed: any) {
|
|||||||
model: 'workspace',
|
model: 'workspace',
|
||||||
name: parsed.name,
|
name: parsed.name,
|
||||||
description: meta.description || undefined,
|
description: meta.description || undefined,
|
||||||
|
...importHeaders(parsed),
|
||||||
|
...importAuthentication(parsed),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Import environments
|
||||||
resources.environments.push(
|
resources.environments.push(
|
||||||
importEnvironment(parsed.environments, meta.id, true),
|
importEnvironment(parsed.environments, meta.id, true),
|
||||||
...(parsed.environments.subEnvironments ?? []).map((r: any) => importEnvironment(r, meta.id)),
|
...(parsed.environments.subEnvironments ?? []).map((r: any) => importEnvironment(r, meta.id)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Import folders
|
||||||
const nextFolder = (children: any[], parentId: string) => {
|
const nextFolder = (children: any[], parentId: string) => {
|
||||||
for (const child of children ?? []) {
|
for (const child of children ?? []) {
|
||||||
if (!isJSObject(child)) continue;
|
if (!isJSObject(child)) continue;
|
||||||
|
|
||||||
if (Array.isArray(child.children)) {
|
if (Array.isArray(child.children)) {
|
||||||
resources.folders.push(importFolder(child, meta.id, parentId));
|
const { folder, environment } = importFolder(child, meta.id, parentId);
|
||||||
|
resources.folders.push(folder);
|
||||||
|
if (environment) resources.environments.push(environment);
|
||||||
nextFolder(child.children, child.meta.id);
|
nextFolder(child.children, child.meta.id);
|
||||||
} else if (child.method) {
|
} else if (child.method) {
|
||||||
resources.httpRequests.push(importHttpRequest(child, meta.id, parentId));
|
resources.httpRequests.push(importHttpRequest(child, meta.id, parentId));
|
||||||
@@ -191,8 +198,8 @@ function importWebsocketRequest(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function importHeaders(r: any) {
|
function importHeaders(obj: any) {
|
||||||
const headers = (r.headers ?? [])
|
const headers = (obj.headers ?? [])
|
||||||
.map((h: any) => ({
|
.map((h: any) => ({
|
||||||
enabled: !h.disabled,
|
enabled: !h.disabled,
|
||||||
name: h.name ?? '',
|
name: h.name ?? '',
|
||||||
@@ -202,19 +209,19 @@ function importHeaders(r: any) {
|
|||||||
return { headers } as const;
|
return { headers } as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
function importAuthentication(r: any) {
|
function importAuthentication(obj: any) {
|
||||||
let authenticationType: string | null = null;
|
let authenticationType: string | null = null;
|
||||||
let authentication = {};
|
let authentication = {};
|
||||||
if (r.authentication?.type === 'bearer') {
|
if (obj.authentication?.type === 'bearer') {
|
||||||
authenticationType = 'bearer';
|
authenticationType = 'bearer';
|
||||||
authentication = {
|
authentication = {
|
||||||
token: convertSyntax(r.authentication.token),
|
token: convertSyntax(obj.authentication.token),
|
||||||
};
|
};
|
||||||
} else if (r.authentication?.type === 'basic') {
|
} else if (obj.authentication?.type === 'basic') {
|
||||||
authenticationType = 'basic';
|
authenticationType = 'basic';
|
||||||
authentication = {
|
authentication = {
|
||||||
username: convertSyntax(r.authentication.username),
|
username: convertSyntax(obj.authentication.username),
|
||||||
password: convertSyntax(r.authentication.password),
|
password: convertSyntax(obj.authentication.password),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,22 +232,50 @@ function importFolder(
|
|||||||
f: any,
|
f: any,
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
parentId: string,
|
parentId: string,
|
||||||
): PartialImportResources['folders'][0] {
|
): {
|
||||||
|
folder: PartialImportResources['folders'][0];
|
||||||
|
environment: PartialImportResources['environments'][0] | null;
|
||||||
|
} {
|
||||||
const id = f.meta?.id ?? f._id;
|
const id = f.meta?.id ?? f._id;
|
||||||
const created = f.meta?.created ?? f.created;
|
const created = f.meta?.created ?? f.created;
|
||||||
const updated = f.meta?.modified ?? f.updated;
|
const updated = f.meta?.modified ?? f.updated;
|
||||||
const sortKey = f.meta?.sortKey ?? f.sortKey;
|
const sortKey = f.meta?.sortKey ?? f.sortKey;
|
||||||
|
|
||||||
|
let environment: PartialImportResources['environments'][0] | null = null;
|
||||||
|
if (Object.keys(f.environment ?? {}).length > 0) {
|
||||||
|
environment = {
|
||||||
|
id: convertId(id + 'folder'),
|
||||||
|
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||||
|
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||||
|
workspaceId: convertId(workspaceId),
|
||||||
|
public: true,
|
||||||
|
parentModel: 'folder',
|
||||||
|
parentId: convertId(id),
|
||||||
|
model: 'environment',
|
||||||
|
name: 'Folder Environment',
|
||||||
|
variables: Object.entries(f.environment ?? {}).map(([name, value]) => ({
|
||||||
|
enabled: true,
|
||||||
|
name,
|
||||||
|
value: `${value}`,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
model: 'folder',
|
folder: {
|
||||||
id: convertId(id),
|
model: 'folder',
|
||||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
id: convertId(id),
|
||||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||||
folderId: parentId === workspaceId ? null : convertId(parentId),
|
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||||
sortPriority: sortKey,
|
folderId: parentId === workspaceId ? null : convertId(parentId),
|
||||||
workspaceId: convertId(workspaceId),
|
sortPriority: sortKey,
|
||||||
description: f.description || undefined,
|
workspaceId: convertId(workspaceId),
|
||||||
name: f.name,
|
description: f.description || undefined,
|
||||||
|
name: f.name,
|
||||||
|
...importAuthentication(f),
|
||||||
|
...importHeaders(f),
|
||||||
|
},
|
||||||
|
environment,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +298,8 @@ function importEnvironment(
|
|||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
sortPriority: sortKey, // Will be added to Yaak later
|
sortPriority: sortKey, // Will be added to Yaak later
|
||||||
base: isParent ?? e.parentId === workspaceId,
|
parentModel: isParent ? 'workspace' : 'environment',
|
||||||
|
parentId: null,
|
||||||
model: 'environment',
|
model: 'environment',
|
||||||
name: e.name,
|
name: e.name,
|
||||||
variables: Object.entries(e.data ?? {}).map(([name, value]) => ({
|
variables: Object.entries(e.data ?? {}).map(([name, value]) => ({
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ collection:
|
|||||||
name: foo
|
name: foo
|
||||||
value: bar
|
value: bar
|
||||||
disabled: false
|
disabled: false
|
||||||
|
environment:
|
||||||
|
folder_env_var: testing
|
||||||
- name: New Request
|
- name: New Request
|
||||||
meta:
|
meta:
|
||||||
id: req_e3f8cdbd58784a539dd4c1e127d73451
|
id: req_e3f8cdbd58784a539dd4c1e127d73451
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
"resources": {
|
"resources": {
|
||||||
"environments": [
|
"environments": [
|
||||||
{
|
{
|
||||||
"base": true,
|
|
||||||
"createdAt": "2025-05-14T04:45:24.903",
|
"createdAt": "2025-05-14T04:45:24.903",
|
||||||
"id": "GENERATE_ID::env_e46dc73e8ccda30ca132153e8f11183bd08119ce",
|
"id": "GENERATE_ID::env_e46dc73e8ccda30ca132153e8f11183bd08119ce",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
@@ -10,6 +9,26 @@
|
|||||||
"public": true,
|
"public": true,
|
||||||
"updatedAt": "2025-05-14T04:45:24.903",
|
"updatedAt": "2025-05-14T04:45:24.903",
|
||||||
"variables": [],
|
"variables": [],
|
||||||
|
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
||||||
|
"parentId": null,
|
||||||
|
"parentModel": "workspace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createdAt": "2025-05-16T16:48:12.298",
|
||||||
|
"id": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7folder",
|
||||||
|
"model": "environment",
|
||||||
|
"name": "Folder Environment",
|
||||||
|
"parentId": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7",
|
||||||
|
"parentModel": "folder",
|
||||||
|
"public": true,
|
||||||
|
"updatedAt": "2025-05-16T16:49:02.427",
|
||||||
|
"variables": [
|
||||||
|
{
|
||||||
|
"enabled": true,
|
||||||
|
"name": "folder_env_var",
|
||||||
|
"value": "testing"
|
||||||
|
}
|
||||||
|
],
|
||||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -22,7 +41,16 @@
|
|||||||
"name": "My Folder",
|
"name": "My Folder",
|
||||||
"sortPriority": -1747414092298,
|
"sortPriority": -1747414092298,
|
||||||
"updatedAt": "2025-05-16T16:49:02.427",
|
"updatedAt": "2025-05-16T16:49:02.427",
|
||||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
||||||
|
"authentication": {},
|
||||||
|
"authenticationType": null,
|
||||||
|
"headers": [
|
||||||
|
{
|
||||||
|
"enabled": true,
|
||||||
|
"name": "foo",
|
||||||
|
"value": "bar"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"grpcRequests": [],
|
"grpcRequests": [],
|
||||||
@@ -80,7 +108,10 @@
|
|||||||
"id": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
"id": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
||||||
"model": "workspace",
|
"model": "workspace",
|
||||||
"name": "Debugging",
|
"name": "Debugging",
|
||||||
"updatedAt": "2025-05-14T04:45:24.902"
|
"updatedAt": "2025-05-14T04:45:24.902",
|
||||||
|
"authentication": {},
|
||||||
|
"authenticationType": null,
|
||||||
|
"headers": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,12 @@
|
|||||||
{
|
{
|
||||||
"createdAt": "2025-01-13T15:15:43.767",
|
"createdAt": "2025-01-13T15:15:43.767",
|
||||||
"updatedAt": "2025-01-13T15:15:55.209",
|
"updatedAt": "2025-01-13T15:15:55.209",
|
||||||
"base": true,
|
|
||||||
"public": true,
|
"public": true,
|
||||||
"id": "GENERATE_ID::env_20945044d3c8497ca8b717bef750987e",
|
"id": "GENERATE_ID::env_20945044d3c8497ca8b717bef750987e",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Base Environment",
|
"name": "Base Environment",
|
||||||
|
"parentId": null,
|
||||||
|
"parentModel": "workspace",
|
||||||
"variables": [
|
"variables": [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
@@ -21,11 +22,12 @@
|
|||||||
{
|
{
|
||||||
"createdAt": "2025-01-13T15:15:58.515",
|
"createdAt": "2025-01-13T15:15:58.515",
|
||||||
"updatedAt": "2025-01-13T15:16:34.705",
|
"updatedAt": "2025-01-13T15:16:34.705",
|
||||||
"base": false,
|
|
||||||
"public": true,
|
"public": true,
|
||||||
"id": "GENERATE_ID::env_6f7728bb7fc04d558d668e954d756ea2",
|
"id": "GENERATE_ID::env_6f7728bb7fc04d558d668e954d756ea2",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Production",
|
"name": "Production",
|
||||||
|
"parentId": null,
|
||||||
|
"parentModel": "environment",
|
||||||
"sortPriority": 1736781358515,
|
"sortPriority": 1736781358515,
|
||||||
"variables": [
|
"variables": [
|
||||||
{
|
{
|
||||||
@@ -39,8 +41,9 @@
|
|||||||
{
|
{
|
||||||
"createdAt": "2025-01-13T15:16:14.707",
|
"createdAt": "2025-01-13T15:16:14.707",
|
||||||
"updatedAt": "2025-01-13T15:16:31.078",
|
"updatedAt": "2025-01-13T15:16:31.078",
|
||||||
"base": false,
|
|
||||||
"public": true,
|
"public": true,
|
||||||
|
"parentId": null,
|
||||||
|
"parentModel": "environment",
|
||||||
"id": "GENERATE_ID::env_976a8b6eb5d44fb6a20150f65c32d243",
|
"id": "GENERATE_ID::env_976a8b6eb5d44fb6a20150f65c32d243",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Staging",
|
"name": "Staging",
|
||||||
@@ -64,7 +67,10 @@
|
|||||||
"model": "folder",
|
"model": "folder",
|
||||||
"name": "Top Level",
|
"name": "Top Level",
|
||||||
"sortPriority": -1736781404718,
|
"sortPriority": -1736781404718,
|
||||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
|
||||||
|
"authentication": {},
|
||||||
|
"authenticationType": null,
|
||||||
|
"headers": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"grpcRequests": [
|
"grpcRequests": [
|
||||||
@@ -165,7 +171,10 @@
|
|||||||
"description": "This is the description",
|
"description": "This is the description",
|
||||||
"id": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
|
"id": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
|
||||||
"model": "workspace",
|
"model": "workspace",
|
||||||
"name": "Dummy"
|
"name": "Dummy",
|
||||||
|
"authentication": {},
|
||||||
|
"authenticationType": null,
|
||||||
|
"headers": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"openapi-to-postmanv2": "^5.0.0",
|
"openapi-to-postmanv2": "^5.0.0",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,9 +57,11 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
|
|||||||
|
|
||||||
const rawDescription = info.description;
|
const rawDescription = info.description;
|
||||||
const description =
|
const description =
|
||||||
typeof rawDescription === 'object' && rawDescription !== null && 'content' in rawDescription
|
typeof rawDescription === 'object' && rawDescription != null && 'content' in rawDescription
|
||||||
? String(rawDescription.content)
|
? String(rawDescription.content)
|
||||||
: String(rawDescription);
|
: rawDescription == null
|
||||||
|
? undefined
|
||||||
|
: String(rawDescription);
|
||||||
|
|
||||||
const workspace: ExportResources['workspaces'][0] = {
|
const workspace: ExportResources['workspaces'][0] = {
|
||||||
model: 'workspace',
|
model: 'workspace',
|
||||||
@@ -75,6 +77,8 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
|
|||||||
id: generateId('environment'),
|
id: generateId('environment'),
|
||||||
name: 'Global Variables',
|
name: 'Global Variables',
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
|
parentModel: 'workspace',
|
||||||
|
parentId: null,
|
||||||
variables:
|
variables:
|
||||||
toArray<{ key: string; value: string }>(root.variable).map((v) => ({
|
toArray<{ key: string; value: string }>(root.variable).map((v) => ({
|
||||||
name: v.key,
|
name: v.key,
|
||||||
|
|||||||
@@ -13,7 +13,9 @@
|
|||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Global Variables",
|
"name": "Global Variables",
|
||||||
"variables": [],
|
"variables": [],
|
||||||
"workspaceId": "GENERATE_ID::WORKSPACE_0"
|
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
||||||
|
"parentId": null,
|
||||||
|
"parentModel": "workspace"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"httpRequests": [
|
"httpRequests": [
|
||||||
@@ -25,6 +27,7 @@
|
|||||||
"name": "Request 1",
|
"name": "Request 1",
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"url": "",
|
"url": "",
|
||||||
|
"sortPriority": 2,
|
||||||
"urlParameters": [],
|
"urlParameters": [],
|
||||||
"body": {},
|
"body": {},
|
||||||
"bodyType": null,
|
"bodyType": null,
|
||||||
@@ -39,6 +42,7 @@
|
|||||||
"folderId": "GENERATE_ID::FOLDER_0",
|
"folderId": "GENERATE_ID::FOLDER_0",
|
||||||
"name": "Request 2",
|
"name": "Request 2",
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
|
"sortPriority": 3,
|
||||||
"url": "",
|
"url": "",
|
||||||
"urlParameters": [],
|
"urlParameters": [],
|
||||||
"body": {},
|
"body": {},
|
||||||
@@ -52,6 +56,7 @@
|
|||||||
"id": "GENERATE_ID::HTTP_REQUEST_2",
|
"id": "GENERATE_ID::HTTP_REQUEST_2",
|
||||||
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
||||||
"folderId": null,
|
"folderId": null,
|
||||||
|
"sortPriority": 4,
|
||||||
"name": "Request 3",
|
"name": "Request 3",
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"url": "",
|
"url": "",
|
||||||
@@ -69,6 +74,7 @@
|
|||||||
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
||||||
"id": "GENERATE_ID::FOLDER_0",
|
"id": "GENERATE_ID::FOLDER_0",
|
||||||
"name": "Top Folder",
|
"name": "Top Folder",
|
||||||
|
"sortPriority": 0,
|
||||||
"folderId": null
|
"folderId": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -76,6 +82,7 @@
|
|||||||
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
"workspaceId": "GENERATE_ID::WORKSPACE_0",
|
||||||
"id": "GENERATE_ID::FOLDER_1",
|
"id": "GENERATE_ID::FOLDER_1",
|
||||||
"name": "Nested Folder",
|
"name": "Nested Folder",
|
||||||
|
"sortPriority": 1,
|
||||||
"folderId": "GENERATE_ID::FOLDER_0"
|
"folderId": "GENERATE_ID::FOLDER_0"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
"workspaceId": "GENERATE_ID::WORKSPACE_1",
|
"workspaceId": "GENERATE_ID::WORKSPACE_1",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Global Variables",
|
"name": "Global Variables",
|
||||||
|
"parentId": null,
|
||||||
|
"parentModel": "workspace",
|
||||||
"variables": [
|
"variables": [
|
||||||
{
|
{
|
||||||
"name": "COLLECTION VARIABLE",
|
"name": "COLLECTION VARIABLE",
|
||||||
@@ -28,6 +30,7 @@
|
|||||||
"workspaceId": "GENERATE_ID::WORKSPACE_1",
|
"workspaceId": "GENERATE_ID::WORKSPACE_1",
|
||||||
"folderId": null,
|
"folderId": null,
|
||||||
"name": "Form URL",
|
"name": "Form URL",
|
||||||
|
"sortPriority": 0,
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "example.com/:foo/:bar",
|
"url": "example.com/:foo/:bar",
|
||||||
"urlParameters": [
|
"urlParameters": [
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,15 +69,13 @@ export function migrateImport(contents: string) {
|
|||||||
// Migrate v4 to v5
|
// Migrate v4 to v5
|
||||||
for (const environment of parsed.resources.environments ?? []) {
|
for (const environment of parsed.resources.environments ?? []) {
|
||||||
if ('base' in environment && environment.base) {
|
if ('base' in environment && environment.base) {
|
||||||
environment.parentId = environment.workspaceId;
|
environment.parentModel = 'workspace';
|
||||||
environment.parentType = 'workspace';
|
environment.parentId = null;
|
||||||
delete environment.environmentId;
|
delete environment.base;
|
||||||
} else if ('base' in environment && !environment.base) {
|
} else if ('base' in environment && !environment.base) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
environment.parentModel = 'environment';
|
||||||
const baseEnvironment = parsed.resources.environments.find((e: any) => e.base);
|
environment.parentId = null;
|
||||||
environment.parentId = baseEnvironment?.id ?? null;
|
delete environment.base;
|
||||||
environment.parentType = 'environment';
|
|
||||||
delete environment.environmentId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,16 +31,20 @@ describe('importer-yaak', () => {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
yaakSchema: 2,
|
yaakSchema: 2,
|
||||||
resources: {
|
resources: {
|
||||||
environments: [{
|
environments: [
|
||||||
id: 'e_1',
|
{
|
||||||
workspaceId: 'w_1',
|
id: 'e_1',
|
||||||
name: 'Production',
|
workspaceId: 'w_1',
|
||||||
variables: [{ name: 'E1', value: 'E1!' }],
|
name: 'Production',
|
||||||
}],
|
variables: [{ name: 'E1', value: 'E1!' }],
|
||||||
workspaces: [{
|
},
|
||||||
id: 'w_1',
|
],
|
||||||
variables: [{ name: 'W1', value: 'W1!' }],
|
workspaces: [
|
||||||
}],
|
{
|
||||||
|
id: 'w_1',
|
||||||
|
variables: [{ name: 'W1', value: 'W1!' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -48,21 +52,98 @@ describe('importer-yaak', () => {
|
|||||||
expect(imported).toEqual(
|
expect(imported).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
resources: {
|
resources: {
|
||||||
workspaces: [{
|
workspaces: [
|
||||||
id: 'w_1',
|
{
|
||||||
}],
|
id: 'w_1',
|
||||||
environments: [{
|
},
|
||||||
id: 'e_1',
|
],
|
||||||
base: false,
|
environments: [
|
||||||
workspaceId: 'w_1',
|
{
|
||||||
name: 'Production',
|
id: 'e_1',
|
||||||
variables: [{ name: 'E1', value: 'E1!' }],
|
workspaceId: 'w_1',
|
||||||
}, {
|
name: 'Production',
|
||||||
id: 'GENERATE_ID::base_env_w_1',
|
variables: [{ name: 'E1', value: 'E1!' }],
|
||||||
workspaceId: 'w_1',
|
parentModel: 'environment',
|
||||||
name: 'Global Variables',
|
parentId: null,
|
||||||
variables: [{ name: 'W1', value: 'W1!' }],
|
},
|
||||||
}],
|
{
|
||||||
|
id: 'GENERATE_ID::base_env_w_1',
|
||||||
|
workspaceId: 'w_1',
|
||||||
|
name: 'Global Variables',
|
||||||
|
variables: [{ name: 'W1', value: 'W1!' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('converts schema 4 to 5', () => {
|
||||||
|
const imported = migrateImport(
|
||||||
|
JSON.stringify({
|
||||||
|
yaakSchema: 2,
|
||||||
|
resources: {
|
||||||
|
environments: [
|
||||||
|
{
|
||||||
|
id: 'e_1',
|
||||||
|
workspaceId: 'w_1',
|
||||||
|
base: false,
|
||||||
|
name: 'Production',
|
||||||
|
variables: [{ name: 'E1', value: 'E1!' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'e_1',
|
||||||
|
workspaceId: 'w_1',
|
||||||
|
base: true,
|
||||||
|
name: 'Global Variables',
|
||||||
|
variables: [{ name: 'G1', value: 'G1!' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
folders: [
|
||||||
|
{
|
||||||
|
id: 'f_1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
workspaces: [
|
||||||
|
{
|
||||||
|
id: 'w_1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(imported).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
resources: {
|
||||||
|
workspaces: [
|
||||||
|
{
|
||||||
|
id: 'w_1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
folders: [
|
||||||
|
{
|
||||||
|
id: 'f_1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
environments: [
|
||||||
|
{
|
||||||
|
id: 'e_1',
|
||||||
|
workspaceId: 'w_1',
|
||||||
|
name: 'Production',
|
||||||
|
variables: [{ name: 'E1', value: 'E1!' }],
|
||||||
|
parentModel: 'environment',
|
||||||
|
parentId: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'e_1',
|
||||||
|
workspaceId: 'w_1',
|
||||||
|
name: 'Global Variables',
|
||||||
|
parentModel: 'workspace',
|
||||||
|
parentId: null,
|
||||||
|
variables: [{ name: 'G1', value: 'G1!' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yaakcli build",
|
"build": "yaakcli build",
|
||||||
"dev": "yaakcli dev",
|
"dev": "yaakcli dev",
|
||||||
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
|
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
|
||||||
|
"test": "vitest --run tests"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"date-fns": "^4.1.0"
|
"date-fns": "^4.1.0"
|
||||||
|
|||||||
@@ -39,6 +39,19 @@ pub(crate) async fn import_data<R: Runtime>(
|
|||||||
.map(|mut v| {
|
.map(|mut v| {
|
||||||
v.id = maybe_gen_id::<Environment>(v.id.as_str(), &mut id_map);
|
v.id = maybe_gen_id::<Environment>(v.id.as_str(), &mut id_map);
|
||||||
v.workspace_id = maybe_gen_id::<Workspace>(v.workspace_id.as_str(), &mut id_map);
|
v.workspace_id = maybe_gen_id::<Workspace>(v.workspace_id.as_str(), &mut id_map);
|
||||||
|
match (v.parent_model.as_str(), v.parent_id.clone().as_deref()) {
|
||||||
|
("folder", Some(parent_id)) => {
|
||||||
|
v.parent_id = Some(maybe_gen_id::<Folder>(&parent_id, &mut id_map));
|
||||||
|
}
|
||||||
|
("", _) => {
|
||||||
|
// Fix any empty ones
|
||||||
|
v.parent_model = "workspace".to_string();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Parent ID only required for the folder case
|
||||||
|
v.parent_id = None;
|
||||||
|
}
|
||||||
|
};
|
||||||
v
|
v
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
Reference in New Issue
Block a user