Skip to content

Commit

Permalink
feat: initial ts
Browse files Browse the repository at this point in the history
  • Loading branch information
seankwarren committed Feb 6, 2024
1 parent 376116a commit 017418a
Show file tree
Hide file tree
Showing 15 changed files with 552 additions and 510 deletions.
132 changes: 0 additions & 132 deletions src/application.js

This file was deleted.

147 changes: 147 additions & 0 deletions src/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { allApplications, getAppData, getAppTree } from "@exabyte-io/application-flavors.js";
import { NamedDefaultableHashedInMemoryEntity } from "@exabyte-io/code.js/dist/entity";
import lodash from "lodash";

import { Executable } from "./executable";
import { getApplicationConfig, getExecutableConfig } from "./tree";

export type ApplicationConfig = {
name: string;
version?: string;
build?: string;
};

type ApplicationBaseEntity = InstanceType<typeof NamedDefaultableHashedInMemoryEntity>;

export type ApplicationBaseEntityConstructor<T extends ApplicationBaseEntity = ApplicationBaseEntity> = new (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
) => T;

export function ApplicationMixin<
T extends ApplicationBaseEntityConstructor = ApplicationBaseEntityConstructor,
>(superclass: T) {
return class extends superclass {
static Executable = Executable;

constructor(...config: any[]) {
const staticConfig = getApplicationConfig(config);
super({ ...staticConfig, ...config });
}

// TODO: extract this from application-flavors "global" default config for espresso 5.4.0
static get defaultConfig() {
return {
name: "espresso",
shortName: "qe",
version: "6.3",
summary: "Quantum Espresso",
build: "Default",
};
}

static create(config) {
return this.createFromNameVersionBuild(config);
}

static createFromNameVersionBuild({ name, version = null, build = "Default" }: {name: string, version?: string | null, build?: string}) {
return new Application({ name, version, build });
}

getExecutables() {
return this.executables;
}

getBuilds() {
const data = getAppData(this.prop("name"));
const { versions } = data;
const builds = ["Default"];
versions.map((v) => v.build && builds.push(v.build));
return lodash.uniq(builds);
}

getVersions() {
const data = getAppData(this.prop("name"));
const { versions } = data;
const these: string[] = versions.map((v) => v.version);
return lodash.uniq(these);
}

static getUniqueAvailableNames() {
return allApplications;
}

getExecutableByName(name: string | null = null) {
return new Application.Executable(
getExecutableConfig({
appName: this.prop("name"),
execName: name,
}),
);
}

getExecutableByConfig(config: {name: string} | null | undefined = null) {
return config ? this.getExecutableByName(config.name) : this.defaultExecutable;
}

get defaultExecutable() {
return this.getExecutableByName();
}

// override upon inheritance
// eslint-disable-next-line class-methods-use-this
get allowedModelTypes() {
return [];
}

get summary() {
return this.prop("summary");
}

get version() {
return this.prop("version");
}

get build() {
return this.prop("build");
}

get shortName() {
return this.prop("shortName", this.prop("name"));
}

get executables() {
const tree = getAppTree(this.prop("name"));
return Object.keys(tree)
.filter((key) => {
const { supportedApplicationVersions } = tree[key];
return (
!supportedApplicationVersions ||
supportedApplicationVersions.includes(this.prop("version"))
);
})
.map((key) => {
return new Application.Executable({ ...tree[key], name: key });
});
}

get hasAdvancedComputeOptions() {
return this.prop("hasAdvancedComputeOptions");
}

get isLicensed() {
return this.prop("isLicensed");
}

get isUsingMaterial() {
const materialUsingApplications = ["vasp", "nwchem", "espresso", "exabyteml"];
return materialUsingApplications.includes(this.name);
}
}
}

export const Application = ApplicationMixin(
NamedDefaultableHashedInMemoryEntity,
);

export type Application = InstanceType<typeof Application>;
File renamed without changes.
File renamed without changes.
80 changes: 0 additions & 80 deletions src/context/providers/nwchem/providers.js

This file was deleted.

Loading

0 comments on commit 017418a

Please sign in to comment.