Skip to content

Commit

Permalink
feat: types improved
Browse files Browse the repository at this point in the history
  • Loading branch information
seankwarren committed Feb 7, 2024
1 parent 017418a commit 37d4d92
Show file tree
Hide file tree
Showing 14 changed files with 779 additions and 338 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"extends": ["@exabyte-io/eslint-config"]
"extends": ["@exabyte-io/eslint-config"],
"ignorePatterns": ["dist/"],
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}

535 changes: 434 additions & 101 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 21 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"version": "0.0.0",
"description": "Application DEfinitions",
"scripts": {
"prepublishOnly": "rm -rf lib; npm run transpile",
"transpile": "tsc",
"postinstall": "npm run transpile",
"test": "nyc --reporter=text mocha --recursive --bail --require @babel/register/lib --require tests/setup.js tests",
"lint": "eslint src tests && prettier --write src tests",
"lint:fix": "eslint --fix --cache src tests && prettier --write src tests",
"transpile": "babel --out-dir dist src",
"postinstall": "npm run transpile",
"prettier": "prettier --check src tests",
"prepare": "husky install"
},
Expand All @@ -16,11 +17,6 @@
"url": "https://github.com/Exabyte-io/ade.js.git"
},
"main": "dist/index.js",
"files": [
"/dist",
"/src",
".babelrc"
],
"author": "Exabyte Inc.",
"bugs": {
"url": "https://github.com/Exabyte-io/ade.js/issues"
Expand All @@ -30,24 +26,32 @@
"dependencies": {
"@babel/cli": "7.16.0",
"@babel/core": "7.16.0",
"@babel/eslint-parser": "7.16.3",
"@babel/plugin-proposal-class-properties": "7.16.0",
"@babel/preset-env": "7.16.4",
"@babel/preset-react": "7.16.7",
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8",
"@exabyte-io/periodic-table.js": "2022.6.8-0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.2",
"@types/underscore": "^1.11.6",
"@types/underscore.string": "^0.0.40",
"lodash": "^4.17.21",
"mixwith": "^0.1.1",
"swig": "^1.4.2",
"typescript": "^5.3.3",
"underscore": "^1.13.3",
"underscore.string": "^3.3.4"
},
"devDependencies": {
"@exabyte-io/code.js": "https://github.com/Exabyte-io/code.js.git#87c1ddfd731798de978e6c579efad44d5738ac6a",
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/made.js": "2022.6.15-0",
"@babel/eslint-parser": "7.16.3",
"@babel/plugin-proposal-class-properties": "7.16.0",
"@babel/preset-env": "7.16.4",
"@babel/preset-react": "7.16.7",
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8",
"@exabyte-io/application-flavors.js": "2024.1.23-1",
"@exabyte-io/code.js": "https://github.com/Exabyte-io/code.js.git#20d456ad83bd59b5a075bc499513fd076f46c6ce",
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/made.js": "^2024.1.8-0",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"chai": "^4.3.4",
"eslint": "7.32.0",
"eslint-config-airbnb": "19.0.2",
Expand All @@ -65,7 +69,7 @@
"prettier": "^2.7.1"
},
"peerDependencies": {
"@exabyte-io/code.js": "https://github.com/Exabyte-io/code.js.git#87c1ddfd731798de978e6c579efad44d5738ac6a",
"@exabyte-io/code.js": "*",
"@exabyte-io/made.js": "*",
"@exabyte-io/application-flavors.js": "*"
},
Expand Down
60 changes: 33 additions & 27 deletions src/application.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
// @ts-ignore
import { allApplications, getAppData, getAppTree } from "@exabyte-io/application-flavors.js";
import { NamedDefaultableHashedInMemoryEntity } from "@exabyte-io/code.js/dist/entity";
import { type Constructor } from "@exabyte-io/code.js/dist/context";

import lodash from "lodash";

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

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;
type ApplicationBase = InstanceType<typeof NamedDefaultableHashedInMemoryEntity>;

// @ts-ignore
export function ApplicationMixin<

Check failure on line 15 in src/application.ts

View workflow job for this annotation

GitHub Actions / run-js-tests (14.x)

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Check failure on line 15 in src/application.ts

View workflow job for this annotation

GitHub Actions / run-js-tests (16.x)

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Check failure on line 15 in src/application.ts

View workflow job for this annotation

GitHub Actions / run-js-tests (18.x)

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
T extends ApplicationBaseEntityConstructor = ApplicationBaseEntityConstructor,
T extends Constructor<ApplicationBase> = Constructor<ApplicationBase>
>(superclass: T) {
return class extends superclass {
return class AdeApplication extends superclass {
static Executable = Executable;

constructor(...config: any[]) {
constructor(...args: any[]) {
const config = args[0] as ApplicationConfig;
if (!config || typeof config.name !== "string") throw new Error("Invalid application configuration object.");
const staticConfig = getApplicationConfig(config);
if (!staticConfig) throw new Error(`Application "${config.name} (${config.version}-${config.build})" is not supported.`);
super({ ...staticConfig, ...config });
}

Expand All @@ -40,28 +37,40 @@ export function ApplicationMixin<
};
}

static create(config) {
static create(config: {
name: string,
version?: string,
build?: string
}) {
return this.createFromNameVersionBuild(config);
}

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

getExecutables() {
return this.executables;
}

getBuilds() {
const data = getAppData(this.prop("name"));
const data = getAppData(this.prop("name")) as ApplicationData;
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 data = getAppData(this.prop("name")) as ApplicationData;
const { versions } = data;
const these: string[] = versions.map((v) => v.version);
return lodash.uniq(these);
Expand All @@ -71,8 +80,8 @@ export function ApplicationMixin<
return allApplications;
}

getExecutableByName(name: string | null = null) {
return new Application.Executable(
getExecutableByName(name?: string) {
return new AdeApplication.Executable(
getExecutableConfig({
appName: this.prop("name"),
execName: name,
Expand Down Expand Up @@ -121,7 +130,7 @@ export function ApplicationMixin<
);
})
.map((key) => {
return new Application.Executable({ ...tree[key], name: key });
return new AdeApplication.Executable({ ...tree[key], name: key });
});
}

Expand All @@ -140,8 +149,5 @@ export function ApplicationMixin<
}
}

export const Application = ApplicationMixin(
NamedDefaultableHashedInMemoryEntity,
);

export const Application = ApplicationMixin(NamedDefaultableHashedInMemoryEntity);

Check failure on line 152 in src/application.ts

View workflow job for this annotation

GitHub Actions / run-js-tests (14.x)

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Check failure on line 152 in src/application.ts

View workflow job for this annotation

GitHub Actions / run-js-tests (16.x)

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Check failure on line 152 in src/application.ts

View workflow job for this annotation

GitHub Actions / run-js-tests (18.x)

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
export type Application = InstanceType<typeof Application>;
3 changes: 2 additions & 1 deletion src/context/providers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ContextProvider } from "@exabyte-io/code.js/dist/context";
import { ContextProviderConfig } from "@exabyte-io/code.js/dist/context/provider";

export class ExecutableContextProvider extends ContextProvider {
constructor(config) {
constructor(config: ContextProviderConfig) {
super({
...config,
domain: "executable",
Expand Down
80 changes: 80 additions & 0 deletions src/context/providers/nwchem/providers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
JobContextMixin,
MaterialContextMixin,
MethodDataContextMixin,
WorkflowContextMixin,
} from "@exabyte-io/code.js/dist/context";
import { Made } from "@exabyte-io/made.js";
import { PERIODIC_TABLE } from "@exabyte-io/periodic-table.js";
import lodash from "lodash";
import { mix } from "mixwith";
import _ from "underscore";
import s from "underscore.string";

import { ExecutableContextProvider } from "../../providers.ts";

export class NWChemTotalEnergyContextProvider extends mix(ExecutableContextProvider).with(
MaterialContextMixin,
MethodDataContextMixin,
WorkflowContextMixin,
JobContextMixin,
) {
static Material = Made.Material;

get atomSymbols() {
return this.material.Basis.uniqueElements;
}

get atomicPositionsWithoutConstraints() {
return this.material.Basis.atomicPositions;
}

get atomicPositions() {
return this.material.Basis.atomicPositionsWithConstraints;
}

get cartesianAtomicPositions() {
return this.material.toCartesian();
}

/*
* @NOTE: Overriding getData makes this provider "stateless", ie. delivering data from scratch each time and not
* considering the content of `this.data`, and `this.isEdited` field(s).
*/
getData() {
/*
TODO: Create ability for user to define CHARGE, MULT, BASIS and FUNCTIONAL parameters.
*/
const CHARGE = 0;
const MULT = 1;
const BASIS = "6-31G";
const FUNCTIONAL = "B3LYP";

return {
CHARGE,
MULT,
BASIS,
NAT: this.atomicPositions.length,
NTYP: this.atomSymbols.length,
ATOMIC_POSITIONS: this.atomicPositions.join("\n"),
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: this.atomicPositionsWithoutConstraints.join("\n"),
ATOMIC_SPECIES: this.ATOMIC_SPECIES,
FUNCTIONAL,
CARTESIAN: this.cartesianAtomicPositions,
};
}

get ATOMIC_SPECIES() {
return _.map(this.atomSymbols, (symbol) => {
return NWChemTotalEnergyContextProvider.symbolToAtomicSpecies(symbol);
}).join("\n");
}

static symbolToAtomicSpecies(symbol, pseudo) {
const el = PERIODIC_TABLE[symbol];
const filename = pseudo
? lodash.get(pseudo, "filename", s.strRightBack(pseudo.path, "/"))
: "";
return el ? s.sprintf("%s %f %s", symbol, el.atomic_mass, filename) : undefined;
}
}
80 changes: 0 additions & 80 deletions src/context/providers/nwchem/providers.ts

This file was deleted.

Loading

0 comments on commit 37d4d92

Please sign in to comment.