@mat3ra/mode 2026.6.3-0 → 2026.8.18-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.
@@ -1,5 +1,5 @@
1
1
  import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
- import type { BaseMethod } from "@mat3ra/esse/dist/js/types";
2
+ import type { BaseInMemoryEntitySchema, BaseMethod } from "@mat3ra/esse/dist/js/types";
3
3
  export type MethodSchemaMixin = BaseMethod;
4
- export type MethodInMemoryEntity = InMemoryEntity & MethodSchemaMixin;
4
+ export type MethodInMemoryEntity = InMemoryEntity<BaseInMemoryEntitySchema & MethodSchemaMixin>;
5
5
  export declare function methodSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & MethodSchemaMixin;
@@ -1,5 +1,5 @@
1
1
  import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
- import type { BaseModel } from "@mat3ra/esse/dist/js/types";
2
+ import type { BaseInMemoryEntitySchema, BaseModel } from "@mat3ra/esse/dist/js/types";
3
3
  export type ModelSchemaMixin = BaseModel;
4
- export type ModelInMemoryEntity = InMemoryEntity & ModelSchemaMixin;
4
+ export type ModelInMemoryEntity = InMemoryEntity<BaseInMemoryEntitySchema & ModelSchemaMixin>;
5
5
  export declare function modelSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & ModelSchemaMixin;
@@ -1,23 +1,24 @@
1
1
  import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
2
  import { type HashedEntity } from "@mat3ra/code/dist/js/entity/mixins/HashedEntityMixin";
3
- import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
4
- import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
5
- import type { BaseMethod, SlugifiedEntry } from "@mat3ra/esse/dist/js/types";
3
+ import type { BaseInMemoryEntitySchema, BaseMethod, FileDataItem, SlugifiedEntry } from "@mat3ra/esse/dist/js/types";
6
4
  import { type MethodSchemaMixin } from "./generated/MethodSchemaMixin";
7
- type Base = typeof InMemoryEntity & Constructor<MethodSchemaMixin> & Constructor<HashedEntity>;
5
+ type MethodEntity = BaseMethod & BaseInMemoryEntitySchema;
6
+ export interface Method extends MethodSchemaMixin, HashedEntity {
7
+ }
8
8
  interface MethodData extends Record<string, unknown> {
9
9
  searchText?: string;
10
+ pseudo?: FileDataItem[];
11
+ allPseudo?: FileDataItem[];
10
12
  }
