Logic for new Environment.base field

This commit is contained in:
Gregory Schier
2025-05-08 14:28:41 -07:00
parent edf65a62c2
commit a5333deb71
8 changed files with 26 additions and 43 deletions

20
package-lock.json generated
View File

@@ -9,7 +9,7 @@
"plugins/*"
],
"dependencies": {
"@yaakapp/api": "^0.5.0"
"@yaakapp/api": "^0.5.1"
},
"devDependencies": {
"@types/node": "^22.7.4",
@@ -999,9 +999,9 @@
}
},
"node_modules/@yaakapp/api": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.5.0.tgz",
"integrity": "sha512-M0PPLGWQft+eQOOJ7ubwvRm3LTYXjAWQ8nniiqV3TkRcwa5++PteIH0OHV2L3Pei8cRQA8S25AD+RajyvFC8XQ==",
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.5.1.tgz",
"integrity": "sha512-0YFrrTJVjrnsSm9BTxSnz1pd1+Q52/CBV1QpTVtXPPqlSIwcvj7jMdwuDpSKy5G8xbaoVzTgBnW25RgKog/q7g==",
"dependencies": {
"@types/node": "^22.5.4"
}
@@ -1054,10 +1054,6 @@
"resolved": "plugins/importer-yaak",
"link": true
},
"node_modules/@yaakapp/template-function-file": {
"resolved": "plugins/template-function-file",
"link": true
},
"node_modules/@yaakapp/template-function-fs": {
"resolved": "plugins/template-function-fs",
"link": true
@@ -7196,7 +7192,8 @@
},
"plugins/template-function-file": {
"name": "@yaakapp/template-function-file",
"version": "0.0.1"
"version": "0.0.1",
"extraneous": true
},
"plugins/template-function-fs": {
"name": "@yaakapp/template-function-fs",
@@ -7225,6 +7222,11 @@
"devDependencies": {
"@types/jsonpath": "^0.2.4"
}
},
"plugins/template-function-secure": {
"name": "@yaakapp/template-function-secure",
"version": "0.0.1",
"extraneous": true
}
}
}

View File

@@ -19,6 +19,6 @@
"workspaces-run": "^1.0.2"
},
"dependencies": {
"@yaakapp/api": "^0.5.0"
"@yaakapp/api": "^0.5.1"
}
}

View File

@@ -101,7 +101,7 @@ function importEnvironment(e: any, workspaceId: string): ExportResources['enviro
createdAt: e.created ? new Date(e.created).toISOString().replace('Z', '') : undefined,
updatedAt: e.updated ? new Date(e.updated).toISOString().replace('Z', '') : undefined,
workspaceId: convertId(workspaceId),
environmentId: e.parentId === workspaceId ? null : convertId(e.parentId),
base: e.parentId === workspaceId,
model: 'environment',
name: e.name,
variables: Object.entries(e.data).map(([name, value]) => ({

View File

@@ -3,7 +3,7 @@
"environments": [
{
"createdAt": "2025-01-13T15:15:43.767",
"environmentId": null,
"base": true,
"id": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
"model": "environment",
"name": "Base Environment",
@@ -18,7 +18,7 @@
},
{
"createdAt": "2025-01-13T15:15:58.515",
"environmentId": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
"base": false,
"id": "GENERATE_ID::env_799ae3d723ef44af91b4817e5d057e6d",
"model": "environment",
"name": "Production",
@@ -33,7 +33,7 @@
},
{
"createdAt": "2025-01-13T15:16:14.707",
"environmentId": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
"base": false,
"id": "GENERATE_ID::env_030fbfdbb274426ebd78e2e6518f8553",
"model": "environment",
"name": "Staging",

View File

@@ -46,7 +46,7 @@ export function migrateImport(contents: string) {
parsed.resources.environments = parsed.resources.environments ?? [];
parsed.resources.environments.push(baseEnvironment);
// Delete variables key from workspace
// Delete variables key from the workspace
delete workspace.variables;
// Add environmentId to relevant environments
@@ -58,6 +58,14 @@ export function migrateImport(contents: string) {
}
}
// Migrate v3 to v4
for (const environment of parsed.resources.environments ?? []) {
if ('environmentId' in environment) {
environment.base = environment.environmentId == null;
delete environment.environmentId;
}
}
return { resources: parsed.resources }; // Should already be in the correct format
}

View File

@@ -53,7 +53,7 @@ describe('importer-yaak', () => {
}],
environments: [{
id: 'e_1',
environmentId: 'GENERATE_ID::base_env_w_1',
base: false,
workspaceId: 'w_1',
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],

View File

@@ -1,9 +0,0 @@
{
"name": "@yaakapp/template-function-file",
"private": true,
"version": "0.0.1",
"scripts": {
"build": "yaakcli build ./src/index.ts",
"dev": "yaakcli dev ./src/index.js"
}
}

View File

@@ -1,18 +0,0 @@
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
import fs from 'node:fs';
export const plugin: PluginDefinition = {
templateFunctions: [{
name: 'fs.readFile',
args: [{ title: 'Select File', type: 'file', name: 'path', label: 'File' }],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
if (!args.values.path) return null;
try {
return fs.promises.readFile(args.values.path, 'utf-8');
} catch (err) {
return null;
}
},
}],
};