@mat3ra/ade 2025.10.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.babelrc +17 -0
  2. package/LICENSE.md +15 -0
  3. package/README.md +106 -0
  4. package/dist/js/ApplicationRegistry.d.ts +57 -0
  5. package/dist/js/ApplicationRegistry.js +171 -0
  6. package/dist/js/application.d.ts +8 -0
  7. package/dist/js/application.js +9 -0
  8. package/dist/js/applicationMixin.d.ts +23 -0
  9. package/dist/js/applicationMixin.js +48 -0
  10. package/dist/js/context/ContextProvider.d.ts +83 -0
  11. package/dist/js/context/ContextProvider.js +139 -0
  12. package/dist/js/context/ContextProviderRegistryContainer.d.ts +24 -0
  13. package/dist/js/context/ContextProviderRegistryContainer.js +30 -0
  14. package/dist/js/context/JSONSchemaFormDataProvider.d.ts +25 -0
  15. package/dist/js/context/JSONSchemaFormDataProvider.js +46 -0
  16. package/dist/js/executable.d.ts +8 -0
  17. package/dist/js/executable.js +12 -0
  18. package/dist/js/executableMixin.d.ts +22 -0
  19. package/dist/js/executableMixin.js +28 -0
  20. package/dist/js/flavor.d.ts +9 -0
  21. package/dist/js/flavor.js +12 -0
  22. package/dist/js/flavorMixin.d.ts +21 -0
  23. package/dist/js/flavorMixin.js +51 -0
  24. package/dist/js/index.d.ts +5 -0
  25. package/dist/js/index.js +14 -0
  26. package/dist/js/template.d.ts +8 -0
  27. package/dist/js/template.js +10 -0
  28. package/dist/js/templateMixin.d.ts +39 -0
  29. package/dist/js/templateMixin.js +162 -0
  30. package/package.json +88 -0
  31. package/src/js/ApplicationRegistry.ts +250 -0
  32. package/src/js/application.ts +18 -0
  33. package/src/js/applicationMixin.ts +86 -0
  34. package/src/js/context/ContextProvider.ts +189 -0
  35. package/src/js/context/ContextProviderRegistryContainer.ts +41 -0
  36. package/src/js/context/JSONSchemaFormDataProvider.ts +57 -0
  37. package/src/js/executable.ts +14 -0
  38. package/src/js/executableMixin.ts +49 -0
  39. package/src/js/flavor.ts +19 -0
  40. package/src/js/flavorMixin.ts +77 -0
  41. package/src/js/index.ts +6 -0
  42. package/src/js/template.ts +17 -0
  43. package/src/js/templateMixin.ts +242 -0
  44. package/tsconfig.json +3 -0
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.templateMixin = templateMixin;
7
+ exports.templateStaticMixin = templateStaticMixin;
8
+ const utils_1 = require("@mat3ra/utils");
9
+ const JSONSchemasInterface_1 = __importDefault(require("@mat3ra/esse/dist/js/esse/JSONSchemasInterface"));
10
+ const nunjucks_1 = __importDefault(require("nunjucks"));
11
+ const ContextProviderRegistryContainer_1 = __importDefault(require("./context/ContextProviderRegistryContainer"));
12
+ function templateMixin(item) {
13
+ // @ts-ignore
14
+ const properties = {
15
+ get isManuallyChanged() {
16
+ return this.prop("isManuallyChanged", false);
17
+ },
18
+ get content() {
19
+ return this.prop("content", "");
20
+ },
21
+ setContent(text) {
22
+ return this.setProp("content", text);
23
+ },
24
+ get rendered() {
25
+ return this.prop("rendered") || this.content;
26
+ },
27
+ setRendered(text) {
28
+ return this.setProp("rendered", text);
29
+ },
30
+ get applicationName() {
31
+ return this.prop("applicationName");
32
+ },
33
+ get executableName() {
34
+ return this.prop("executableName");
35
+ },
36
+ get contextProviders() {
37
+ return this.prop("contextProviders", []);
38
+ },
39
+ addContextProvider(provider) {
40
+ this.setProp("contextProviders", [...this.contextProviders, provider]);
41
+ },
42
+ removeContextProvider(provider) {
43
+ const contextProviders = this.contextProviders.filter((p) => {
44
+ return p.name !== provider.name && p.domain !== provider.domain;
45
+ });
46
+ this.setProp("contextProviders", contextProviders);
47
+ },
48
+ render(externalContext) {
49
+ const renderingContext = this.getRenderingContext(externalContext);
50
+ if (!this.isManuallyChanged) {
51
+ try {
52
+ const template = nunjucks_1.default.compile(this.content);
53
+ // deepClone to pass JSON data without classes
54
+ const rendered = template.render(this._cleanRenderingContext(renderingContext));
55
+ this.setRendered(this.isManuallyChanged ? rendered : rendered || this.content);
56
+ }
57
+ catch (e) {
58
+ console.log(`Template is not compiled: ${e}`);
59
+ console.log({
60
+ content: this.content,
61
+ _cleanRenderingContext: this._cleanRenderingContext(renderingContext),
62
+ });
63
+ }
64
+ }
65
+ },
66
+ getRenderedJSON(context) {
67
+ this.render(context);
68
+ return this.toJSON();
69
+ },
70
+ // Remove "bulky" items and JSON stringify before passing it to rendering engine (eg. jinja) to compile.
71
+ // This way the context should still be passed in full to contextProviders, but not to final text template.
72
+ // eslint-disable-next-line class-methods-use-this
73
+ _cleanRenderingContext(object) {
74
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
+ const { job, ...clone } = object;
76
+ return utils_1.Utils.clone.deepClone(clone);
77
+ },
78
+ /*
79
+ * @summary Initializes context provider class instances. `providerContext` is used to pass the data about any
80
+ * previously stored values. That is if data was previously saved in database, the context provider
81
+ * shall receive it on initialization through providerContext and prioritize this value over the default.
82
+ */
83
+ getContextProvidersAsClassInstances(providerContext) {
84
+ return this.contextProviders.map((p) => {
85
+ var _a;
86
+ const providerInstance = (_a = this.constructor.contextProviderRegistry) === null || _a === void 0 ? void 0 : _a.findProviderInstanceByName(p.name);
87
+ if (!providerInstance) {
88
+ throw new Error(`Provider ${p.name} not found`);
89
+ }
90
+ const clsInstance = new providerInstance.constructor({
91
+ ...providerInstance.config,
92
+ context: providerContext,
93
+ });
94
+ return clsInstance;
95
+ });
96
+ },
97
+ /*
98
+ * @summary Extracts the the data from all context providers for further use during render.
99
+ */
100
+ getDataFromProvidersForRenderingContext(providerContext) {
101
+ const result = {};
102
+ this.getContextProvidersAsClassInstances(providerContext).forEach((contextProvider) => {
103
+ const context = contextProvider.yieldDataForRendering();
104
+ Object.keys(context).forEach((key) => {
105
+ // merge context keys if they are objects otherwise override them.
106
+ result[key] =
107
+ result[key] !== null && typeof result[key] === "object"
108
+ ? // @ts-ignore
109
+ { ...result[key], ...context[key] }
110
+ : context[key];
111
+ });
112
+ });
113
+ return result;
114
+ },
115
+ /*
116
+ * @summary Extracts the the data from all context providers for further save in persistent context.
117
+ */
118
+ // TODO: optimize logic to prevent re-initializing the context provider classes again below, reuse above function
119
+ getDataFromProvidersForPersistentContext(providerContext) {
120
+ const result = {};
121
+ this.getContextProvidersAsClassInstances(providerContext).forEach((contextProvider) => {
122
+ // only save in the persistent context the data from providers that were edited (or able to be edited)
123
+ Object.assign(result, contextProvider.isEdited ? contextProvider.yieldData() : {});
124
+ });
125
+ return result;
126
+ },
127
+ /*
128
+ * @summary Combines rendering context (in order of preference):
129
+ * - context from templates initialized with external context
130
+ * - "external" context and
131
+ */
132
+ getRenderingContext(externalContext) {
133
+ return {
134
+ ...externalContext,
135
+ ...this.getDataFromProvidersForRenderingContext(externalContext),
136
+ };
137
+ },
138
+ };
139
+ Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
140
+ return properties;
141
+ }
142
+ function templateStaticMixin(item) {
143
+ // @ts-ignore
144
+ const properties = {
145
+ contextProviderRegistry: null,
146
+ get jsonSchema() {
147
+ return JSONSchemasInterface_1.default.getSchemaById("software/template");
148
+ },
149
+ setContextProvidersConfig(classConfigMap) {
150
+ const contextProviderRegistry = new ContextProviderRegistryContainer_1.default();
151
+ Object.entries(classConfigMap).forEach(([name, { providerCls, config }]) => {
152
+ contextProviderRegistry.addProvider({
153
+ instance: providerCls.getConstructorConfig(config),
154
+ name,
155
+ });
156
+ });
157
+ this.contextProviderRegistry = contextProviderRegistry;
158
+ },
159
+ };
160
+ Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
161
+ return properties;
162
+ }
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@mat3ra/ade",
3
+ "version": "2025.10.2-0",
4
+ "description": "Application DEfinitions",
5
+ "scripts": {
6
+ "test": "nyc --reporter=text mocha --recursive --bail tests/js/**/*.ts",
7
+ "test:coverage": "nyc --reporter=text --reporter=html --reporter=lcov mocha --recursive --bail tests/js/**/*.ts",
8
+ "test:coverage:html": "nyc --reporter=html mocha --recursive --bail tests/js/**/*.ts",
9
+ "test:coverage:check": "nyc --reporter=text --check-coverage mocha --recursive --bail tests/js/**/*.ts",
10
+ "test:coverage:view": "node scripts/view-coverage.js",
11
+ "lint": "eslint src tests && prettier --write src tests",
12
+ "lint:fix": "eslint --fix --cache src tests && prettier --write src tests",
13
+ "transpile": "tsc -p tsconfig-transpile.json",
14
+ "prettier": "prettier --check src tests",
15
+ "prepare": "husky install"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/Exabyte-io/ade.git"
20
+ },
21
+ "main": "dist/js/index.js",
22
+ "files": [
23
+ "/dist",
24
+ "/src/js",
25
+ ".babelrc",
26
+ "tsconfig.json"
27
+ ],
28
+ "author": "Exabyte Inc.",
29
+ "bugs": {
30
+ "url": "https://github.com/Exabyte-io/ade/issues"
31
+ },
32
+ "license": "Apache-2.0",
33
+ "homepage": "https://github.com/Exabyte-io/ade",
34
+ "dependencies": {
35
+ "@types/react-jsonschema-form": "^1.7.13",
36
+ "lodash": "^4.17.21",
37
+ "nunjucks": "^3.2.4",
38
+ "react-jsonschema-form": "^1.8.1"
39
+ },
40
+ "devDependencies": {
41
+ "@babel/eslint-parser": "^7.16.3",
42
+ "@exabyte-io/eslint-config": "2025.5.13-0",
43
+ "@mat3ra/utils": "2025.9.20-0",
44
+ "@mat3ra/code": "2025.8.7-0",
45
+ "@mat3ra/esse": "2025.8.14-0",
46
+ "@mat3ra/made": "2025.7.15-0",
47
+ "@mat3ra/standata": "2025.10.1-0",
48
+ "@mat3ra/tsconfig": "2024.6.3-0",
49
+ "@types/nunjucks": "^3.2.6",
50
+ "@typescript-eslint/eslint-plugin": "^5.9.1",
51
+ "@typescript-eslint/parser": "^5.9.1",
52
+ "chai": "^4.3.4",
53
+ "eslint": "^7.32.0",
54
+ "eslint-config-airbnb": "^19.0.2",
55
+ "eslint-config-prettier": "^8.5.0",
56
+ "eslint-import-resolver-exports": "^1.0.0-beta.5",
57
+ "eslint-import-resolver-meteor": "^0.4.0",
58
+ "eslint-import-resolver-node": "^0.3.9",
59
+ "eslint-plugin-import": "^2.25.3",
60
+ "eslint-plugin-jsdoc": "^37.1.0",
61
+ "eslint-plugin-jsx-a11y": "^6.5.1",
62
+ "eslint-plugin-mui-path-imports": "0.0.15",
63
+ "eslint-plugin-prettier": "^4.2.1",
64
+ "eslint-plugin-react": "^7.30.0",
65
+ "eslint-plugin-simple-import-sort": "^7.0.0",
66
+ "husky": "^7.0.4",
67
+ "lint-staged": "^12.1.2",
68
+ "mocha": "^9.1.3",
69
+ "nyc": "^15.1.0",
70
+ "prettier": "^2.7.1",
71
+ "ts-node": "^10.9.2",
72
+ "typescript": "^5.6.0"
73
+ },
74
+ "peerDependencies": {
75
+ "@mat3ra/utils": "*",
76
+ "@mat3ra/code": "*",
77
+ "@mat3ra/esse": "*",
78
+ "@mat3ra/made": "*",
79
+ "@mat3ra/standata": "*"
80
+ },
81
+ "engines": {
82
+ "node": ">=20.0.0"
83
+ },
84
+ "lint-staged": {
85
+ "*.js": "eslint --cache --fix",
86
+ "*.{js,css}": "prettier --write"
87
+ }
88
+ }
@@ -0,0 +1,250 @@
1
+ import { getOneMatchFromObject } from "@mat3ra/code/dist/js/utils/object";
2
+ import type { ApplicationSchemaBase, ExecutableSchema } from "@mat3ra/esse/dist/js/types";
3
+ import { ApplicationStandata } from "@mat3ra/standata";
4
+
5
+ import Application from "./application";
6
+ import Executable from "./executable";
7
+ import Flavor from "./flavor";
8
+ import Template from "./template";
9
+
10
+ type ApplicationVersion = {
11
+ [build: string]: ApplicationSchemaBase;
12
+ };
13
+
14
+ type ApplicationTreeItem = {
15
+ defaultVersion: string;
16
+ [version: string]: ApplicationVersion | string;
17
+ };
18
+
19
+ export type CreateApplicationConfig = {
20
+ name: string;
21
+ version?: string | null;
22
+ build?: string | null;
23
+ };
24
+
25
+ type ApplicationTree = Partial<Record<string, ApplicationTreeItem>>;
26
+
27
+ export default class ApplicationRegistry {
28
+ // applications
29
+ static applicationsTree?: ApplicationTree;
30
+
31
+ static applicationsArray?: ApplicationSchemaBase[];
32
+
33
+ static createApplication({ name, version = null, build = null }: CreateApplicationConfig) {
34
+ const staticConfig = ApplicationRegistry.getApplicationConfig({ name, version, build });
35
+ return new Application({
36
+ ...staticConfig,
37
+ name,
38
+ ...(version && { version }),
39
+ ...(build && { build }),
40
+ });
41
+ }
42
+
43
+ static getUniqueAvailableApplicationNames() {
44
+ return new ApplicationStandata().getAllApplicationNames();
45
+ }
46
+
47
+ /**
48
+ * @summary Return all applications as both a nested object of Applications and an array of config objects
49
+ * @returns containing applications and applicationConfigs
50
+ */
51
+ static getAllApplications() {
52
+ if (this.applicationsTree && this.applicationsArray) {
53
+ return {
54
+ applicationsTree: this.applicationsTree,
55
+ applicationsArray: this.applicationsArray,
56
+ };
57
+ }
58
+
59
+ const applicationsTree: ApplicationTree = {};
60
+ const applicationsArray: ApplicationSchemaBase[] = [];
61
+
62
+ const allApplications = new ApplicationStandata().getAllApplicationNames();
63
+ allApplications.forEach((appName) => {
64
+ const { versions, defaultVersion, ...appData } =
65
+ new ApplicationStandata().getAppDataForApplication(appName);
66
+
67
+ const appTreeItem: ApplicationTreeItem = { defaultVersion };
68
+
69
+ versions.forEach((versionInfo) => {
70
+ const { version, build } = versionInfo;
71
+
72
+ let buildToUse = build;
73
+ if (!build) {
74
+ buildToUse = ApplicationStandata.getDefaultBuildForApplicationAndVersion(
75
+ appName,
76
+ version,
77
+ );
78
+ versionInfo.build = buildToUse;
79
+ }
80
+
81
+ const appVersion =
82
+ version in appTreeItem && typeof appTreeItem[version] === "object"
83
+ ? appTreeItem[version]
84
+ : {};
85
+
86
+ appTreeItem[version] = appVersion;
87
+
88
+ const applicationConfig: ApplicationSchemaBase = {
89
+ ...appData,
90
+ build: buildToUse,
91
+ ...versionInfo,
92
+ };
93
+
94
+ if (buildToUse) {
95
+ appVersion[buildToUse] = applicationConfig;
96
+ }
97
+ applicationsArray.push(applicationConfig);
98
+ });
99
+
100
+ applicationsTree[appName] = appTreeItem;
101
+ });
102
+
103
+ this.applicationsTree = applicationsTree;
104
+ this.applicationsArray = applicationsArray;
105
+
106
+ return {
107
+ applicationsTree,
108
+ applicationsArray: this.applicationsArray,
109
+ };
110
+ }
111
+
112
+ /**
113
+ * @summary Get an application from the constructed applications
114
+ * @param name name of the application
115
+ * @param version version of the application (optional, defaults to defaultVersion)
116
+ * @param build the build to use (optional, defaults to Default)
117
+ * @return an application
118
+ */
119
+ static getApplicationConfig({ name, version = null, build = null }: CreateApplicationConfig) {
120
+ const { applicationsTree } = this.getAllApplications();
121
+ const app = applicationsTree[name];
122
+
123
+ if (!app) {
124
+ throw new Error(`Application ${name} not found`);
125
+ }
126
+
127
+ let buildToUse: string | null = build;
128
+ if (!build) {
129
+ try {
130
+ buildToUse = ApplicationStandata.getDefaultBuildForApplicationAndVersion(
131
+ name,
132
+ version || app.defaultVersion,
133
+ );
134
+ } catch (error) {
135
+ console.warn(
136
+ `Failed to get default build for ${name} version ${
137
+ version || app.defaultVersion
138
+ }: ${error}`,
139
+ );
140
+ return null;
141
+ }
142
+ }
143
+
144
+ const version_ = version || app.defaultVersion;
145
+ const appVersion = app[version_];
146
+
147
+ if (!appVersion || typeof appVersion === "string") {
148
+ console.warn(`Version ${version_} not available for ${name} !`);
149
+ return null;
150
+ }
151
+
152
+ if (!buildToUse) {
153
+ console.warn(`No build specified for ${name} version ${version_}`);
154
+ return null;
155
+ }
156
+
157
+ return appVersion[buildToUse] ?? null;
158
+ }
159
+
160
+ static getExecutables({ name, version }: { name: string; version?: string }) {
161
+ const tree = new ApplicationStandata().getAppTreeForApplication(name);
162
+
163
+ return Object.keys(tree)
164
+ .filter((key) => {
165
+ const executable = tree[key];
166
+ const { supportedApplicationVersions } = executable;
167
+ return (
168
+ !supportedApplicationVersions ||
169
+ (version && supportedApplicationVersions.includes(version))
170
+ );
171
+ })
172
+ .map((key) => new Executable({ ...tree[key], name: key }));
173
+ }
174
+
175
+ static getExecutableByName(appName: string, execName?: string) {
176
+ const appTree = new ApplicationStandata().getAppTreeForApplication(appName);
177
+
178
+ Object.entries(appTree).forEach(([name, exec]) => {
179
+ exec.name = name;
180
+ });
181
+
182
+ const config = execName
183
+ ? appTree[execName]
184
+ : (getOneMatchFromObject(appTree, "isDefault", true) as ExecutableSchema);
185
+
186
+ return new Executable(config);
187
+ }
188
+
189
+ // TODO: remove this method and use getApplicationExecutableByName directly
190
+ static getExecutableByConfig(appName: string, config?: { name: string }) {
191
+ return this.getExecutableByName(appName, config?.name);
192
+ }
193
+
194
+ static getExecutableFlavors(executable: Executable) {
195
+ const flavorsTree = executable.prop("flavors", {}) as Record<string, any>;
196
+
197
+ return Object.keys(flavorsTree).map((key) => {
198
+ return new Flavor({
199
+ ...flavorsTree[key],
200
+ name: key,
201
+ });
202
+ });
203
+ }
204
+
205
+ static getFlavorByName(executable: Executable, name?: string) {
206
+ return this.getExecutableFlavors(executable).find((flavor) =>
207
+ name ? flavor.name === name : flavor.isDefault,
208
+ );
209
+ }
210
+
211
+ static getFlavorByConfig(executable: Executable, config?: { name: string }) {
212
+ return this.getFlavorByName(executable, config?.name);
213
+ }
214
+
215
+ // flavors
216
+ static getInputAsTemplates(flavor: Flavor) {
217
+ const appName = flavor.prop("applicationName", "");
218
+ const execName = flavor.prop("executableName", "");
219
+
220
+ return flavor.input.map((input) => {
221
+ const inputName = input.templateName || input.name;
222
+
223
+ const filtered = new ApplicationStandata().getTemplatesByName(
224
+ appName,
225
+ execName,
226
+ inputName,
227
+ );
228
+
229
+ if (filtered.length !== 1) {
230
+ console.log(
231
+ `found ${filtered.length} templates for app=${appName} exec=${execName} name=${inputName} expected 1`,
232
+ );
233
+ }
234
+
235
+ return new Template({ ...filtered[0], name: input.name });
236
+ });
237
+ }
238
+
239
+ static getInputAsRenderedTemplates(flavor: Flavor, context: Record<string, unknown>) {
240
+ return this.getInputAsTemplates(flavor).map((template) => {
241
+ return template.getRenderedJSON(context);
242
+ });
243
+ }
244
+
245
+ static getAllFlavorsForApplication(appName: string, version?: string) {
246
+ const allExecutables = this.getExecutables({ name: appName, version });
247
+
248
+ return allExecutables.flatMap((executable) => this.getExecutableFlavors(executable));
249
+ }
250
+ }
@@ -0,0 +1,18 @@
1
+ import { NamedDefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
+ import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
3
+
4
+ import {
5
+ type ApplicationMixin,
6
+ type ApplicationStaticMixin,
7
+ applicationMixin,
8
+ applicationStaticMixin,
9
+ } from "./applicationMixin";
10
+
11
+ type Base = typeof NamedDefaultableInMemoryEntity &
12
+ Constructor<ApplicationMixin> &
13
+ ApplicationStaticMixin;
14
+
15
+ export default class Application extends (NamedDefaultableInMemoryEntity as Base) {}
16
+
17
+ applicationMixin(Application.prototype);
18
+ applicationStaticMixin(Application);
@@ -0,0 +1,86 @@
1
+ import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
+ import type { DefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/DefaultableMixin";
3
+ import type { NamedInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin";
4
+ import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
5
+ import JSONSchemasInterface from "@mat3ra/esse/dist/js/esse/JSONSchemasInterface";
6
+ import type { ApplicationSchemaBase } from "@mat3ra/esse/dist/js/types";
7
+ import { ApplicationStandata } from "@mat3ra/standata";
8
+
9
+ import Executable from "./executable";
10
+
11
+ type Base = InMemoryEntity & NamedInMemoryEntity & DefaultableInMemoryEntity;
12
+
13
+ export type BaseConstructor = Constructor<Base> & {
14
+ constructCustomExecutable?: (config: object) => Executable;
15
+ };
16
+
17
+ export type ApplicationConstructor = Constructor<ApplicationMixin> & ApplicationStaticMixin;
18
+
19
+ export type ApplicationMixin = Pick<
20
+ ApplicationSchemaBase,
21
+ "summary" | "version" | "build" | "shortName" | "hasAdvancedComputeOptions" | "isLicensed"
22
+ > & {
23
+ name: Required<ApplicationSchemaBase>["name"];
24
+ isUsingMaterial: boolean;
25
+ };
26
+
27
+ export type DefaultApplicationConfig = Pick<
28
+ ApplicationSchemaBase,
29
+ "name" | "shortName" | "version" | "summary" | "build"
30
+ >;
31
+
32
+ export type ApplicationStaticMixin = {
33
+ defaultConfig: DefaultApplicationConfig;
34
+ jsonSchema: ApplicationSchemaBase;
35
+ };
36
+
37
+ export function applicationMixin(item: Base) {
38
+ // @ts-expect-error
39
+ const properties: ApplicationMixin & Base = {
40
+ get summary() {
41
+ return this.prop("summary");
42
+ },
43
+
44
+ get version() {
45
+ return this.prop("version", "");
46
+ },
47
+
48
+ get build() {
49
+ return this.prop("build");
50
+ },
51
+
52
+ get shortName() {
53
+ return this.prop("shortName", this.name);
54
+ },
55
+
56
+ get hasAdvancedComputeOptions() {
57
+ return this.prop("hasAdvancedComputeOptions", false);
58
+ },
59
+
60
+ get isLicensed() {
61
+ return this.prop("isLicensed", false);
62
+ },
63
+
64
+ get isUsingMaterial() {
65
+ const materialUsingApplications = ["vasp", "nwchem", "espresso"];
66
+ return materialUsingApplications.includes(this.name);
67
+ },
68
+ };
69
+
70
+ Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
71
+ }
72
+
73
+ export function applicationStaticMixin<T extends BaseConstructor>(Application: T) {
74
+ const properties: ApplicationStaticMixin = {
75
+ get defaultConfig() {
76
+ return new ApplicationStandata().getDefaultConfig();
77
+ },
78
+ get jsonSchema() {
79
+ return JSONSchemasInterface.getSchemaById(
80
+ "software/application",
81
+ ) as ApplicationSchemaBase;
82
+ },
83
+ };
84
+
85
+ Object.defineProperties(Application, Object.getOwnPropertyDescriptors(properties));
86
+ }