mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 16:31:18 +02:00
Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@yaak/importer-yaak",
|
||||
"displayName": "Yaak Importer",
|
||||
"description": "Import data from Yaak export files",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Import data from Yaak export files",
|
||||
"scripts": {
|
||||
"build": "yaakcli build",
|
||||
"dev": "yaakcli dev",
|
||||
"test": "vitest --run tests"
|
||||
"test": "vp test --run tests"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Environment, PluginDefinition } from '@yaakapp/api';
|
||||
import type { Environment, PluginDefinition } from "@yaakapp/api";
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
importer: {
|
||||
name: 'Yaak',
|
||||
description: 'Yaak official format',
|
||||
name: "Yaak",
|
||||
description: "Yaak official format",
|
||||
onImport(_ctx, args) {
|
||||
return migrateImport(args.text);
|
||||
},
|
||||
@@ -11,7 +11,7 @@ export const plugin: PluginDefinition = {
|
||||
};
|
||||
|
||||
export function migrateImport(contents: string) {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: none
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
let parsed: any;
|
||||
try {
|
||||
parsed = JSON.parse(contents);
|
||||
@@ -23,24 +23,24 @@ export function migrateImport(contents: string) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const isYaakExport = 'yaakSchema' in parsed;
|
||||
const isYaakExport = "yaakSchema" in parsed;
|
||||
if (!isYaakExport) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Migrate v1 to v2 -- changes requests to httpRequests
|
||||
if ('requests' in parsed.resources) {
|
||||
if ("requests" in parsed.resources) {
|
||||
parsed.resources.httpRequests = parsed.resources.requests;
|
||||
parsed.resources.requests = undefined;
|
||||
}
|
||||
|
||||
// Migrate v2 to v3
|
||||
for (const workspace of parsed.resources.workspaces ?? []) {
|
||||
if ('variables' in workspace) {
|
||||
if ("variables" in workspace) {
|
||||
// Create the base environment
|
||||
const baseEnvironment: Partial<Environment> = {
|
||||
id: `GENERATE_ID::base_env_${workspace.id}`,
|
||||
name: 'Global Variables',
|
||||
name: "Global Variables",
|
||||
variables: workspace.variables,
|
||||
workspaceId: workspace.id,
|
||||
};
|
||||
@@ -61,7 +61,7 @@ export function migrateImport(contents: string) {
|
||||
|
||||
// Migrate v3 to v4
|
||||
for (const environment of parsed.resources.environments ?? []) {
|
||||
if ('environmentId' in environment) {
|
||||
if ("environmentId" in environment) {
|
||||
environment.base = environment.environmentId == null;
|
||||
environment.environmentId = undefined;
|
||||
}
|
||||
@@ -69,12 +69,12 @@ export function migrateImport(contents: string) {
|
||||
|
||||
// Migrate v4 to v5
|
||||
for (const environment of parsed.resources.environments ?? []) {
|
||||
if ('base' in environment && environment.base && environment.parentModel == null) {
|
||||
environment.parentModel = 'workspace';
|
||||
if ("base" in environment && environment.base && environment.parentModel == null) {
|
||||
environment.parentModel = "workspace";
|
||||
environment.parentId = null;
|
||||
environment.base = undefined;
|
||||
} else if ('base' in environment && !environment.base && environment.parentModel == null) {
|
||||
environment.parentModel = 'environment';
|
||||
} else if ("base" in environment && !environment.base && environment.parentModel == null) {
|
||||
environment.parentModel = "environment";
|
||||
environment.parentId = null;
|
||||
environment.base = undefined;
|
||||
}
|
||||
@@ -84,5 +84,5 @@ export function migrateImport(contents: string) {
|
||||
}
|
||||
|
||||
function isJSObject(obj: unknown) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||
return Object.prototype.toString.call(obj) === "[object Object]";
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { migrateImport } from '../src';
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { migrateImport } from "../src";
|
||||
|
||||
describe('importer-yaak', () => {
|
||||
test('Skips invalid imports', () => {
|
||||
expect(migrateImport('not JSON')).toBeUndefined();
|
||||
expect(migrateImport('[]')).toBeUndefined();
|
||||
describe("importer-yaak", () => {
|
||||
test("Skips invalid imports", () => {
|
||||
expect(migrateImport("not JSON")).toBeUndefined();
|
||||
expect(migrateImport("[]")).toBeUndefined();
|
||||
expect(migrateImport(JSON.stringify({ resources: {} }))).toBeUndefined();
|
||||
});
|
||||
|
||||
test('converts schema 1 to 2', () => {
|
||||
test("converts schema 1 to 2", () => {
|
||||
const imported = migrateImport(
|
||||
JSON.stringify({
|
||||
yaakSchema: 1,
|
||||
@@ -26,23 +26,23 @@ describe('importer-yaak', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
test('converts schema 2 to 3', () => {
|
||||
test("converts schema 2 to 3", () => {
|
||||
const imported = migrateImport(
|
||||
JSON.stringify({
|
||||
yaakSchema: 2,
|
||||
resources: {
|
||||
environments: [
|
||||
{
|
||||
id: 'e_1',
|
||||
workspaceId: 'w_1',
|
||||
name: 'Production',
|
||||
variables: [{ name: 'E1', value: 'E1!' }],
|
||||
id: "e_1",
|
||||
workspaceId: "w_1",
|
||||
name: "Production",
|
||||
variables: [{ name: "E1", value: "E1!" }],
|
||||
},
|
||||
],
|
||||
workspaces: [
|
||||
{
|
||||
id: 'w_1',
|
||||
variables: [{ name: 'W1', value: 'W1!' }],
|
||||
id: "w_1",
|
||||
variables: [{ name: "W1", value: "W1!" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -54,23 +54,23 @@ describe('importer-yaak', () => {
|
||||
resources: {
|
||||
workspaces: [
|
||||
{
|
||||
id: 'w_1',
|
||||
id: "w_1",
|
||||
},
|
||||
],
|
||||
environments: [
|
||||
{
|
||||
id: 'e_1',
|
||||
workspaceId: 'w_1',
|
||||
name: 'Production',
|
||||
variables: [{ name: 'E1', value: 'E1!' }],
|
||||
parentModel: 'environment',
|
||||
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!' }],
|
||||
id: "GENERATE_ID::base_env_w_1",
|
||||
workspaceId: "w_1",
|
||||
name: "Global Variables",
|
||||
variables: [{ name: "W1", value: "W1!" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -78,35 +78,35 @@ describe('importer-yaak', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('converts schema 4 to 5', () => {
|
||||
test("converts schema 4 to 5", () => {
|
||||
const imported = migrateImport(
|
||||
JSON.stringify({
|
||||
yaakSchema: 2,
|
||||
resources: {
|
||||
environments: [
|
||||
{
|
||||
id: 'e_1',
|
||||
workspaceId: 'w_1',
|
||||
id: "e_1",
|
||||
workspaceId: "w_1",
|
||||
base: false,
|
||||
name: 'Production',
|
||||
variables: [{ name: 'E1', value: 'E1!' }],
|
||||
name: "Production",
|
||||
variables: [{ name: "E1", value: "E1!" }],
|
||||
},
|
||||
{
|
||||
id: 'e_1',
|
||||
workspaceId: 'w_1',
|
||||
id: "e_1",
|
||||
workspaceId: "w_1",
|
||||
base: true,
|
||||
name: 'Global Variables',
|
||||
variables: [{ name: 'G1', value: 'G1!' }],
|
||||
name: "Global Variables",
|
||||
variables: [{ name: "G1", value: "G1!" }],
|
||||
},
|
||||
],
|
||||
folders: [
|
||||
{
|
||||
id: 'f_1',
|
||||
id: "f_1",
|
||||
},
|
||||
],
|
||||
workspaces: [
|
||||
{
|
||||
id: 'w_1',
|
||||
id: "w_1",
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -118,30 +118,30 @@ describe('importer-yaak', () => {
|
||||
resources: {
|
||||
workspaces: [
|
||||
{
|
||||
id: 'w_1',
|
||||
id: "w_1",
|
||||
},
|
||||
],
|
||||
folders: [
|
||||
{
|
||||
id: 'f_1',
|
||||
id: "f_1",
|
||||
},
|
||||
],
|
||||
environments: [
|
||||
{
|
||||
id: 'e_1',
|
||||
workspaceId: 'w_1',
|
||||
name: 'Production',
|
||||
variables: [{ name: 'E1', value: 'E1!' }],
|
||||
parentModel: 'environment',
|
||||
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',
|
||||
id: "e_1",
|
||||
workspaceId: "w_1",
|
||||
name: "Global Variables",
|
||||
parentModel: "workspace",
|
||||
parentId: null,
|
||||
variables: [{ name: 'G1', value: 'G1!' }],
|
||||
variables: [{ name: "G1", value: "G1!" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user