From 615de8b3cc39ccf54af86dcfd3d3aee540620a8d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 25 Sep 2025 07:12:50 -0700 Subject: [PATCH] Update importers for folder environment and fix tests --- .github/workflows/release.yml | 4 + package.json | 1 + plugins/action-copy-curl/package.json | 3 +- plugins/action-copy-grpcurl/package.json | 3 +- plugins/auth-bearer/package.json | 3 +- plugins/importer-curl/package.json | 3 +- plugins/importer-insomnia/package.json | 3 +- plugins/importer-insomnia/src/v5.ts | 76 +++++++--- .../fixtures/version-5-minimal.input.yaml | 2 + .../fixtures/version-5-minimal.output.json | 37 ++++- .../tests/fixtures/version-5.output.json | 19 ++- plugins/importer-openapi/package.json | 3 +- plugins/importer-postman/package.json | 3 +- plugins/importer-postman/src/index.ts | 8 +- .../tests/fixtures/nested.output.json | 9 +- .../tests/fixtures/params.output.json | 3 + plugins/importer-yaak/package.json | 3 +- plugins/importer-yaak/src/index.ts | 14 +- plugins/importer-yaak/tests/index.test.ts | 131 ++++++++++++++---- plugins/template-function-regex/package.json | 3 +- .../template-function-timestamp/package.json | 3 +- src-tauri/src/import.rs | 13 ++ 22 files changed, 273 insertions(+), 74 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc5900bc..655cd7e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,12 +72,16 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} + # Some things (eg. WASM package) requires building before lint will work - name: Run bootstrap run: npm run bootstrap - name: Run lint run: npm run lint + - name: Run tests + run: npm test + - name: Set version run: npm run replace-version env: diff --git a/package.json b/package.json index 10497315..8124d388 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "migration": "node scripts/create-migration.cjs", "build": "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: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", diff --git a/plugins/action-copy-curl/package.json b/plugins/action-copy-curl/package.json index 67ef7075..0fe3a23e 100644 --- a/plugins/action-copy-curl/package.json +++ b/plugins/action-copy-curl/package.json @@ -12,6 +12,7 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint": "tsc --noEmit && eslint . --ext .ts,.tsx" + "lint": "tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" } } diff --git a/plugins/action-copy-grpcurl/package.json b/plugins/action-copy-grpcurl/package.json index e8a3bedc..fbb92351 100644 --- a/plugins/action-copy-grpcurl/package.json +++ b/plugins/action-copy-grpcurl/package.json @@ -12,6 +12,7 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" } } diff --git a/plugins/auth-bearer/package.json b/plugins/auth-bearer/package.json index e10f87ee..b23ded8d 100644 --- a/plugins/auth-bearer/package.json +++ b/plugins/auth-bearer/package.json @@ -12,6 +12,7 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" } } diff --git a/plugins/importer-curl/package.json b/plugins/importer-curl/package.json index 027fd34d..b37db3ff 100644 --- a/plugins/importer-curl/package.json +++ b/plugins/importer-curl/package.json @@ -7,7 +7,8 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint": "tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" }, "dependencies": { "shell-quote": "^1.8.1" diff --git a/plugins/importer-insomnia/package.json b/plugins/importer-insomnia/package.json index 8315a1a9..de0fc0b0 100644 --- a/plugins/importer-insomnia/package.json +++ b/plugins/importer-insomnia/package.json @@ -7,7 +7,8 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" }, "dependencies": { "yaml": "^2.4.2" diff --git a/plugins/importer-insomnia/src/v5.ts b/plugins/importer-insomnia/src/v5.ts index feb63219..a5b0d3dc 100644 --- a/plugins/importer-insomnia/src/v5.ts +++ b/plugins/importer-insomnia/src/v5.ts @@ -30,18 +30,25 @@ export function convertInsomniaV5(parsed: any) { model: 'workspace', name: parsed.name, description: meta.description || undefined, + ...importHeaders(parsed), + ...importAuthentication(parsed), }); + + // Import environments resources.environments.push( importEnvironment(parsed.environments, meta.id, true), ...(parsed.environments.subEnvironments ?? []).map((r: any) => importEnvironment(r, meta.id)), ); + // Import folders const nextFolder = (children: any[], parentId: string) => { for (const child of children ?? []) { if (!isJSObject(child)) continue; 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); } else if (child.method) { resources.httpRequests.push(importHttpRequest(child, meta.id, parentId)); @@ -191,8 +198,8 @@ function importWebsocketRequest( }; } -function importHeaders(r: any) { - const headers = (r.headers ?? []) +function importHeaders(obj: any) { + const headers = (obj.headers ?? []) .map((h: any) => ({ enabled: !h.disabled, name: h.name ?? '', @@ -202,19 +209,19 @@ function importHeaders(r: any) { return { headers } as const; } -function importAuthentication(r: any) { +function importAuthentication(obj: any) { let authenticationType: string | null = null; let authentication = {}; - if (r.authentication?.type === 'bearer') { + if (obj.authentication?.type === 'bearer') { authenticationType = 'bearer'; 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'; authentication = { - username: convertSyntax(r.authentication.username), - password: convertSyntax(r.authentication.password), + username: convertSyntax(obj.authentication.username), + password: convertSyntax(obj.authentication.password), }; } @@ -225,22 +232,50 @@ function importFolder( f: any, workspaceId: string, parentId: string, -): PartialImportResources['folders'][0] { +): { + folder: PartialImportResources['folders'][0]; + environment: PartialImportResources['environments'][0] | null; +} { const id = f.meta?.id ?? f._id; const created = f.meta?.created ?? f.created; const updated = f.meta?.modified ?? f.updated; 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 { - model: 'folder', - id: convertId(id), - createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined, - updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined, - folderId: parentId === workspaceId ? null : convertId(parentId), - sortPriority: sortKey, - workspaceId: convertId(workspaceId), - description: f.description || undefined, - name: f.name, + folder: { + model: 'folder', + id: convertId(id), + createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined, + updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined, + folderId: parentId === workspaceId ? null : convertId(parentId), + sortPriority: sortKey, + workspaceId: convertId(workspaceId), + 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 // @ts-expect-error sortPriority: sortKey, // Will be added to Yaak later - base: isParent ?? e.parentId === workspaceId, + parentModel: isParent ? 'workspace' : 'environment', + parentId: null, model: 'environment', name: e.name, variables: Object.entries(e.data ?? {}).map(([name, value]) => ({ diff --git a/plugins/importer-insomnia/tests/fixtures/version-5-minimal.input.yaml b/plugins/importer-insomnia/tests/fixtures/version-5-minimal.input.yaml index ff7a005b..87a3bf02 100644 --- a/plugins/importer-insomnia/tests/fixtures/version-5-minimal.input.yaml +++ b/plugins/importer-insomnia/tests/fixtures/version-5-minimal.input.yaml @@ -38,6 +38,8 @@ collection: name: foo value: bar disabled: false + environment: + folder_env_var: testing - name: New Request meta: id: req_e3f8cdbd58784a539dd4c1e127d73451 diff --git a/plugins/importer-insomnia/tests/fixtures/version-5-minimal.output.json b/plugins/importer-insomnia/tests/fixtures/version-5-minimal.output.json index b581956c..4cfb4d9b 100644 --- a/plugins/importer-insomnia/tests/fixtures/version-5-minimal.output.json +++ b/plugins/importer-insomnia/tests/fixtures/version-5-minimal.output.json @@ -2,7 +2,6 @@ "resources": { "environments": [ { - "base": true, "createdAt": "2025-05-14T04:45:24.903", "id": "GENERATE_ID::env_e46dc73e8ccda30ca132153e8f11183bd08119ce", "model": "environment", @@ -10,6 +9,26 @@ "public": true, "updatedAt": "2025-05-14T04:45:24.903", "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" } ], @@ -22,7 +41,16 @@ "name": "My Folder", "sortPriority": -1747414092298, "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": [], @@ -80,7 +108,10 @@ "id": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c", "model": "workspace", "name": "Debugging", - "updatedAt": "2025-05-14T04:45:24.902" + "updatedAt": "2025-05-14T04:45:24.902", + "authentication": {}, + "authenticationType": null, + "headers": [] } ] } diff --git a/plugins/importer-insomnia/tests/fixtures/version-5.output.json b/plugins/importer-insomnia/tests/fixtures/version-5.output.json index 6b00c40a..4a72e90a 100644 --- a/plugins/importer-insomnia/tests/fixtures/version-5.output.json +++ b/plugins/importer-insomnia/tests/fixtures/version-5.output.json @@ -4,11 +4,12 @@ { "createdAt": "2025-01-13T15:15:43.767", "updatedAt": "2025-01-13T15:15:55.209", - "base": true, "public": true, "id": "GENERATE_ID::env_20945044d3c8497ca8b717bef750987e", "model": "environment", "name": "Base Environment", + "parentId": null, + "parentModel": "workspace", "variables": [ { "enabled": true, @@ -21,11 +22,12 @@ { "createdAt": "2025-01-13T15:15:58.515", "updatedAt": "2025-01-13T15:16:34.705", - "base": false, "public": true, "id": "GENERATE_ID::env_6f7728bb7fc04d558d668e954d756ea2", "model": "environment", "name": "Production", + "parentId": null, + "parentModel": "environment", "sortPriority": 1736781358515, "variables": [ { @@ -39,8 +41,9 @@ { "createdAt": "2025-01-13T15:16:14.707", "updatedAt": "2025-01-13T15:16:31.078", - "base": false, "public": true, + "parentId": null, + "parentModel": "environment", "id": "GENERATE_ID::env_976a8b6eb5d44fb6a20150f65c32d243", "model": "environment", "name": "Staging", @@ -64,7 +67,10 @@ "model": "folder", "name": "Top Level", "sortPriority": -1736781404718, - "workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53" + "workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53", + "authentication": {}, + "authenticationType": null, + "headers": [] } ], "grpcRequests": [ @@ -165,7 +171,10 @@ "description": "This is the description", "id": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53", "model": "workspace", - "name": "Dummy" + "name": "Dummy", + "authentication": {}, + "authenticationType": null, + "headers": [] } ] } diff --git a/plugins/importer-openapi/package.json b/plugins/importer-openapi/package.json index 21a08e2f..7dc4d690 100644 --- a/plugins/importer-openapi/package.json +++ b/plugins/importer-openapi/package.json @@ -7,7 +7,8 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" }, "dependencies": { "openapi-to-postmanv2": "^5.0.0", diff --git a/plugins/importer-postman/package.json b/plugins/importer-postman/package.json index ca8a2bcb..10cbef25 100644 --- a/plugins/importer-postman/package.json +++ b/plugins/importer-postman/package.json @@ -8,6 +8,7 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint": "tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" } } diff --git a/plugins/importer-postman/src/index.ts b/plugins/importer-postman/src/index.ts index c23aba10..370a37f4 100644 --- a/plugins/importer-postman/src/index.ts +++ b/plugins/importer-postman/src/index.ts @@ -57,9 +57,11 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin const rawDescription = info.description; const description = - typeof rawDescription === 'object' && rawDescription !== null && 'content' in rawDescription + typeof rawDescription === 'object' && rawDescription != null && 'content' in rawDescription ? String(rawDescription.content) - : String(rawDescription); + : rawDescription == null + ? undefined + : String(rawDescription); const workspace: ExportResources['workspaces'][0] = { model: 'workspace', @@ -75,6 +77,8 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin id: generateId('environment'), name: 'Global Variables', workspaceId: workspace.id, + parentModel: 'workspace', + parentId: null, variables: toArray<{ key: string; value: string }>(root.variable).map((v) => ({ name: v.key, diff --git a/plugins/importer-postman/tests/fixtures/nested.output.json b/plugins/importer-postman/tests/fixtures/nested.output.json index 9e9bfaab..b44cab1b 100644 --- a/plugins/importer-postman/tests/fixtures/nested.output.json +++ b/plugins/importer-postman/tests/fixtures/nested.output.json @@ -13,7 +13,9 @@ "model": "environment", "name": "Global Variables", "variables": [], - "workspaceId": "GENERATE_ID::WORKSPACE_0" + "workspaceId": "GENERATE_ID::WORKSPACE_0", + "parentId": null, + "parentModel": "workspace" } ], "httpRequests": [ @@ -25,6 +27,7 @@ "name": "Request 1", "method": "GET", "url": "", + "sortPriority": 2, "urlParameters": [], "body": {}, "bodyType": null, @@ -39,6 +42,7 @@ "folderId": "GENERATE_ID::FOLDER_0", "name": "Request 2", "method": "GET", + "sortPriority": 3, "url": "", "urlParameters": [], "body": {}, @@ -52,6 +56,7 @@ "id": "GENERATE_ID::HTTP_REQUEST_2", "workspaceId": "GENERATE_ID::WORKSPACE_0", "folderId": null, + "sortPriority": 4, "name": "Request 3", "method": "GET", "url": "", @@ -69,6 +74,7 @@ "workspaceId": "GENERATE_ID::WORKSPACE_0", "id": "GENERATE_ID::FOLDER_0", "name": "Top Folder", + "sortPriority": 0, "folderId": null }, { @@ -76,6 +82,7 @@ "workspaceId": "GENERATE_ID::WORKSPACE_0", "id": "GENERATE_ID::FOLDER_1", "name": "Nested Folder", + "sortPriority": 1, "folderId": "GENERATE_ID::FOLDER_0" } ] diff --git a/plugins/importer-postman/tests/fixtures/params.output.json b/plugins/importer-postman/tests/fixtures/params.output.json index 1eb16ce3..34acac0a 100644 --- a/plugins/importer-postman/tests/fixtures/params.output.json +++ b/plugins/importer-postman/tests/fixtures/params.output.json @@ -13,6 +13,8 @@ "workspaceId": "GENERATE_ID::WORKSPACE_1", "model": "environment", "name": "Global Variables", + "parentId": null, + "parentModel": "workspace", "variables": [ { "name": "COLLECTION VARIABLE", @@ -28,6 +30,7 @@ "workspaceId": "GENERATE_ID::WORKSPACE_1", "folderId": null, "name": "Form URL", + "sortPriority": 0, "method": "POST", "url": "example.com/:foo/:bar", "urlParameters": [ diff --git a/plugins/importer-yaak/package.json b/plugins/importer-yaak/package.json index 45c1d0a4..9bdd07de 100644 --- a/plugins/importer-yaak/package.json +++ b/plugins/importer-yaak/package.json @@ -7,6 +7,7 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" } } diff --git a/plugins/importer-yaak/src/index.ts b/plugins/importer-yaak/src/index.ts index 61fd6e38..e5907c8a 100644 --- a/plugins/importer-yaak/src/index.ts +++ b/plugins/importer-yaak/src/index.ts @@ -69,15 +69,13 @@ export function migrateImport(contents: string) { // Migrate v4 to v5 for (const environment of parsed.resources.environments ?? []) { if ('base' in environment && environment.base) { - environment.parentId = environment.workspaceId; - environment.parentType = 'workspace'; - delete environment.environmentId; + environment.parentModel = 'workspace'; + environment.parentId = null; + delete environment.base; } else if ('base' in environment && !environment.base) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const baseEnvironment = parsed.resources.environments.find((e: any) => e.base); - environment.parentId = baseEnvironment?.id ?? null; - environment.parentType = 'environment'; - delete environment.environmentId; + environment.parentModel = 'environment'; + environment.parentId = null; + delete environment.base; } } diff --git a/plugins/importer-yaak/tests/index.test.ts b/plugins/importer-yaak/tests/index.test.ts index a55e62b1..634f76d0 100644 --- a/plugins/importer-yaak/tests/index.test.ts +++ b/plugins/importer-yaak/tests/index.test.ts @@ -31,16 +31,20 @@ describe('importer-yaak', () => { JSON.stringify({ yaakSchema: 2, resources: { - environments: [{ - id: 'e_1', - workspaceId: 'w_1', - name: 'Production', - variables: [{ name: 'E1', value: 'E1!' }], - }], - workspaces: [{ - id: 'w_1', - variables: [{ name: 'W1', value: 'W1!' }], - }], + environments: [ + { + id: 'e_1', + workspaceId: 'w_1', + name: 'Production', + variables: [{ name: 'E1', value: 'E1!' }], + }, + ], + workspaces: [ + { + id: 'w_1', + variables: [{ name: 'W1', value: 'W1!' }], + }, + ], }, }), ); @@ -48,21 +52,98 @@ describe('importer-yaak', () => { expect(imported).toEqual( expect.objectContaining({ resources: { - workspaces: [{ - id: 'w_1', - }], - environments: [{ - id: 'e_1', - base: false, - workspaceId: 'w_1', - name: 'Production', - variables: [{ name: 'E1', value: 'E1!' }], - }, { - id: 'GENERATE_ID::base_env_w_1', - workspaceId: 'w_1', - name: 'Global Variables', - variables: [{ name: 'W1', value: 'W1!' }], - }], + workspaces: [ + { + id: 'w_1', + }, + ], + environments: [ + { + id: 'e_1', + workspaceId: 'w_1', + name: 'Production', + variables: [{ name: 'E1', value: 'E1!' }], + parentModel: 'environment', + parentId: null, + }, + { + 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!' }], + }, + ], }, }), ); diff --git a/plugins/template-function-regex/package.json b/plugins/template-function-regex/package.json index bd8797f8..64bb767d 100644 --- a/plugins/template-function-regex/package.json +++ b/plugins/template-function-regex/package.json @@ -7,6 +7,7 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" } } diff --git a/plugins/template-function-timestamp/package.json b/plugins/template-function-timestamp/package.json index d79ff99f..d11ee831 100755 --- a/plugins/template-function-timestamp/package.json +++ b/plugins/template-function-timestamp/package.json @@ -5,7 +5,8 @@ "scripts": { "build": "yaakcli build", "dev": "yaakcli dev", - "lint":"tsc --noEmit && eslint . --ext .ts,.tsx" + "lint":"tsc --noEmit && eslint . --ext .ts,.tsx", + "test": "vitest --run tests" }, "dependencies": { "date-fns": "^4.1.0" diff --git a/src-tauri/src/import.rs b/src-tauri/src/import.rs index 5a118d93..5f9972de 100644 --- a/src-tauri/src/import.rs +++ b/src-tauri/src/import.rs @@ -39,6 +39,19 @@ pub(crate) async fn import_data( .map(|mut v| { v.id = maybe_gen_id::(v.id.as_str(), &mut id_map); v.workspace_id = maybe_gen_id::(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::(&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 }) .collect();