11
- declare const Method_base: Base;
12
- export declare class Method extends Method_base implements BaseMethod {
13
+ export declare class Method extends InMemoryEntity<MethodEntity> implements BaseMethod, HashedEntity {
13
14
  constructor(config: BaseMethod);
14
- toJSON: () => BaseMethod & AnyObject;
15
15
  cloneWithoutData(): Method;
16
16
  setSubtype(subtype: SlugifiedEntry): void;
17
17
  static get defaultConfig(): {
18
18
  readonly type: "pseudopotential";
19
19
  readonly subtype: "us";
20
20
  };
21
+ get methodData(): MethodData;
21
22
  get searchText(): string;
22
23
  setSearchText(searchText: string): void;
23
24
  setData(data?: MethodData): void;
package/dist/js/method.js CHANGED
@@ -22,17 +22,22 @@ class Method extends entity_1.InMemoryEntity {
22
22
  static get defaultConfig() {
23
23
  return default_methods_1.PseudopotentialMethodConfig;
24
24
  }
25
+ get methodData() {
26
+ var _a;
27
+ return (_a = this.data) !== null && _a !== void 0 ? _a : {};
28
+ }
25
29
  get searchText() {
26
- return this.prop("data.searchText", "");
30
+ var _a;
31
+ return (_a = this.methodData.searchText) !== null && _a !== void 0 ? _a : "";
27
32
  }
28
33
  setSearchText(searchText) {
29
- this.setData({ ...this.data, searchText });
34
+ this.setData({ ...this.methodData, searchText });
30
35
  }
31
36
  setData(data = {}) {
32
- this.setProp("data", data);
37
+ this.data = data;
33
38
  }
34
39
  cleanData(fieldsToExclude = []) {
35
- const filteredData = { ...this.data };
40
+ const filteredData = { ...this.methodData };
36
41
  fieldsToExclude.forEach((field) => {
37
42
  delete filteredData[field];
38
43
  });
@@ -1,4 +1,3 @@
1
- import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
2
1
  import { type BaseMethod, type FileDataItem } from "@mat3ra/esse/dist/js/types";
3
2
  import { PseudopotentialFilter, PseudopotentialMetaProperty } from "@mat3ra/prode";
4
3
  import { Method } from "../method";
@@ -7,7 +6,6 @@ export type ExchangeCorrelation = {
7
6
  functional: string;
8
7
  };
9
8
  export declare class PseudopotentialMethod extends Method {
10
- toJSON: () => BaseMethod & AnyObject;
11
9
  get pseudo(): FileDataItem[];
12
10
  get allPseudo(): FileDataItem[];
13
11
  get pseudopotentials(): PseudopotentialMetaProperty[];
@@ -9,10 +9,12 @@ const underscore_1 = __importDefault(require("underscore"));
9
9
  const method_1 = require("../method");
10
10
  class PseudopotentialMethod extends method_1.Method {
11
11
  get pseudo() {
12
- return this.prop("data.pseudo", []);
12
+ var _a;
13
+ return (_a = this.methodData.pseudo) !== null && _a !== void 0 ? _a : [];
13
14
  }
14
15
  get allPseudo() {
15
- return this.prop("data.allPseudo", []);
16
+ var _a;
17
+ return (_a = this.methodData.allPseudo) !== null && _a !== void 0 ? _a : [];
16
18
  }
17
19
  get pseudopotentials() {
18
20
  return this.pseudo.map((config) => new prode_1.PseudopotentialMetaProperty(config));
@@ -37,13 +39,13 @@ class PseudopotentialMethod extends method_1.Method {
37
39
  }
38
40
  setPseudopotentials(pseudopotentials) {
39
41
  this.setData({
40
- ...this.data,
42
+ ...this.methodData,
41
43
  pseudo: underscore_1.default.sortBy(pseudopotentials, "element").map((item) => item.toJSON()),
42
44
  });
43
45
  }
44
46
  setAllPseudopotentials(pseudopotentials) {
45
47
  this.setData({
46
- ...this.data,
48
+ ...this.methodData,
47
49
  allPseudo: underscore_1.default.sortBy(pseudopotentials, "element").map((item) => item.toJSON()),
48
50
  });
49
51
  }
@@ -1,15 +1,20 @@
1
1
  import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
2
  import { type HashedEntity } from "@mat3ra/code/dist/js/entity/mixins/HashedEntityMixin";
3
- import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
4
- import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
5
- import type { AnyModelSchema, ApplicationSchema, BaseMethod, BaseModel, SlugifiedEntry, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
3
+ import type { ApplicationSchema, BaseInMemoryEntitySchema, BaseMethod, BaseModel, SlugifiedEntry, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
6
4
  import { type ModelSchemaMixin } from "./generated/ModelSchemaMixin";
7
5
  import { Method } from "./method";
8
6
  import { MethodFactory } from "./methods/factory";
9
7
  import type { MethodTreeBranch, ModelConfig, ModelTree } from "./types";
10
- type Base = typeof InMemoryEntity & Constructor<ModelSchemaMixin> & Constructor<HashedEntity>;
11
- declare const Model_base: Base;
12
- export declare class Model extends Model_base implements BaseModel {
8
+ export type ModelEntity = BaseInMemoryEntitySchema & Pick<BaseModel, "method"> & {
9
+ type: string;
10
+ subtype: SlugifiedEntryOrSlug;
11
+ refiners?: SlugifiedEntry[];
12
+ modifiers?: SlugifiedEntry[];
13
+ functional?: string;
14
+ };
15
+ export interface Model extends ModelSchemaMixin, HashedEntity {
16
+ }
17
+ export declare class Model extends InMemoryEntity<ModelEntity> implements BaseModel {
13
18
  protected _application?: ApplicationSchema;
14
19
  protected _MethodFactory: typeof MethodFactory;
15
20
  protected _method?: Method;
@@ -39,11 +44,9 @@ export declare class Model extends Model_base implements BaseModel {
39
44
  subtype: "gga";
40
45
  };
41
46
  static get allTypes(): SlugifiedEntry[];
42
- _json: AnyModelSchema & AnyObject;
43
- toJSON(): AnyModelSchema & AnyObject;
47
+ toJSON(): ModelEntity;
44
48
  protected _stringToSlugifiedObject(slug: SlugifiedEntryOrSlug): SlugifiedEntry;
45
49
  get isUnknown(): boolean;
46
50
  protected get subtypeSlug(): string;
47
51
  getHashObject(): Record<string, unknown>;
48
52
  }
49
- export {};
package/dist/js/model.js CHANGED
@@ -16,7 +16,7 @@ const EMPTY_BRANCH = { methods: {} };
16
16
  class Model extends entity_1.InMemoryEntity {
17
17
  constructor(config) {
18
18
  const { application, method = method_1.Method.defaultConfig, ...entityConfig } = config;
19
- super(entityConfig);
19
+ super({ ...entityConfig, method });
20
20
  this._application = application;
21
21
  this._MethodFactory = factory_1.MethodFactory;
22
22
  this.method = method || this.method;
@@ -14,16 +14,15 @@ export declare class DFTModel extends Model {
14
14
  readonly defaultRefiners: SlugifiedEntry[];
15
15
  readonly defaultModifiers: SlugifiedEntry[];
16
16
  get slugifiedFunctional(): SlugifiedEntry;
17
- get functional(): "pz" | "pw" | "vwn" | "other" | "pbe" | "pbesol" | "pw91" | "b3lyp" | "hse06";
18
- set functional(functional: "pz" | "pw" | "vwn" | "other" | "pbe" | "pbesol" | "pw91" | "b3lyp" | "hse06");
19
- get refiners(): SlugifiedEntry[];
20
- get modifiers(): SlugifiedEntry[];
17
+ get functional(): string | undefined;
18
+ set functional(functional: string | undefined);
19
+ get refiners(): SlugifiedEntry[] | undefined;
20
+ get modifiers(): SlugifiedEntry[] | undefined;
21
21
  setSubtype(subtype: SlugifiedEntryOrSlug): void;
22
22
  setFunctional(functional: string): void;
23
23
  private _setArrayProp;
24
24
  setRefiners(refiners: SlugifiedEntryOrSlug | SlugifiedEntryOrSlug[]): void;
25
25
  setModifiers(modifiers: SlugifiedEntryOrSlug | SlugifiedEntryOrSlug[]): void;
26
- _json: DFTModelSchema & AnyObject;
27
26
  toJSON(): DFTModelSchema & AnyObject;
28
27
  get allFunctionals(): SlugifiedEntry[];
29
28
  get allRefiners(): SlugifiedEntry[];
@@ -11,15 +11,14 @@ class DFTModel extends model_1.Model {
11
11
  this.defaultRefiners = [];
12
12
  this.defaultModifiers = [];
13
13
  this._MethodFactory = config.MethodFactory || factory_1.MethodFactory;
14
- this.functional =
15
- this.prop("functional") || this.defaultFunctional.slug;
14
+ this.functional = this.prop("functional") || this.defaultFunctional.slug;
16
15
  }
17
16
  get groupSlug() {
18
- var _a;
19
- const refinersSlug = this.refiners.map((o) => o.slug).join("+");
20
- const modifiersSlug = this.modifiers.map((o) => o.slug).join("+");
17
+ var _a, _b, _c;
18
+ const refinersSlug = ((_a = this.refiners) !== null && _a !== void 0 ? _a : []).map((o) => o.slug).join("+");
19
+ const modifiersSlug = ((_b = this.modifiers) !== null && _b !== void 0 ? _b : []).map((o) => o.slug).join("+");
21
20
  const slugs = [
22
- (_a = this._application) === null || _a === void 0 ? void 0 : _a.shortName,
21
+ (_c = this._application) === null || _c === void 0 ? void 0 : _c.shortName,
23
22
  this.type,
24
23
  this.subtype,
25
24
  this.functional,
@@ -33,7 +32,8 @@ class DFTModel extends model_1.Model {
33
32
  return (0, tree_1.treeSlugToNamedObject)(slug);
34
33
  }
35
34
  get slugifiedFunctional() {
36
- return this._stringToSlugifiedObject(this.functional);
35
+ var _a;
36
+ return this._stringToSlugifiedObject((_a = this.functional) !== null && _a !== void 0 ? _a : this.defaultFunctional.slug);
37
37
  }
38
38
  get functional() {
39
39
  return this.requiredProp("functional");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mat3ra/mode",
3
- "version": "2026.6.3-0",
3
+ "version": "2026.8.18-0",
4
4
  "description": "MOdel and method DEfinitions",
5
5
  "scripts": {
6
6
  "test": "nyc --reporter=text mocha --recursive --bail",
@@ -31,7 +31,6 @@
31
31
  "license": "Apache-2.0",
32
32
  "homepage": "https://github.com/Exabyte-io/mode",
33
33
  "dependencies": {
34
- "@mat3ra/utils": "^2026.3.2-0",
35
34
  "@babel/cli": "7.16.0",
36
35
  "@babel/core": "7.16.0",
37
36
  "@babel/eslint-parser": "7.16.3",
@@ -40,9 +39,10 @@
40
39
  "@babel/preset-react": "7.16.7",
41
40
  "@babel/register": "^7.16.0",
42
41
  "@babel/runtime-corejs3": "7.16.8",
42
+ "@mat3ra/utils": "2026.8.18-1",
43
43
  "@types/lodash": "^4.14.202",
44
- "@types/underscore": "^1.11.14",
45
44
  "@types/node": "^20.11.30",
45
+ "@types/underscore": "^1.11.14",
46
46
  "ajv": "^8.12.0",
47
47
  "js-yaml": "^4.1.0",
48
48
  "lodash": "^4.17.21",
@@ -54,13 +54,15 @@
54
54
  },
55
55
  "devDependencies": {
56
56
  "@exabyte-io/eslint-config": "2025.5.13-0",
57
- "@mat3ra/code": "2026.5.27-0",
58
- "@mat3ra/esse": "2026.5.27-0",
59
- "@mat3ra/prode": "2026.5.28-0",
57
+ "@mat3ra/code": "2026.8.18-0",
58
+ "@mat3ra/esse": "2026.8.18-2",
59
+ "@mat3ra/prode": "2026.8.18-0",
60
60
  "@mat3ra/standata": "2026.5.28-0",
61
61
  "@mat3ra/tsconfig": "2024.6.3-0",
62
62
  "@types/chai": "^4.3.11",
63
63
  "@types/mocha": "^10.0.6",
64
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
65
+ "@typescript-eslint/parser": "^5.62.0",
64
66
  "chai": "^4.3.4",
65
67
  "eslint": "^7.32.0",
66
68
  "eslint-config-airbnb": "^19.0.2",
@@ -82,8 +84,8 @@
82
84
  "prettier": "^2.7.1"
83
85
  },
84
86
  "peerDependencies": {
85
- "@mat3ra/esse": "*",
86
87
  "@mat3ra/code": "*",
88
+ "@mat3ra/esse": "*",
87
89
  "@mat3ra/prode": "*"
88
90
  },
89
91
  "engines": {
@@ -1,35 +1,35 @@
1
1
  import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
- import type { BaseMethod } from "@mat3ra/esse/dist/js/types";
2
+ import type { BaseInMemoryEntitySchema, BaseMethod } from "@mat3ra/esse/dist/js/types";
3
3
 
4
4
  export type MethodSchemaMixin = BaseMethod;
5
5
 
6
- export type MethodInMemoryEntity = InMemoryEntity & MethodSchemaMixin;
6
+ export type MethodInMemoryEntity = InMemoryEntity<BaseInMemoryEntitySchema & MethodSchemaMixin>;
7
7
 
8
8
  export function methodSchemaMixin<T extends InMemoryEntity>(
9
9
  item: InMemoryEntity,
10
10
  ): asserts item is T & MethodSchemaMixin {
11
11
  // @ts-expect-error
12
- const properties: InMemoryEntity & MethodSchemaMixin = {
12
+ const properties: InMemoryEntity<MethodSchemaMixin> & MethodSchemaMixin = {
13
13
  get type() {
14
- return this.requiredProp<BaseMethod["type"]>("type");
14
+ return this.requiredProp("type");
15
15
  },
16
16
  set type(value: BaseMethod["type"]) {
17
17
  this.setProp("type", value);
18
18
  },
19
19
  get subtype() {
20
- return this.requiredProp<BaseMethod["subtype"]>("subtype");
20
+ return this.requiredProp("subtype");
21
21
  },
22
22
  set subtype(value: BaseMethod["subtype"]) {
23
23
  this.setProp("subtype", value);
24
24
  },
25
25
  get precision() {
26
- return this.prop<BaseMethod["precision"]>("precision");
26
+ return this.prop("precision");
27
27
  },
28
28
  set precision(value: BaseMethod["precision"]) {
29
29
  this.setProp("precision", value);
30
30
  },
31
31
  get data() {
32
- return this.prop<BaseMethod["data"]>("data");
32
+ return this.prop("data");
33
33
  },
34
34
  set data(value: BaseMethod["data"]) {
35
35
  this.setProp("data", value);
@@ -1,29 +1,29 @@
1
1
  import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
- import type { BaseModel } from "@mat3ra/esse/dist/js/types";
2
+ import type { BaseInMemoryEntitySchema, BaseModel } from "@mat3ra/esse/dist/js/types";
3
3
 
4
4
  export type ModelSchemaMixin = BaseModel;
5
5
 
6
- export type ModelInMemoryEntity = InMemoryEntity & ModelSchemaMixin;
6
+ export type ModelInMemoryEntity = InMemoryEntity<BaseInMemoryEntitySchema & ModelSchemaMixin>;
7
7
 
8
8
  export function modelSchemaMixin<T extends InMemoryEntity>(
9
9
  item: InMemoryEntity,
10
10
  ): asserts item is T & ModelSchemaMixin {
11
11
  // @ts-expect-error
12
- const properties: InMemoryEntity & ModelSchemaMixin = {
12
+ const properties: InMemoryEntity<ModelSchemaMixin> & ModelSchemaMixin = {
13
13
  get type() {
14
- return this.requiredProp<BaseModel["type"]>("type");
14
+ return this.requiredProp("type");
15
15
  },
16
16
  set type(value: BaseModel["type"]) {
17
17
  this.setProp("type", value);
18
18
  },
19
19
  get subtype() {
20
- return this.requiredProp<BaseModel["subtype"]>("subtype");
20
+ return this.requiredProp("subtype");
21
21
  },
22
22
  set subtype(value: BaseModel["subtype"]) {
23
23
  this.setProp("subtype", value);
24
24
  },
25
25
  get method() {
26
- return this.requiredProp<BaseModel["method"]>("method");
26
+ return this.requiredProp("method");
27
27
  },
28
28
  set method(value: BaseModel["method"]) {
29
29
  this.setProp("method", value);
package/src/js/method.ts CHANGED
@@ -4,27 +4,32 @@ import {
4
4
  hashedEntityMixin,
5
5
  } from "@mat3ra/code/dist/js/entity/mixins/HashedEntityMixin";
6
6
  import { deepClone } from "@mat3ra/code/dist/js/utils";
7
- import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
8
- import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
9
- import type { BaseMethod, SlugifiedEntry } from "@mat3ra/esse/dist/js/types";
7
+ import type {
8
+ BaseInMemoryEntitySchema,
9
+ BaseMethod,
10
+ FileDataItem,
11
+ SlugifiedEntry,
12
+ } from "@mat3ra/esse/dist/js/types";
10
13
 
11
14
  import { PseudopotentialMethodConfig } from "./default_methods";
12
15
  import { type MethodSchemaMixin, methodSchemaMixin } from "./generated/MethodSchemaMixin";
13
16
 
14
- type Base = typeof InMemoryEntity & Constructor<MethodSchemaMixin> & Constructor<HashedEntity>;
17
+ type MethodEntity = BaseMethod & BaseInMemoryEntitySchema;
18
+
19
+ export interface Method extends MethodSchemaMixin, HashedEntity {}
15
20
 
16
21
  interface MethodData extends Record<string, unknown> {
17
22
  searchText?: string;
23
+ pseudo?: FileDataItem[];
24
+ allPseudo?: FileDataItem[];
18
25
  }
19
26
 
20
- export class Method extends (InMemoryEntity as Base) implements BaseMethod {
27
+ export class Method extends InMemoryEntity<MethodEntity> implements BaseMethod, HashedEntity {
21
28
  constructor(config: BaseMethod) {
22
29
  const data = config.data || {};
23
30
  super({ ...config, data });
24
31
  }
25
32
 
26
- declare toJSON: () => BaseMethod & AnyObject;
27
-
28
33
  cloneWithoutData(): Method {
29
34
  const clone = this.clone() as Method;
30
35
  clone.setData({});
@@ -39,20 +44,24 @@ export class Method extends (InMemoryEntity as Base) implements BaseMethod {
39
44
  return PseudopotentialMethodConfig;
40
45
  }
41
46
 
47
+ get methodData(): MethodData {
48
+ return (this.data as MethodData | undefined) ?? {};
49
+ }
50
+
42
51
  get searchText(): string {
43
- return this.prop<string>("data.searchText", "");
52
+ return this.methodData.searchText ?? "";
44
53
  }
45
54
 
46
55
  setSearchText(searchText: string): void {
47
- this.setData({ ...this.data, searchText });
56
+ this.setData({ ...this.methodData, searchText });
48
57
  }
49
58
 
50
59
  setData(data: MethodData = {}): void {
51
- this.setProp("data", data);
60
+ this.data = data;
52
61
  }
53
62
 
54
63
  cleanData(fieldsToExclude: string[] = []): MethodData {
55
- const filteredData = { ...(this.data as MethodData) };
64
+ const filteredData = { ...this.methodData };
56
65
  fieldsToExclude.forEach((field) => {
57
66
  delete filteredData[field];
58
67
  });
@@ -1,4 +1,3 @@
1
- import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
2
1
  import { type BaseMethod, type FileDataItem } from "@mat3ra/esse/dist/js/types";
3
2
  import { PseudopotentialFilter, PseudopotentialMetaProperty } from "@mat3ra/prode";
4
3
  import _ from "underscore";
@@ -11,14 +10,12 @@ export type ExchangeCorrelation = {
11
10
  };
12
11
 
13
12
  export class PseudopotentialMethod extends Method {
14
- declare toJSON: () => BaseMethod & AnyObject;
15
-
16
- get pseudo() {
17
- return this.prop<FileDataItem[]>("data.pseudo", []);
13
+ get pseudo(): FileDataItem[] {
14
+ return this.methodData.pseudo ?? [];
18
15
  }
19
16
 
20
- get allPseudo() {
21
- return this.prop<FileDataItem[]>("data.allPseudo", []);
17
+ get allPseudo(): FileDataItem[] {
18
+ return this.methodData.allPseudo ?? [];
22
19
  }
23
20
 
24
21
  get pseudopotentials() {
@@ -50,14 +47,14 @@ export class PseudopotentialMethod extends Method {
50
47
 
51
48
  setPseudopotentials(pseudopotentials: PseudopotentialMetaProperty[]) {
52
49
  this.setData({
53
- ...this.data,
50
+ ...this.methodData,
54
51
  pseudo: _.sortBy(pseudopotentials, "element").map((item) => item.toJSON()),
55
52
  });
56
53
  }
57
54
 
58
55
  setAllPseudopotentials(pseudopotentials: PseudopotentialMetaProperty[]) {
59
56
  this.setData({
60
- ...this.data,
57
+ ...this.methodData,
61
58
  allPseudo: _.sortBy(pseudopotentials, "element").map((item) => item.toJSON()),
62
59
  });
63
60
  }
package/src/js/model.ts CHANGED
@@ -3,11 +3,9 @@ import {
3
3
  type HashedEntity,
4
4
  hashedEntityMixin,
5
5
  } from "@mat3ra/code/dist/js/entity/mixins/HashedEntityMixin";
6
- import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
7
- import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
8
6
  import type {
9
- AnyModelSchema,
10
7
  ApplicationSchema,
8
+ BaseInMemoryEntitySchema,
11
9
  BaseMethod,
12
10
  BaseModel,
13
11
  SlugifiedEntry,
@@ -24,9 +22,18 @@ import type { MethodTreeBranch, ModelConfig, ModelTree } from "./types";
24
22
 
25
23
  const EMPTY_BRANCH: MethodTreeBranch = { methods: {} };
26
24
 
27
- type Base = typeof InMemoryEntity & Constructor<ModelSchemaMixin> & Constructor<HashedEntity>;
25
+ export type ModelEntity = BaseInMemoryEntitySchema &
26
+ Pick<BaseModel, "method"> & {
27
+ type: string;
28
+ subtype: SlugifiedEntryOrSlug;
29
+ refiners?: SlugifiedEntry[];
30
+ modifiers?: SlugifiedEntry[];
31
+ functional?: string;
32
+ };
28
33
 
29
- export class Model extends (InMemoryEntity as Base) implements BaseModel {
34
+ export interface Model extends ModelSchemaMixin, HashedEntity {}
35
+
36
+ export class Model extends InMemoryEntity<ModelEntity> implements BaseModel {
30
37
  protected _application?: ApplicationSchema;
31
38
 
32
39
  protected _MethodFactory: typeof MethodFactory;
@@ -35,7 +42,7 @@ export class Model extends (InMemoryEntity as Base) implements BaseModel {
35
42
 
36
43
  constructor(config: ModelConfig) {
37
44
  const { application, method = Method.defaultConfig, ...entityConfig } = config;
38
- super(entityConfig);
45
+ super({ ...entityConfig, method } as ModelEntity);
39
46
  this._application = application;
40
47
  this._MethodFactory = MethodFactory;
41
48
  this.method = method || this.method;
@@ -137,15 +144,13 @@ export class Model extends (InMemoryEntity as Base) implements BaseModel {
137
144
  return Object.keys(MODEL_TREE).map((modelSlug) => treeSlugToNamedObject(modelSlug));
138
145
  }
139
146
 
140
- declare _json: AnyModelSchema & AnyObject;
141
-
142
- toJSON(): AnyModelSchema & AnyObject {
147
+ toJSON(): ModelEntity {
143
148
  return {
144
149
  ...super.toJSON(),
145
150
  type: this.type,
146
151
  subtype: this.subtype,
147
152
  method: this.Method.toJSONWithCleanData(),
148
- } as AnyModelSchema & AnyObject;
153
+ };
149
154
  }
150
155
 
151
156
  // eslint-disable-next-line class-methods-use-this
@@ -166,7 +171,7 @@ export class Model extends (InMemoryEntity as Base) implements BaseModel {
166
171
  }
167
172
 
168
173
  getHashObject(): Record<string, unknown> {
169
- const json = this.toJSON() as Record<string, unknown>;
174
+ const json = this.toJSON() as unknown as Record<string, unknown>;
170
175
  json.method = this.Method.calculateHash();
171
176
  return json;
172
177
  }
@@ -15,8 +15,7 @@ export class DFTModel extends Model {
15
15
  constructor(config: ModelConfig & { MethodFactory?: typeof MethodFactory }) {
16
16
  super(config);
17
17
  this._MethodFactory = config.MethodFactory || MethodFactory;
18
- this.functional =
19
- this.prop<DFTModelSchema["functional"]>("functional") || this.defaultFunctional.slug;
18
+ this.functional = this.prop("functional") || this.defaultFunctional.slug;
20
19
  }
21
20
 
22
21
  declare type: DFTModelSchema["type"];
@@ -24,8 +23,8 @@ export class DFTModel extends Model {
24
23
  declare subtype: DFTModelSchema["subtype"];
25
24
 
26
25
  get groupSlug(): string {
27
- const refinersSlug = this.refiners.map((o) => o.slug).join("+");
28
- const modifiersSlug = this.modifiers.map((o) => o.slug).join("+");
26
+ const refinersSlug = (this.refiners ?? []).map((o) => o.slug).join("+");
27
+ const modifiersSlug = (this.modifiers ?? []).map((o) => o.slug).join("+");
29
28
  const slugs = [
30
29
  this._application?.shortName,
31
30
  this.type,
@@ -47,11 +46,11 @@ export class DFTModel extends Model {
47
46
  readonly defaultModifiers: SlugifiedEntry[] = [];
48
47
 
49
48
  get slugifiedFunctional() {
50
- return this._stringToSlugifiedObject(this.functional);
49
+ return this._stringToSlugifiedObject(this.functional ?? this.defaultFunctional.slug);
51
50
  }
52
51
 
53
52
  get functional() {
54
- return this.requiredProp<DFTModelSchema["functional"]>("functional");
53
+ return this.requiredProp("functional");
55
54
  }
56
55
 
57
56
  set functional(functional) {
@@ -59,11 +58,11 @@ export class DFTModel extends Model {
59
58
  }
60
59
 
61
60
  get refiners() {
62
- return this.prop<SlugifiedEntry[]>("refiners", this.defaultRefiners);
61
+ return this.prop("refiners", this.defaultRefiners);
63
62
  }
64
63
 
65
64
  get modifiers() {
66
- return this.prop<SlugifiedEntry[]>("modifiers", this.defaultModifiers);
65
+ return this.prop("modifiers", this.defaultModifiers);
67
66
  }
68
67
 
69
68
  setSubtype(subtype: SlugifiedEntryOrSlug): void {
@@ -93,8 +92,6 @@ export class DFTModel extends Model {
93
92
  this._setArrayProp("modifiers", modifiers);
94
93
  }
95
94
 
96
- declare _json: DFTModelSchema & AnyObject;
97
-
98
95
  toJSON(): DFTModelSchema & AnyObject {
99
96
  const baseJson = super.toJSON();
100
97
  const keysToExclude = ["type", "subtype", "functional", "refiners", "modifiers", "method"];