Skip to content

Commit

Permalink
TA-3148: Update NodeExportTransport and export/import logic to work w…
Browse files Browse the repository at this point in the history
…ith JSON files
  • Loading branch information
Buqeta committed Jul 17, 2024
1 parent 44e9966 commit 0aca1bb
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/content/factory/widget-manager.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";
import { FatalError, logger } from "../../util/logger";
import { WidgetManager } from "../manager/widget.manager";
import * as AdmZip from "adm-zip";
import {parse} from "../../util/yaml";
import {parse} from "../../util/json";

interface Manifest {
key: string;
Expand Down
2 changes: 1 addition & 1 deletion src/content/manager/analysis.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseManager } from "./base.manager";
import { ManagerConfig } from "../../interfaces/manager-config.interface";
import { AssetManager } from "./asset.manager";
import * as fs from "fs";
import {stringify} from "../../util/yaml";
import {stringify} from "../../util/json";
import * as FormData from "form-data";

export class AnalysisManager extends BaseManager {
Expand Down
2 changes: 1 addition & 1 deletion src/content/manager/asset.manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseManager } from "./base.manager";
import { ManagerConfig } from "../../interfaces/manager-config.interface";
import { SaveContentNode } from "../../interfaces/save-content-node.interface";
import { parse, stringify } from "../../util/yaml";
import { parse, stringify } from "../../util/json";

