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

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;
}
},
}],
};