@voximplant/voxengine-ci
Version:
Manage Voximplant Platform `applications`, `rules` and `scenarios` from your own environment
84 lines (83 loc) • 4.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VoxApplicationPersistentRepository = void 0;
const node_path_1 = require("node:path");
const vox_application_entity_1 = require("../entities/vox-application.entity");
const abstract_persistent_repository_1 = require("./abstract.persistent.repository");
class VoxApplicationPersistentRepository extends abstract_persistent_repository_1.AbstractPersistentRepository {
constructor(context) {
super(context);
this.relativeStoragePath = 'applications';
this.basename = 'application.config';
this.metadataBasename = 'application.metadata.config';
this.create = async (voxApplication) => {
try {
const joinedPath = (0, node_path_1.join)(this.relativeStoragePath, voxApplication.applicationName);
await this.context.client.createFile(joinedPath, this.basename, JSON.stringify(voxApplication));
}
catch (error) {
console.error(this.lmg.generate('ERR__CREATE_FAILED', this.constructor.name));
console.error(error);
}
};
this.createMetadata = async (voxApplicationMetadata) => {
try {
const joinedPath = (0, node_path_1.join)(this.relativeStoragePath, voxApplicationMetadata.applicationName);
await this.context.client.createMetadataFile(joinedPath, this.metadataBasename, JSON.stringify(voxApplicationMetadata));
}
catch (error) {
console.error(this.lmg.generate('ERR__CREATE_METADATA_FAILED', this.constructor.name));
console.error(error);
}
};
this.createOrUpdate = async (voxApplication) => {
try {
const joinedPath = (0, node_path_1.join)(this.relativeStoragePath, voxApplication.applicationName);
await this.context.client.createOrUpdateFile(joinedPath, this.basename, JSON.stringify(voxApplication));
}
catch (error) {
console.error(this.lmg.generate('ERR__CREATE_OR_UPDATE_FAILED', this.constructor.name));
console.error(error);
}
};
this.createOrUpdateMetadata = async (voxApplicationMetadata) => {
try {
const joinedPath = (0, node_path_1.join)(this.relativeStoragePath, voxApplicationMetadata.applicationName);
await this.context.client.createOrUpdateFile(joinedPath, this.metadataBasename, JSON.stringify(voxApplicationMetadata));
}
catch (error) {
console.error(this.lmg.generate('ERR__CREATE_OR_UPDATE_METADATA_FAILED', this.constructor.name));
console.error(error);
}
};
this.read = async (applicationName) => {
try {
const joinedPath = (0, node_path_1.join)(this.relativeStoragePath, applicationName, this.basename);
const rawData = await this.context.client.readFile(joinedPath);
if (!rawData)
return;
const rawApplication = (JSON.parse(rawData));
return new vox_application_entity_1.VoxApplication(rawApplication);
}
catch (error) {
console.error(this.lmg.generate('ERR__READ_FAILED', this.constructor.name));
console.error(error);
}
};
this.readMetadata = async (applicationName) => {
try {
const joinedPath = (0, node_path_1.join)(this.relativeStoragePath, applicationName, this.metadataBasename);
const rawData = await this.context.client.readMetadataFile(joinedPath);
if (!rawData)
return;
const rawApplicationMetadata = (JSON.parse(rawData));
return new vox_application_entity_1.VoxApplicationMetadata(rawApplicationMetadata);
}
catch (error) {
console.error(this.lmg.generate('ERR__READ_METADATA_FAILED', this.constructor.name));
console.error(error);
}
};
}
}
exports.VoxApplicationPersistentRepository = VoxApplicationPersistentRepository;