export class AssetManager extends BaseManager {
public static ASSET_FILE_PREFIX = "asset_";
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/batch-export-import-constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export enum BatchExportImportConstants {
STUDIO_FILE_NAME = "studio.yml",
VARIABLES_FILE_NAME = "variables.yml",
MANIFEST_FILE_NAME = "manifest.yml",
STUDIO_FILE_NAME = "studio.json",
VARIABLES_FILE_NAME = "variables.json",
MANIFEST_FILE_NAME = "manifest.json",
STUDIO = "STUDIO",
APP_MODE_VIEWER = "VIEWER",
ZIP_EXTENSION = ".zip",
YAML_EXTENSION = ".yml",
JSON_EXTENSION = ".json",
NODES_FOLDER_NAME = "nodes/",
SCENARIO_NODE = "SCENARIO"
}
6 changes: 3 additions & 3 deletions src/interfaces/package-export-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface NodeExportTransport {
name: string;
type: string;
exportSerializationType: string;
configuration: string;
configuration: NodeConfiguration;
schemaVersion: number;

spaceId: string;
Expand All @@ -60,8 +60,8 @@ export interface NodeExportTransport {
serializedDocument?: Buffer;
}

export interface NodeSerializedContent {
variables: VariableDefinition[]
export interface NodeConfiguration {
[key: string]: any;
}

export interface StudioPackageManifest {
Expand Down
2 changes: 1 addition & 1 deletion src/services/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import { ManifestNodeTransport } from "../interfaces/manifest-transport";
import { FatalError, logger } from "../util/logger";
import {parse} from "../util/yaml";
import {parse} from "../util/json";

export class FileService {
public static readonly fileDownloadedMessage = "File downloaded successfully. New filename: ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "../../interfaces/package-export-transport";
import {FileService, fileService} from "../file-service";
import {studioService} from "../studio/studio.service";
import {parse, stringify} from "../../util/yaml"
import {parse, stringify} from "../../util/json"
import * as FormData from "form-data";
import {BatchExportImportConstants} from "../../interfaces/batch-export-import-constants";
import {packageApi} from "../../api/package-api";
Expand Down
2 changes: 1 addition & 1 deletion src/services/package-manager/package-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {SpaceTransport} from "../../interfaces/save-space.interface";
import {ManifestDependency, ManifestNodeTransport} from "../../interfaces/manifest-transport";
import {DataPoolInstallVersionReport} from "../../interfaces/data-pool-manager.interfaces";
import {SemanticVersioning} from "../../util/semantic-versioning"
import {stringify} from "../../util/yaml";
import {stringify} from "../../util/json";
import * as FormData from "form-data";

class PackageService {
Expand Down
16 changes: 8 additions & 8 deletions src/services/studio/studio.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
NodeConfiguration,
NodeExportTransport,
NodeSerializedContent,
PackageExportTransport,
PackageKeyAndVersionPair,
StudioPackageManifest,
VariableExportTransport,
VariableManifestTransport
VariableManifestTransport,
} from "../../interfaces/package-export-transport";

import {packageApi} from "../../api/package-api";
Expand All @@ -17,7 +17,7 @@ import {
} from "../../interfaces/package-manager.interfaces";
import {dataModelService} from "../package-manager/datamodel-service";
import {IZipEntry} from "adm-zip";
import {parse, stringify} from "../../util/yaml";
import {parse, stringify} from "../../util/json";
import {nodeApi} from "../../api/node-api";
import {variablesApi} from "../../api/variables-api";
import {spaceApi} from "../../api/space-api";
Expand Down Expand Up @@ -140,7 +140,7 @@ class StudioService {
}

private deleteScenarioAssets(packageZip: AdmZip): void {
packageZip.getEntries().filter(entry => entry.entryName.startsWith(BatchExportImportConstants.NODES_FOLDER_NAME) && entry.entryName.endsWith(BatchExportImportConstants.YAML_EXTENSION))
packageZip.getEntries().filter(entry => entry.entryName.startsWith(BatchExportImportConstants.NODES_FOLDER_NAME) && entry.entryName.endsWith(BatchExportImportConstants.JSON_EXTENSION))
.forEach(entry => {
const node: NodeExportTransport = parse(entry.getData().toString());
if (node.type === BatchExportImportConstants.SCENARIO_NODE) {
Expand All @@ -157,18 +157,18 @@ class StudioService {
return;
}

const packageEntry = packageZip.getEntry("package.yml");
const packageEntry = packageZip.getEntry("package.json");

const exportedNode: NodeExportTransport = parse(packageEntry.getData().toString());
const nodeContent: NodeSerializedContent = parse(exportedNode.configuration);
const nodeContent: NodeConfiguration = exportedNode.configuration;

nodeContent.variables = nodeContent.variables.map(variable => ({
...variable,
metadata: variable.type === PackageManagerVariableType.CONNECTION ?
connectionVariablesByKey.get(variable.key).metadata : variable.metadata
}));

exportedNode.configuration = stringify(nodeContent);
exportedNode.configuration = nodeContent;
packageZip.updateFile(packageEntry, Buffer.from(stringify(exportedNode)));
}

Expand Down Expand Up @@ -212,7 +212,7 @@ class StudioService {

const packageZip = new AdmZip(file.getData());
packageZip.getEntries().forEach(nodeFile => {
if (nodeFile.entryName.endsWith(BatchExportImportConstants.YAML_EXTENSION)) {
if (nodeFile.entryName.endsWith(BatchExportImportConstants.JSON_EXTENSION)) {
const updatedNodeFile = this.updateSpaceIdForNode(nodeFile.getData().toString(), spaceId);
packageZip.updateFile(nodeFile, Buffer.from(updatedNodeFile));
}
Expand Down
15 changes: 15 additions & 0 deletions src/util/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export function stringify(data: any): string {
return JSON.stringify(data, replacer, 2);
}

export function parse<T>(data: string): T {
return JSON.parse(data);
}

const replacer = (key, value) => {
if (value instanceof Map) {
return Object.fromEntries(value);
}
return value;
};
9 changes: 0 additions & 9 deletions src/util/yaml.ts

This file was deleted.

9 changes: 4 additions & 5 deletions tests/config/config-diff.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {PackageManifestTransport} from "../../src/interfaces/package-export-transport";
import {ConfigUtils} from "../utls/config-utils";
import * as path from "path";
import {stringify} from "../../src/util/yaml";
import {mockCreateReadStream, mockExistsSync, mockReadFileSync} from "../utls/fs-mock-utils";
import {
PackageDiffMetadata,
Expand All @@ -22,7 +21,7 @@ describe("Config diff", () => {
const manifest: PackageManifestTransport[] = [];
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO"));

const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []}));
const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []});
const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST");
const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0");
const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]);
Expand All @@ -49,7 +48,7 @@ describe("Config diff", () => {
const manifest: PackageManifestTransport[] = [];
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO"));

const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []}));
const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []});
const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST");
const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0");
const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]);
Expand Down Expand Up @@ -91,7 +90,7 @@ describe("Config diff", () => {
const manifest: PackageManifestTransport[] = [];
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO"));

const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []}));
const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []});
const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST");
const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0");
const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]);
Expand Down Expand Up @@ -137,7 +136,7 @@ describe("Config diff", () => {
const manifest: PackageManifestTransport[] = [];
manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO"));

const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []}));
const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []});
const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST");
const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0");
const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]);
Expand Down
Loading

0 comments on commit 0aca1bb

Please sign in to comment.