Skip to content

SOF-7640: remove data source dependencies #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: chore/SOF-7644
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions dist/js/AdeFactory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { type ApplicationName } from "@exabyte-io/application-flavors.js";
import type { ApplicationSchemaBase } from "@mat3ra/esse/dist/js/types";
import Application from "./application";
import Executable from "./executable";
import Flavor from "./flavor";
import Template from "./template";
type ApplicationVersion = {
[build: string]: ApplicationSchemaBase;
};
type ApplicationTreeItem = {
defaultVersion: string;
[version: string]: ApplicationVersion | string;
};
export type CreateApplicationConfig = {
name: ApplicationName;
version?: string | null;
build?: string;
};
type ApplicationTree = Partial<Record<ApplicationName, ApplicationTreeItem>>;
export default class AdeFactory {
static applicationsTree?: ApplicationTree;
static applicationsArray?: ApplicationSchemaBase[];
static createApplication({ name, version, build }: CreateApplicationConfig): Application;
static getUniqueAvailableApplicationNames(): ApplicationName[];
/**
* @summary Return all applications as both a nested object of Applications and an array of config objects
* @returns containing applications and applicationConfigs
*/
static getAllApplications(): {
applicationsTree: Partial<Record<ApplicationName, ApplicationTreeItem>>;
applicationsArray: ApplicationSchemaBase[];
};
/**
* @summary Get an application from the constructed applications
* @param name name of the application
* @param version version of the application (optional, defaults to defaultVersion)
* @param build the build to use (optional, defaults to Default)
* @return an application
*/
static getApplicationConfig({ name, version, build, }: CreateApplicationConfig): ApplicationSchemaBase | null;
static getExecutables({ name, version }: {
name: ApplicationName;
version?: string;
}): Executable[];
static getExecutableByName(appName: ApplicationName, execName?: string): Executable;
static getExecutableByConfig(appName: ApplicationName, config?: {
name: string;
}): Executable;
static getExecutableFlavors(executable: Executable): Flavor[];
static getFlavorByName(executable: Executable, name?: string): Flavor | undefined;
static getFlavorByConfig(executable: Executable, config?: {
name: string;
}): Flavor | undefined;
static getInputAsTemplates(flavor: Flavor): Template[];
static getInputAsRenderedTemplates(flavor: Flavor, context: Record<string, unknown>): import("@mat3ra/esse/dist/js/esse/types").AnyObject[];
static getAllFlavorsForApplication(appName: ApplicationName, version?: string): Flavor[];
}
export {};
142 changes: 142 additions & 0 deletions dist/js/AdeFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const application_flavors_js_1 = require("@exabyte-io/application-flavors.js");
const object_1 = require("@mat3ra/code/dist/js/utils/object");
const application_1 = __importDefault(require("./application"));
const executable_1 = __importDefault(require("./executable"));
const flavor_1 = __importDefault(require("./flavor"));
const template_1 = __importDefault(require("./template"));
class AdeFactory {
static createApplication({ name, version = null, build = "Default" }) {
const staticConfig = AdeFactory.getApplicationConfig({ name, version, build });
return new application_1.default({ ...staticConfig, name, version, build });
}
static getUniqueAvailableApplicationNames() {
return application_flavors_js_1.allApplications;
}
/**
* @summary Return all applications as both a nested object of Applications and an array of config objects
* @returns containing applications and applicationConfigs
*/
static getAllApplications() {
if (this.applicationsTree && this.applicationsArray) {
return {
applicationsTree: this.applicationsTree,
applicationsArray: this.applicationsArray,
};
}
const applicationsTree = {};
const applicationsArray = [];
application_flavors_js_1.allApplications.forEach((appName) => {
const { versions, defaultVersion, build = "Default", ...appData } = (0, application_flavors_js_1.getAppData)(appName);
const appTreeItem = { defaultVersion };
versions.forEach((options) => {
const { version } = options;
const appVersion = version in appTreeItem && typeof appTreeItem[version] === "object"
? appTreeItem[version]
: {};
appTreeItem[version] = appVersion;
const applicationConfig = { ...appData, build, ...options };
appVersion[build] = applicationConfig;
applicationsArray.push(applicationConfig);
});
applicationsTree[appName] = appTreeItem;
});
this.applicationsTree = applicationsTree;
this.applicationsArray = applicationsArray;
return {
applicationsTree,
applicationsArray: this.applicationsArray,
};
}
/**
* @summary Get an application from the constructed applications
* @param name name of the application
* @param version version of the application (optional, defaults to defaultVersion)
* @param build the build to use (optional, defaults to Default)
* @return an application
*/
static getApplicationConfig({ name, version = null, build = "Default", }) {
var _a;
const { applicationsTree } = this.getAllApplications();
const app = applicationsTree[name];
if (!app) {
throw new Error(`Application ${name} not found`);
}
const version_ = version || app.defaultVersion;
const appVersion = app[version_];
if (!appVersion || typeof appVersion === "string") {
console.log(`Version ${version_} not available for ${name} !`);
}
if (typeof appVersion === "string") {
return null;
}
return (_a = appVersion[build]) !== null && _a !== void 0 ? _a : null;
}
static getExecutables({ name, version }) {
const tree = (0, application_flavors_js_1.getAppTree)(name);
return Object.keys(tree)
.filter((key) => {
const executable = tree[key];
const { supportedApplicationVersions } = executable;
return (!supportedApplicationVersions ||
(version && supportedApplicationVersions.includes(version)));
})
.map((key) => new executable_1.default({ ...tree[key], name: key }));
}
static getExecutableByName(appName, execName) {
const appTree = (0, application_flavors_js_1.getAppTree)(appName);
Object.entries(appTree).forEach(([name, exec]) => {
exec.name = name;
});
const config = execName
? appTree[execName]
: (0, object_1.getOneMatchFromObject)(appTree, "isDefault", true);
return new executable_1.default(config);
}
// TODO: remove this method and use getApplicationExecutableByName directly
static getExecutableByConfig(appName, config) {
return this.getExecutableByName(appName, config === null || config === void 0 ? void 0 : config.name);
}
static getExecutableFlavors(executable) {
const flavorsTree = executable.prop("flavors", {});
return Object.keys(flavorsTree).map((key) => {
return new flavor_1.default({
...flavorsTree[key],
name: key,
});
});
}
static getFlavorByName(executable, name) {
return this.getExecutableFlavors(executable).find((flavor) => name ? flavor.name === name : flavor.isDefault);
}
static getFlavorByConfig(executable, config) {
return this.getFlavorByName(executable, config === null || config === void 0 ? void 0 : config.name);
}
// flavors
static getInputAsTemplates(flavor) {
const appName = flavor.prop("applicationName", "");
const execName = flavor.prop("executableName", "");
return flavor.input.map((input) => {
const inputName = input.templateName || input.name;
const filtered = application_flavors_js_1.allTemplates.filter((temp) => temp.applicationName === appName &&
temp.executableName === execName &&
temp.name === inputName);
if (filtered.length !== 1) {
console.log(`found ${filtered.length} templates for app=${appName} exec=${execName} name=${inputName} expected 1`);
}
return new template_1.default({ ...filtered[0], name: input.name });
});
}
static getInputAsRenderedTemplates(flavor, context) {
return this.getInputAsTemplates(flavor).map((template) => template.getRenderedJSON(context));
}
static getAllFlavorsForApplication(appName, version) {
const allExecutables = this.getExecutables({ name: appName, version });
return allExecutables.flatMap((executable) => this.getExecutableFlavors(executable));
}
}
exports.default = AdeFactory;
18 changes: 18 additions & 0 deletions dist/js/ApplicationFlavorsFactory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Application from "./application";
import Executable from "./executable";
import Flavor from "./flavor";
import { type CreateApplicationConfig } from "./tree";
export declare class AdeFactory {
static createApplication({ name, version, build }: CreateApplicationConfig): Application;
static getApplicationExecutables(application: Application): Executable[];
static getApplicationExecutableByName(application: Application, name?: string): Executable;
static getApplicationExecutableByConfig(application: Application, config?: {
name: string;
}): Executable;
static getFlavorsByApplicationVersion(executable: Executable, version: string): Flavor[];
static getExecutableFlavors(executable: Executable): Flavor[];
static getFlavorByName(executable: Executable, name?: string): Flavor | undefined;
static getFlavorByConfig(executable: Executable, config?: {
name: string;
}): Flavor | undefined;
}
66 changes: 66 additions & 0 deletions dist/js/ApplicationFlavorsFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdeFactory = void 0;
const application_flavors_js_1 = require("@exabyte-io/application-flavors.js");
const object_1 = require("@mat3ra/code/dist/js/utils/object");
const application_1 = __importDefault(require("./application"));
const executable_1 = __importDefault(require("./executable"));
const flavor_1 = __importDefault(require("./flavor"));
class AdeFactory {
// applications
static createApplication({ name, version = null, build = "Default" }) {
return new application_1.default({ name, version, build });
}
static getApplicationExecutables(application) {
const tree = (0, application_flavors_js_1.getAppTree)(application.name);
return Object.keys(tree)
.filter((key) => {
const { supportedApplicationVersions } = tree[key];
return (!supportedApplicationVersions ||
supportedApplicationVersions.includes(application.version));
})
.map((key) => new executable_1.default({ ...tree[key], name: key }));
}
static getApplicationExecutableByName(application, name) {
const appTree = (0, application_flavors_js_1.getAppTree)(application.name);
Object.entries(appTree).forEach(([name, exec]) => {
exec.name = name;
});
const config = name
? appTree[name]
: (0, object_1.getOneMatchFromObject)(appTree, "isDefault", true);
return new executable_1.default(config);
}
// TODO: remove this method and use getApplicationExecutableByName directly
static getApplicationExecutableByConfig(application, config) {
return this.getApplicationExecutableByName(application, config === null || config === void 0 ? void 0 : config.name);
}
// executables
static getFlavorsByApplicationVersion(executable, version) {
const filteredFlavors = this.getExecutableFlavors(executable).filter((flavor) => {
const supportedApplicationVersions = flavor.prop("supportedApplicationVersions");
return !supportedApplicationVersions || supportedApplicationVersions.includes(version);
});
return filteredFlavors;
}
static getExecutableFlavors(executable) {
const flavorsTree = executable.prop("flavors", {});
return Object.keys(flavorsTree).map((key) => {
return new flavor_1.default({
...flavorsTree[key],
name: key,
executable,
});
});
}
static getFlavorByName(executable, name) {
return this.getExecutableFlavors(executable).find((flavor) => name ? flavor.name === name : flavor.isDefault);
}
static getFlavorByConfig(executable, config) {
return this.getFlavorByName(executable, config === null || config === void 0 ? void 0 : config.name);
}
}
exports.AdeFactory = AdeFactory;
2 changes: 0 additions & 2 deletions dist/js/application.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { NamedDefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity";
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
import { type ApplicationMixin } from "./applicationMixin";
import { type CreateApplicationConfig } from "./tree";
type Base = typeof NamedDefaultableInMemoryEntity & Constructor<ApplicationMixin>;
declare const Application_base: Base;
export default class Application extends Application_base {
constructor(config: CreateApplicationConfig);
}
export {};
5 changes: 0 additions & 5 deletions dist/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const entity_1 = require("@mat3ra/code/dist/js/entity");
const applicationMixin_1 = require("./applicationMixin");
const tree_1 = require("./tree");
class Application extends entity_1.NamedDefaultableInMemoryEntity {
constructor(config) {
const staticConfig = (0, tree_1.getApplicationConfig)(config);
super({ ...staticConfig, ...config });
}
}
exports.default = Application;
(0, applicationMixin_1.applicationMixin)(Application.prototype);
Expand Down
38 changes: 13 additions & 25 deletions dist/js/applicationMixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
import { type ApplicationName } from "@exabyte-io/application-flavors.js";
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import type { DefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/DefaultableMixin";
import type { NamedInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin";
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
import Executable from "./executable";
import { CreateApplicationConfig } from "./tree";
type Base = InMemoryEntity & NamedInMemoryEntity & DefaultableInMemoryEntity;
export declare function applicationMixin(item: Base): Base;
export type BaseConstructor = Constructor<Base> & {
constructCustomExecutable?: (config: object) => Executable;
};
export declare function applicationStaticMixin<T extends BaseConstructor>(Application: T): ApplicationStaticProperties;
export type ApplicationStaticProperties = {
defaultConfig: {
name: string;
shortName: string;
version: string;
summary: string;
build: string;
};
create: (config: CreateApplicationConfig) => Base;
createFromNameVersionBuild: (config: CreateApplicationConfig) => Base;
getUniqueAvailableNames: () => string[];
constructExecutable: (config: object) => Executable;
};
export type ApplicationConstructor = Constructor<ApplicationMixin> & ApplicationStaticProperties;
export type ApplicationConstructor = Constructor<ApplicationMixin> & ApplicationStaticMixin;
export type ApplicationMixin = {
defaultExecutable: Executable;
summary: string | undefined;
version: string;
build: string | undefined;
shortName: string;
executables: Executable[];
name: ApplicationName;
hasAdvancedComputeOptions: boolean;
isLicensed: boolean;
isUsingMaterial: boolean;
getExecutableByName: (name?: string) => Executable;
getExecutableByConfig: (config?: {
};
export type ApplicationStaticMixin = {
defaultConfig: {
name: string;
}) => Executable;
getExecutables: () => Executable[];
getBuilds: () => string[];
getVersions: () => string[];
shortName: string;
version: string;
summary: string;
build: string;
};
};
export declare function applicationMixin(item: Base): Base;
export declare function applicationStaticMixin<T extends BaseConstructor>(Application: T): ApplicationStaticMixin;
export {};
Loading