diff --git a/dist/js/constants.d.ts b/dist/js/constants.d.ts index a2041a4d..eb129258 100644 --- a/dist/js/constants.d.ts +++ b/dist/js/constants.d.ts @@ -1,3 +1,29 @@ +export declare enum Units { + bohr = "bohr", + angstrom = "angstrom", + degree = "degree", + radian = "radian", + alat = "alat" +} +/** + * @summary Coordinates units for a material's basis. + */ +export declare enum AtomicCoordinateUnits { + crystal = "crystal", + cartesian = "cartesian" +} +export declare enum Tolerance { + length = 0.01, + lengthAngstrom = 0.001, + pointsDistance = 0.001 +} +export declare enum Coefficients { + EV_TO_RY = 0.0734986176, + BOHR_TO_ANGSTROM = 0.52917721092, + ANGSTROM_TO_BOHR = 1.8897261245650618, + EV_A_TO_RY_BOHR = 0.03889379346800142 +} +export declare const HASH_TOLERANCE: 3; export declare const coefficients: { EV_TO_RY: number; BOHR_TO_ANGSTROM: number; @@ -23,7 +49,6 @@ export declare const ATOMIC_COORD_UNITS: { crystal: string; cartesian: string; }; -export declare const HASH_TOLERANCE = 3; declare const _default: { coefficients: { EV_TO_RY: number; diff --git a/dist/js/constants.js b/dist/js/constants.js index fe53999a..faf3bc3d 100644 --- a/dist/js/constants.js +++ b/dist/js/constants.js @@ -1,6 +1,39 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.HASH_TOLERANCE = exports.ATOMIC_COORD_UNITS = exports.units = exports.tolerance = exports.coefficients = void 0; +exports.ATOMIC_COORD_UNITS = exports.units = exports.tolerance = exports.coefficients = exports.HASH_TOLERANCE = exports.Coefficients = exports.Tolerance = exports.AtomicCoordinateUnits = exports.Units = void 0; +var Units; +(function (Units) { + Units["bohr"] = "bohr"; + Units["angstrom"] = "angstrom"; + Units["degree"] = "degree"; + Units["radian"] = "radian"; + Units["alat"] = "alat"; +})(Units || (exports.Units = Units = {})); +/** + * @summary Coordinates units for a material's basis. + */ +var AtomicCoordinateUnits; +(function (AtomicCoordinateUnits) { + AtomicCoordinateUnits["crystal"] = "crystal"; + AtomicCoordinateUnits["cartesian"] = "cartesian"; +})(AtomicCoordinateUnits || (exports.AtomicCoordinateUnits = AtomicCoordinateUnits = {})); +// in crystal coordinates +var Tolerance; +(function (Tolerance) { + Tolerance[Tolerance["length"] = 0.01] = "length"; + Tolerance[Tolerance["lengthAngstrom"] = 0.001] = "lengthAngstrom"; + Tolerance[Tolerance["pointsDistance"] = 0.001] = "pointsDistance"; +})(Tolerance || (exports.Tolerance = Tolerance = {})); +var Coefficients; +(function (Coefficients) { + Coefficients[Coefficients["EV_TO_RY"] = 0.0734986176] = "EV_TO_RY"; + Coefficients[Coefficients["BOHR_TO_ANGSTROM"] = 0.52917721092] = "BOHR_TO_ANGSTROM"; + Coefficients[Coefficients["ANGSTROM_TO_BOHR"] = 1.8897261245650618] = "ANGSTROM_TO_BOHR"; + Coefficients[Coefficients["EV_A_TO_RY_BOHR"] = 0.03889379346800142] = "EV_A_TO_RY_BOHR"; +})(Coefficients || (exports.Coefficients = Coefficients = {})); +// Only 3 digits will be considered for lattice and basis params on hashing +exports.HASH_TOLERANCE = 3; +// TODO: remove everything below this line exports.coefficients = { EV_TO_RY: 0.0734986176, BOHR_TO_ANGSTROM: 0.52917721092, @@ -27,8 +60,6 @@ exports.ATOMIC_COORD_UNITS = { crystal: "crystal", cartesian: "cartesian", }; -// Only 3 digits will be considered for lattice and basis params on hashing -exports.HASH_TOLERANCE = 3; exports.default = { coefficients: exports.coefficients, tolerance: exports.tolerance, diff --git a/dist/js/entity/in_memory.d.ts b/dist/js/entity/in_memory.d.ts index f9b0527c..8c7ef904 100644 --- a/dist/js/entity/in_memory.d.ts +++ b/dist/js/entity/in_memory.d.ts @@ -25,7 +25,7 @@ export declare class InMemoryEntity implements BaseInMemoryEntitySchema { static allowJsonSchemaTypesCoercing: boolean; static readonly jsonSchema?: JSONSchema; _json: AnyObject; - constructor(config?: {}); + constructor(config?: object | InMemoryEntity); prop(name: string, defaultValue: T): T; prop(name: string): T | undefined; /** diff --git a/dist/js/entity/in_memory.js b/dist/js/entity/in_memory.js index fc7ea313..c3540198 100644 --- a/dist/js/entity/in_memory.js +++ b/dist/js/entity/in_memory.js @@ -62,9 +62,14 @@ class InMemoryEntity { } constructor(config = {}) { this._json = {}; - this._json = this.constructor._isDeepCloneRequired - ? (0, clone_1.deepClone)(config) - : (0, clone_1.clone)(config); + if (config instanceof InMemoryEntity) { + this._json = config.toJSON(); + } + else { + this._json = this.constructor._isDeepCloneRequired + ? (0, clone_1.deepClone)(config) + : (0, clone_1.clone)(config); + } } /** * @summary Return a prop or the default diff --git a/dist/js/entity/index.d.ts b/dist/js/entity/index.d.ts index 2f14d49d..6fa0e96e 100644 --- a/dist/js/entity/index.d.ts +++ b/dist/js/entity/index.d.ts @@ -1,14 +1,9 @@ import { InMemoryEntity } from "./in_memory"; -import { ContextAndRenderFieldsMixin } from "./mixins/context"; -import { RuntimeContextFieldMixin } from "./mixins/context_runtime"; -import { FlowchartEntityMixin, FlowchartItemMixin } from "./mixins/flowchart"; -import { HasScopeTrackMixin } from "./mixins/props"; -import { RuntimeItemsMixin } from "./mixins/runtime_items"; -import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, NamedInMemoryEntity } from "./other"; +import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedInMemoryEntity } from "./other"; import { InMemoryEntitySet } from "./set"; import { ENTITY_SET_TYPES } from "./set/enums"; import { constructEntitySetFactoryByConfig } from "./set/factory"; import { InMemoryEntityInSetMixin, InMemoryEntitySetMixin } from "./set/mixins"; import { OrderedInMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin } from "./set/ordered/mixins"; import * as selectorsForEntitySet from "./set/selectors"; -export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasScopeTrackMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, }; +export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, }; diff --git a/dist/js/entity/index.js b/dist/js/entity/index.js index 3cc2997e..a5a3eb30 100644 --- a/dist/js/entity/index.js +++ b/dist/js/entity/index.js @@ -33,28 +33,14 @@ var __importStar = (this && this.__importStar) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.FlowchartItemMixin = exports.FlowchartEntityMixin = exports.ContextAndRenderFieldsMixin = exports.OrderedInMemoryEntityInSetMixin = exports.OrderedInMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = exports.InMemoryEntitySet = exports.RuntimeContextFieldMixin = exports.RuntimeItemsMixin = exports.HasScopeTrackMixin = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.DefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.InMemoryEntity = void 0; +exports.OrderedInMemoryEntityInSetMixin = exports.OrderedInMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = exports.InMemoryEntitySet = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.DefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.InMemoryEntity = void 0; const in_memory_1 = require("./in_memory"); Object.defineProperty(exports, "InMemoryEntity", { enumerable: true, get: function () { return in_memory_1.InMemoryEntity; } }); -const context_1 = require("./mixins/context"); -Object.defineProperty(exports, "ContextAndRenderFieldsMixin", { enumerable: true, get: function () { return context_1.ContextAndRenderFieldsMixin; } }); -const context_runtime_1 = require("./mixins/context_runtime"); -Object.defineProperty(exports, "RuntimeContextFieldMixin", { enumerable: true, get: function () { return context_runtime_1.RuntimeContextFieldMixin; } }); -const flowchart_1 = require("./mixins/flowchart"); -Object.defineProperty(exports, "FlowchartEntityMixin", { enumerable: true, get: function () { return flowchart_1.FlowchartEntityMixin; } }); -Object.defineProperty(exports, "FlowchartItemMixin", { enumerable: true, get: function () { return flowchart_1.FlowchartItemMixin; } }); -const props_1 = require("./mixins/props"); -Object.defineProperty(exports, "HasScopeTrackMixin", { enumerable: true, get: function () { return props_1.HasScopeTrackMixin; } }); -const runtime_items_1 = require("./mixins/runtime_items"); -Object.defineProperty(exports, "RuntimeItemsMixin", { enumerable: true, get: function () { return runtime_items_1.RuntimeItemsMixin; } }); const other_1 = require("./other"); Object.defineProperty(exports, "DefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.DefaultableInMemoryEntity; } }); Object.defineProperty(exports, "HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity; } }); Object.defineProperty(exports, "HasMetadataNamedDefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.HasMetadataNamedDefaultableInMemoryEntity; } }); Object.defineProperty(exports, "NamedDefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableInMemoryEntity; } }); -Object.defineProperty(exports, "NamedDefaultableRepetitionContextAndRenderInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableRepetitionContextAndRenderInMemoryEntity; } }); -Object.defineProperty(exports, "NamedDefaultableRepetitionImportantSettingsInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableRepetitionImportantSettingsInMemoryEntity; } }); -Object.defineProperty(exports, "NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity; } }); Object.defineProperty(exports, "NamedInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedInMemoryEntity; } }); const set_1 = require("./set"); Object.defineProperty(exports, "InMemoryEntitySet", { enumerable: true, get: function () { return set_1.InMemoryEntitySet; } }); diff --git a/dist/js/entity/mixins/ContextAndRenderFieldsMixin.d.ts b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.d.ts new file mode 100644 index 00000000..2e41bca9 --- /dev/null +++ b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.d.ts @@ -0,0 +1,15 @@ +import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; +import type { InMemoryEntity } from "../in_memory"; +export type Context = AnyObject; +export type ContextAndRenderFields = { + context?: Context; + updateContext(ctx: Context): void; + getPersistentContext(): Context | undefined; + updatePersistentContext(ctx: Context): void; + getCombinedContext(): Context; +}; +type AbstractBase = { + render(ctx: Context): void; +}; +export declare function contextAndRenderFieldsMixin(item: T): asserts item is T & ContextAndRenderFields; +export {}; diff --git a/dist/js/entity/mixins/ContextAndRenderFieldsMixin.js b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.js new file mode 100644 index 00000000..7fe3a434 --- /dev/null +++ b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.contextAndRenderFieldsMixin = contextAndRenderFieldsMixin; +function contextAndRenderFieldsMixin(item) { + // @ts-expect-error + const properties = { + updateContext(ctx) { + this.context = { ...this.context, ...ctx }; + }, + getPersistentContext() { + return this.prop("context"); + }, + updatePersistentContext(ctx) { + this.setProp("context", { ...ctx }); + }, + getCombinedContext() { + return { ...this.getPersistentContext(), ...this.context }; + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/DefaultableMixin.d.ts b/dist/js/entity/mixins/DefaultableMixin.d.ts index 17976383..ccc28681 100644 --- a/dist/js/entity/mixins/DefaultableMixin.d.ts +++ b/dist/js/entity/mixins/DefaultableMixin.d.ts @@ -1,13 +1,9 @@ -import type { Constructor } from "../../utils/types"; +import { type DefaultableSchemaMixin } from "../../generated/DefaultableSchemaMixin"; +import type { AbstractConstructor, Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function defaultableEntityMixin(item: T): InMemoryEntity & DefaultableInMemoryEntity; -export declare function defaultableEntityStaticMixin(Item: Constructor): DefaultableInMemoryStaticEntity & Constructor & Constructor & { - defaultConfig?: object | null; -}; -export type DefaultableInMemoryEntity = { - isDefault: boolean; -}; +export type Defaultable = DefaultableSchemaMixin; export type DefaultableInMemoryStaticEntity = { - createDefault: () => InMemoryEntity & DefaultableInMemoryEntity; + createDefault: () => InMemoryEntity & Defaultable; }; -export type DefaultableInMemoryEntityConstructor = Constructor & DefaultableInMemoryStaticEntity; +export type DefaultableInMemoryEntityConstructor = Constructor & DefaultableInMemoryStaticEntity; +export declare function defaultableEntityMixin(Item: AbstractConstructor): void; diff --git a/dist/js/entity/mixins/DefaultableMixin.js b/dist/js/entity/mixins/DefaultableMixin.js index afd926e4..af808ac6 100644 --- a/dist/js/entity/mixins/DefaultableMixin.js +++ b/dist/js/entity/mixins/DefaultableMixin.js @@ -2,20 +2,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultableEntityMixin = defaultableEntityMixin; -exports.defaultableEntityStaticMixin = defaultableEntityStaticMixin; -function defaultableEntityMixin(item) { - // @ts-expect-error - const properties = { - get isDefault() { - return this.prop("isDefault", false); - }, - set isDefault(isDefault) { - this.setProp("isDefault", isDefault); - }, - }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; -} +const DefaultableSchemaMixin_1 = require("../../generated/DefaultableSchemaMixin"); function defaultableEntityStaticMixin(Item) { // @ts-expect-error const staticProperties = { @@ -26,3 +13,7 @@ function defaultableEntityStaticMixin(Item) { Object.defineProperties(Item, Object.getOwnPropertyDescriptors(staticProperties)); return staticProperties; } +function defaultableEntityMixin(Item) { + (0, DefaultableSchemaMixin_1.defaultableSchemaMixin)(Item.prototype); + defaultableEntityStaticMixin(Item); +} diff --git a/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts b/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts index be7326c1..2aa7725a 100644 --- a/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts +++ b/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts @@ -1,9 +1,11 @@ import type { ConsistencyCheck } from "@mat3ra/esse/dist/js/types"; +import { type HasConsistencyChecksSchemaMixin } from "../../generated/HasConsistencyChecksSchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function hasConsistencyChecksMixin(item: T): InMemoryEntity & HasConsistencyChecksInMemoryEntity; -export type HasConsistencyChecksInMemoryEntity = { - consistencyChecks: ConsistencyCheck[]; +type HasConsistencyChecksProperties = { addConsistencyChecks: (array: ConsistencyCheck[]) => void; }; -export type HasConsistencyChecksInMemoryEntityConstructor = Constructor; +export type HasConsistencyChecks = HasConsistencyChecksSchemaMixin & HasConsistencyChecksProperties; +export type HasConsistencyChecksInMemoryEntityConstructor = Constructor; +export declare function hasConsistencyChecksMixin(item: T): asserts item is T & HasConsistencyChecks; +export {}; diff --git a/dist/js/entity/mixins/HasConsistencyChecksMixin.js b/dist/js/entity/mixins/HasConsistencyChecksMixin.js index f71cb3e9..1e4d7889 100644 --- a/dist/js/entity/mixins/HasConsistencyChecksMixin.js +++ b/dist/js/entity/mixins/HasConsistencyChecksMixin.js @@ -1,19 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasConsistencyChecksMixin = hasConsistencyChecksMixin; +const HasConsistencyChecksSchemaMixin_1 = require("../../generated/HasConsistencyChecksSchemaMixin"); function hasConsistencyChecksMixin(item) { + (0, HasConsistencyChecksSchemaMixin_1.hasConsistencyChecksSchemaMixin)(item); // @ts-expect-error const properties = { - get consistencyChecks() { - return this.prop("consistencyChecks", []); - }, - set consistencyChecks(array) { - this.setProp("consistencyChecks", array); - }, addConsistencyChecks(array) { this.consistencyChecks = [...(this.consistencyChecks || []), ...array]; }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; } diff --git a/dist/js/entity/mixins/HasDescriptionMixin.d.ts b/dist/js/entity/mixins/HasDescriptionMixin.d.ts index 520fe15a..8de49b3b 100644 --- a/dist/js/entity/mixins/HasDescriptionMixin.d.ts +++ b/dist/js/entity/mixins/HasDescriptionMixin.d.ts @@ -1,9 +1,3 @@ -import type { DescriptionSchema } from "@mat3ra/esse/dist/js/types"; -import type { Constructor } from "../../utils/types"; -import { InMemoryEntity } from "../in_memory"; -export declare function hasDescriptionMixin(item: T): InMemoryEntity & HasDescriptionInMemoryEntity; -export type HasDescriptionInMemoryEntity = { - description: string; - descriptionObject: DescriptionSchema["descriptionObject"]; -}; -export type HasDescriptionInMemoryEntityConstructor = Constructor; +import { type HasDescriptionSchemaMixin, hasDescriptionSchemaMixin } from "../../generated/HasDescriptionSchemaMixin"; +export type HasDescription = HasDescriptionSchemaMixin; +export declare const hasDescriptionMixin: typeof hasDescriptionSchemaMixin; diff --git a/dist/js/entity/mixins/HasDescriptionMixin.js b/dist/js/entity/mixins/HasDescriptionMixin.js index ce240947..c535ac9e 100644 --- a/dist/js/entity/mixins/HasDescriptionMixin.js +++ b/dist/js/entity/mixins/HasDescriptionMixin.js @@ -1,22 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.hasDescriptionMixin = hasDescriptionMixin; -function hasDescriptionMixin(item) { - // @ts-expect-error - const properties = { - get description() { - return this.prop("description", ""); - }, - set description(string) { - this.setProp("description", string); - }, - get descriptionObject() { - return this.prop("descriptionObject"); - }, - set descriptionObject(obj) { - this.setProp("descriptionObject", obj); - }, - }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; -} +exports.hasDescriptionMixin = void 0; +const HasDescriptionSchemaMixin_1 = require("../../generated/HasDescriptionSchemaMixin"); +exports.hasDescriptionMixin = HasDescriptionSchemaMixin_1.hasDescriptionSchemaMixin; diff --git a/dist/js/entity/mixins/HasMetadataMixin.d.ts b/dist/js/entity/mixins/HasMetadataMixin.d.ts index 097d45aa..49273f34 100644 --- a/dist/js/entity/mixins/HasMetadataMixin.d.ts +++ b/dist/js/entity/mixins/HasMetadataMixin.d.ts @@ -1,8 +1,11 @@ +import type { MetadataSchema } from "@mat3ra/esse/dist/js/types"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function hasMetadataMixin(item: T): InMemoryEntity & HasMetadataInMemoryEntity; -export type HasMetadataInMemoryEntity = { - metadata: object; - updateMetadata: (object: object) => void; +type Metadata = MetadataSchema["metadata"]; +export type HasMetadata = { + metadata?: T; + updateMetadata: (object: Partial) => void; }; -export type HasMetadataInMemoryEntityConstructor = Constructor; +export type HasMetadataInMemoryEntityConstructor = Constructor>; +export declare function hasMetadataMixin(item: T): asserts item is T & HasMetadata; +export {}; diff --git a/dist/js/entity/mixins/HasMetadataMixin.js b/dist/js/entity/mixins/HasMetadataMixin.js index a513f28c..cb9338b4 100644 --- a/dist/js/entity/mixins/HasMetadataMixin.js +++ b/dist/js/entity/mixins/HasMetadataMixin.js @@ -1,19 +1,21 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasMetadataMixin = hasMetadataMixin; -function hasMetadataMixin(item) { +function hasMetadataPropertiesMixin(item) { // @ts-expect-error const properties = { get metadata() { - return this.prop("metadata", {}); + return this.prop("metadata"); }, - set metadata(object) { - this.setProp("metadata", object); + set metadata(value) { + this.setProp("metadata", value); }, updateMetadata(object) { - this.metadata = { ...this.metadata, ...object }; + this.setProp("metadata", { ...this.metadata, ...object }); }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; +} +function hasMetadataMixin(item) { + hasMetadataPropertiesMixin(item); } diff --git a/dist/js/entity/mixins/HashedEntityMixin.d.ts b/dist/js/entity/mixins/HashedEntityMixin.d.ts new file mode 100644 index 00000000..178b857b --- /dev/null +++ b/dist/js/entity/mixins/HashedEntityMixin.d.ts @@ -0,0 +1,8 @@ +import type { Constructor } from "../../utils/types"; +import { InMemoryEntity } from "../in_memory"; +export type HashedEntity = { + calculateHash(): string; + getHashObject?(): object; +}; +export type HashedInMemoryEntityConstructor = Constructor; +export declare function hashedEntityMixin(item: T): asserts item is T & HashedEntity; diff --git a/dist/js/entity/mixins/HashedEntityMixin.js b/dist/js/entity/mixins/HashedEntityMixin.js new file mode 100644 index 00000000..d365abc1 --- /dev/null +++ b/dist/js/entity/mixins/HashedEntityMixin.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hashedEntityMixin = hashedEntityMixin; +const hash_1 = require("../../utils/hash"); +function hashedEntityMixin(item) { + // @ts-expect-error + const properties = { + /** + * @summary Calculates hash based on meaningful fields and unit-specific fields. Unit-specific fields are + * separated into _typeSpecificHash function which can be overwritten by child classes. + * head and next are also important but not considered since they are included in subworkflow hash. + */ + calculateHash() { + var _a, _b; + return (0, hash_1.calculateHashFromObject)((_b = (_a = this.getHashObject) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {}); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/ImportantSettingsProviderMixin.d.ts b/dist/js/entity/mixins/ImportantSettingsProviderMixin.d.ts new file mode 100644 index 00000000..9cb5ce49 --- /dev/null +++ b/dist/js/entity/mixins/ImportantSettingsProviderMixin.d.ts @@ -0,0 +1,17 @@ +import type { Constructor } from "../../utils/types"; +import type { InMemoryEntity } from "../in_memory"; +export interface ContextProvider { + domain?: string; +} +export type ImportantSettingsProvider = { + important: object; + setImportant(key: string, value: unknown): void; + importantSettingsProviders: ContextProvider[]; + isImportantEdited: boolean | undefined; +}; +type AbstractBase = { + contextProviders: ContextProvider[]; +}; +export type ImportantSettingsProviderInMemoryEntityConstructor = Constructor; +export declare function importantSettingsProviderMixin(item: T): asserts item is T & ImportantSettingsProvider; +export {}; diff --git a/dist/js/entity/mixins/ImportantSettingsProviderMixin.js b/dist/js/entity/mixins/ImportantSettingsProviderMixin.js new file mode 100644 index 00000000..b4477d54 --- /dev/null +++ b/dist/js/entity/mixins/ImportantSettingsProviderMixin.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.importantSettingsProviderMixin = importantSettingsProviderMixin; +const clone_1 = require("../../utils/clone"); +function importantSettingsProviderMixin(item) { + // @ts-expect-error + const properties = { + get important() { + return (0, clone_1.deepClone)(this._json.important || {}); + }, + setImportant(key, value) { + this.setProp("important", { [key]: value }); + }, + get importantSettingsProviders() { + return this.contextProviders.filter((p) => p.domain === "important"); + }, + get isImportantEdited() { + return this.prop("important.isEdited"); + }, + set isImportantEdited(bool) { + this.setProp("important", Object.assign(this.important, { isEdited: bool })); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/NamedEntityMixin.d.ts b/dist/js/entity/mixins/NamedEntityMixin.d.ts index 4ffdc6b8..e11a74f2 100644 --- a/dist/js/entity/mixins/NamedEntityMixin.d.ts +++ b/dist/js/entity/mixins/NamedEntityMixin.d.ts @@ -1,8 +1,10 @@ +import { type NamedEntitySchemaMixin } from "../../generated/NamedEntitySchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function namedEntityMixin(item: T): InMemoryEntity & NamedInMemoryEntity; -export type NamedInMemoryEntity = { - name: string; +type NamedEntityProperties = { setName: (name: string) => void; }; -export type NamedInMemoryEntityConstructor = Constructor; +export type NamedEntity = NamedEntitySchemaMixin & NamedEntityProperties; +export type NamedInMemoryEntityConstructor = Constructor; +export declare function namedEntityMixin(item: T): asserts item is T & NamedEntity; +export {}; diff --git a/dist/js/entity/mixins/NamedEntityMixin.js b/dist/js/entity/mixins/NamedEntityMixin.js index 1b153663..8884807d 100644 --- a/dist/js/entity/mixins/NamedEntityMixin.js +++ b/dist/js/entity/mixins/NamedEntityMixin.js @@ -1,19 +1,17 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.namedEntityMixin = namedEntityMixin; -function namedEntityMixin(item) { +const NamedEntitySchemaMixin_1 = require("../../generated/NamedEntitySchemaMixin"); +function namedEntityPropertiesMixin(item) { // @ts-expect-error const properties = { - get name() { - return this.prop("name", ""); - }, - set name(name) { - this.setProp("name", name); - }, setName(name) { this.setProp("name", name); }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; +} +function namedEntityMixin(item) { + (0, NamedEntitySchemaMixin_1.namedEntitySchemaMixin)(item); + namedEntityPropertiesMixin(item); } diff --git a/dist/js/entity/mixins/RuntimeItemsMixin.d.ts b/dist/js/entity/mixins/RuntimeItemsMixin.d.ts index 91521250..9bf97071 100644 --- a/dist/js/entity/mixins/RuntimeItemsMixin.d.ts +++ b/dist/js/entity/mixins/RuntimeItemsMixin.d.ts @@ -1,35 +1,14 @@ -import type { NameResultSchema } from "@mat3ra/esse/dist/js/types"; +import { type RuntimeItemsSchemaMixin } from "../../generated/RuntimeItemsSchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare enum ItemKey { - results = "results", - monitors = "monitors", - preProcessors = "preProcessors", - postProcessors = "postProcessors" -} -export type BaseRuntimeItemsInMemoryEntity = InMemoryEntity & { - _json: { - results?: NameResultSchema[]; - monitors?: NameResultSchema[]; - preProcessors?: NameResultSchema[]; - postProcessors?: NameResultSchema[]; - }; - defaultResults?: NameResultSchema[]; - defaultMonitors?: NameResultSchema[]; - defaultPreProcessors?: NameResultSchema[]; - defaultPostProcessors?: NameResultSchema[]; -}; -export declare function runtimeItemsMixin(item: BaseRuntimeItemsInMemoryEntity): void; -export type RuntimeItemsInMemoryEntity = { - results: NameResultSchema[]; - monitors: NameResultSchema[]; - preProcessors: NameResultSchema[]; - postProcessors: NameResultSchema[]; +type RuntimeItemsProperties = { hashObjectFromRuntimeItems: { - results: NameResultSchema[]; - preProcessors: NameResultSchema[]; - postProcessors: NameResultSchema[]; + results: RuntimeItemsSchemaMixin["results"]; + preProcessors: RuntimeItemsSchemaMixin["preProcessors"]; + postProcessors: RuntimeItemsSchemaMixin["postProcessors"]; }; }; -export type RuntimeItemsInMemoryEntityConstructor = Constructor; -export default function RuntimeItemsMixin>(superclass: S): S & RuntimeItemsInMemoryEntityConstructor; +export type RuntimeItems = RuntimeItemsSchemaMixin & RuntimeItemsProperties; +export type RuntimeItemsInMemoryEntityConstructor = Constructor; +export declare function runtimeItemsMixin(item: T): asserts item is T & RuntimeItems; +export {}; diff --git a/dist/js/entity/mixins/RuntimeItemsMixin.js b/dist/js/entity/mixins/RuntimeItemsMixin.js index 1634358b..28ebc9cf 100644 --- a/dist/js/entity/mixins/RuntimeItemsMixin.js +++ b/dist/js/entity/mixins/RuntimeItemsMixin.js @@ -1,41 +1,10 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.ItemKey = void 0; exports.runtimeItemsMixin = runtimeItemsMixin; -exports.default = RuntimeItemsMixin; -const object_1 = require("../../utils/object"); -var ItemKey; -(function (ItemKey) { - ItemKey["results"] = "results"; - ItemKey["monitors"] = "monitors"; - ItemKey["preProcessors"] = "preProcessors"; - ItemKey["postProcessors"] = "postProcessors"; -})(ItemKey || (exports.ItemKey = ItemKey = {})); -/* - * @summary Contains runtime items: results, monitors, pre/postProcessors - * Is meant to work with Entity, InMemoryEntity b/c of `prop` extraction from `_json`. - */ -function runtimeItemsMixin(item) { - // @ts-expect-error - this is a hack to get the properties of the item +const RuntimeItemsSchemaMixin_1 = require("../../generated/RuntimeItemsSchemaMixin"); +function runtimeItemsPropertiesMixin(item) { + // @ts-expect-error const properties = { - get results() { - var _a; - return this.prop("results", (_a = this.defaultResults) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, - get monitors() { - var _a; - return this.prop("monitors", (_a = this.defaultMonitors) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, - get preProcessors() { - var _a; - // TODO: safeMakeObject could return null. Should we throw an error here? - return this.prop("preProcessors", (_a = this.defaultPreProcessors) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, - get postProcessors() { - var _a; - // TODO: safeMakeObject could return null. Should we throw an error here? - return this.prop("postProcessors", (_a = this.defaultPostProcessors) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, get hashObjectFromRuntimeItems() { return { results: this.results, @@ -46,9 +15,7 @@ function runtimeItemsMixin(item) { }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); } -function RuntimeItemsMixin(superclass) { - class RuntimeItemsMixin extends superclass { - } - runtimeItemsMixin(RuntimeItemsMixin.prototype); - return RuntimeItemsMixin; +function runtimeItemsMixin(item) { + (0, RuntimeItemsSchemaMixin_1.runtimeItemsSchemaMixin)(item); + runtimeItemsPropertiesMixin(item); } diff --git a/dist/js/entity/mixins/TaggableMixin.d.ts b/dist/js/entity/mixins/TaggableMixin.d.ts index 55e7b0aa..a8b7cff5 100644 --- a/dist/js/entity/mixins/TaggableMixin.d.ts +++ b/dist/js/entity/mixins/TaggableMixin.d.ts @@ -1,8 +1,10 @@ +import { type TaggableSchemaMixin } from "../../generated/TaggableSchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function taggableMixin(item: T): InMemoryEntity & TaggableInMemoryEntity; -export type TaggableInMemoryEntity = { - tags: string[]; +type TaggableProperties = { setTags: (array: string[]) => void; }; -export type TaggableInMemoryEntityConstructor = Constructor; +export type Taggable = TaggableSchemaMixin & TaggableProperties; +export type TaggableInMemoryEntityConstructor = Constructor; +export declare function taggableMixin(item: T): asserts item is T & Taggable; +export {}; diff --git a/dist/js/entity/mixins/TaggableMixin.js b/dist/js/entity/mixins/TaggableMixin.js index eb3df3e6..a8bf3ab3 100644 --- a/dist/js/entity/mixins/TaggableMixin.js +++ b/dist/js/entity/mixins/TaggableMixin.js @@ -1,19 +1,17 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.taggableMixin = taggableMixin; -function taggableMixin(item) { +const TaggableSchemaMixin_1 = require("../../generated/TaggableSchemaMixin"); +function taggablePropertiesMixin(item) { // @ts-expect-error const properties = { - get tags() { - return this.prop("tags", []); - }, - set tags(array) { - this.setProp("tags", array); - }, setTags(array) { this.tags = array.filter((value, index, self) => self.indexOf(value) === index); }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; +} +function taggableMixin(item) { + (0, TaggableSchemaMixin_1.taggableSchemaMixin)(item); + taggablePropertiesMixin(item); } diff --git a/dist/js/entity/mixins/context.d.ts b/dist/js/entity/mixins/context.d.ts deleted file mode 100644 index 64e2333b..00000000 --- a/dist/js/entity/mixins/context.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; -import { InMemoryEntityConstructor } from "../in_memory"; -export type Context = AnyObject; -export declare function ContextAndRenderFieldsMixin(superclass: T): { - new (...params: any[]): { - _context: Context; - context: AnyObject; - updateContext(ctx?: {}, executeRender?: boolean): void; - getPersistentContext(): object | undefined; - updatePersistentContext(ctx?: object): void; - getCombinedContext(): { - [x: string]: unknown; - }; - render(_context?: AnyObject): void; - _json: AnyObject; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): AnyObject; - toJSONSafe(exclude?: string[]): AnyObject; - toJSONQuick(exclude?: string[]): AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: AnyObject): AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & T; -export interface ContextProvider { - domain: string; -} -export declare function DomainContextProviderMixin(superclass: T): { - new (...args: any[]): { - _contextProviders: ContextProvider[]; - readonly contextProviders: ContextProvider[]; - _json: AnyObject; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): AnyObject; - toJSONSafe(exclude?: string[]): AnyObject; - toJSONQuick(exclude?: string[]): AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: AnyObject): AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & T; -export declare function ImportantSettingsProviderMixin(superclass: T): { - new (...args: any[]): { - readonly important: any; - setImportant(key: string, value: unknown): void; - readonly importantSettingsProviders: ContextProvider[]; - isImportantEdited: boolean | undefined; - _contextProviders: ContextProvider[]; - readonly contextProviders: ContextProvider[]; - _json: AnyObject; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): AnyObject; - toJSONSafe(exclude?: string[]): AnyObject; - toJSONQuick(exclude?: string[]): AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: AnyObject): AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & T; diff --git a/dist/js/entity/mixins/context.js b/dist/js/entity/mixins/context.js deleted file mode 100644 index 76d2bd5b..00000000 --- a/dist/js/entity/mixins/context.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ContextAndRenderFieldsMixin = ContextAndRenderFieldsMixin; -exports.DomainContextProviderMixin = DomainContextProviderMixin; -exports.ImportantSettingsProviderMixin = ImportantSettingsProviderMixin; -const clone_1 = require("../../utils/clone"); -function ContextAndRenderFieldsMixin(superclass) { - return class extends superclass { - /** - * @see https://stackoverflow.com/questions/64396668/why-do-typescript-mixins-require-a-constructor-with-a-single-rest-parameter-any - * */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...params) { - super(...params); - this._context = params[0].context || {}; - } - // in-memory, or "volatile" context that is reset when the `parent` object is destroyed - get context() { - return this._context; - } - set context(newContext) { - this._context = newContext; - } - updateContext(ctx = {}, executeRender = false) { - this._context = { ...this.context, ...ctx }; - if (executeRender) - this.render(); - } - // to get "persistent" context, that is stored in database and further should be provided to constructor - // when the `parent` object is re-created - getPersistentContext() { - return this.prop("context"); - } - // to make context persistent in `_json` - updatePersistentContext(ctx = {}) { - this.setProp("context", { ...ctx }); - } - // to get persistent and volatile context combined - getCombinedContext() { - return { ...this.getPersistentContext(), ...this.context }; - } - // override in subclasses - // eslint-disable-next-line @typescript-eslint/no-unused-vars - render(_context = this.context) { - throw new Error("RenderInitMixin: render not implemented in derived class"); - } - }; -} -/* - * @summary Handles logic for domain-specific context, eg. "important settings". - * Important settings are stored inside "important" property and have context providers associated with it. - */ -function DomainContextProviderMixin(superclass) { - return class extends superclass { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...args) { - super(...args); - this._contextProviders = []; - } - get contextProviders() { - // override in children - return this._contextProviders; - } - }; -} -function ImportantSettingsProviderMixin(superclass) { - return class extends DomainContextProviderMixin(superclass) { - get important() { - return (0, clone_1.deepClone)(this._json.important || {}); - } - setImportant(key, value) { - this.setProp("important", { [key]: value }); - } - get importantSettingsProviders() { - return this.contextProviders.filter((p) => p.domain === "important"); - } - get isImportantEdited() { - return this.prop("important.isEdited"); - } - set isImportantEdited(bool) { - this.setProp("important", Object.assign(this.important, { isEdited: bool })); - } - }; -} diff --git a/dist/js/entity/mixins/context_runtime.d.ts b/dist/js/entity/mixins/context_runtime.d.ts deleted file mode 100644 index 432f0a1a..00000000 --- a/dist/js/entity/mixins/context_runtime.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { JobBaseSchema } from "@mat3ra/esse/dist/js/types"; -import { InMemoryEntityConstructor } from "../in_memory"; -type RuntimeContext = Required["runtimeContext"]; -export declare function RuntimeContextFieldMixin(superclass: T): { - new (...args: any[]): { - _runtimeContext: RuntimeContext; - runtimeContext: RuntimeContext; - updateRuntimeContext(ctx?: RuntimeContext): void; - toJSON(exclude?: string[]): { - runtimeContext: {}; - }; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & T; -export {}; diff --git a/dist/js/entity/mixins/context_runtime.js b/dist/js/entity/mixins/context_runtime.js deleted file mode 100644 index 67da5130..00000000 --- a/dist/js/entity/mixins/context_runtime.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RuntimeContextFieldMixin = RuntimeContextFieldMixin; -function RuntimeContextFieldMixin(superclass) { - return class extends superclass { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...args) { - super(...args); - const config = args[0]; - this._runtimeContext = config.runtimeContext || {}; - } - // in-memory, or "volatile" runtimeContext that is reset when the `parent` object is destroyed - get runtimeContext() { - return this._runtimeContext; - } - set runtimeContext(newContext) { - this._runtimeContext = newContext; - } - updateRuntimeContext(ctx = {}) { - this.runtimeContext = Object.assign(this._runtimeContext, ctx); - } - toJSON(exclude = []) { - return { ...super.toJSON(exclude), runtimeContext: this._runtimeContext }; - } - }; -} diff --git a/dist/js/entity/mixins/repetition.d.ts b/dist/js/entity/mixins/repetition.d.ts deleted file mode 100644 index 60d71b43..00000000 --- a/dist/js/entity/mixins/repetition.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { InMemoryEntityConstructor } from "../in_memory"; -export interface HasRepetition { - setRepetition: (repetition: number) => void; -} -type Units = HasRepetition[]; -type Workflows = HasRepetition[]; -type Subworkflows = HasRepetition[]; -export declare function HasRepetitionMixin(superclass: T): { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: Units; - workflows: Workflows; - subworkflows: Subworkflows; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & T; -export {}; diff --git a/dist/js/entity/mixins/repetition.js b/dist/js/entity/mixins/repetition.js deleted file mode 100644 index cb93c0ad..00000000 --- a/dist/js/entity/mixins/repetition.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.HasRepetitionMixin = HasRepetitionMixin; -function HasRepetitionMixin(superclass) { - return class extends superclass { - constructor() { - super(...arguments); - this._repetition = 0; - this._totalRepetitions = 0; - } - get repetition() { - return this._repetition || 0; - } - // TODO: make abstract and move to workflow/subworkflow classes? - setRepetition(repetition) { - this._repetition = repetition; - if (["Subworkflow", "Workflow"].find((n) => this.constructor.name === n)) { - this.units.forEach((u) => u.setRepetition(repetition)); - } - if (this.constructor.name === "Workflow") { - this.subworkflows.forEach((sw) => sw.setRepetition(repetition)); - this.workflows.forEach((wf) => wf.setRepetition(repetition)); - } - } - get totalRepetitions() { - return this._totalRepetitions || 1; - } - setTotalRepetitions(totalRepetition) { - this._totalRepetitions = totalRepetition; - } - }; -} diff --git a/dist/js/entity/mixins/runtime_items.d.ts b/dist/js/entity/mixins/runtime_items.d.ts deleted file mode 100644 index edb54feb..00000000 --- a/dist/js/entity/mixins/runtime_items.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; -import { NameResultSchema, RuntimeItemSchema } from "@mat3ra/esse/dist/js/types"; -import type { Constructor } from "src/js/utils/types"; -import { InMemoryEntityConstructor } from "../in_memory"; -import RuntimeItemsMixin, { type BaseRuntimeItemsInMemoryEntity, ItemKey } from "./RuntimeItemsMixin"; -export { RuntimeItemsMixin, ItemKey }; -export interface RuntimeItemsUILogicJSON extends AnyObject { - results?: NameResultSchema[]; - monitors?: NameResultSchema[]; - preProcessors?: NameResultSchema[]; - postProcessors?: NameResultSchema[]; -} -export declare function RuntimeItemsUILogicMixin>(superclass: T): { - new (...params: any): { - _json: RuntimeItemsUILogicJSON; - getDefaultsByKey(key: ItemKey): NameResultSchema[] | undefined; - setRuntimeItemsToDefaultValues(): void; - /** - * @summary Must pass config for subclasses to override and use initialization logic - * @private - */ - _initRuntimeItems(keys: ItemKey[], _config: object): void; - _addRuntimeItem(key: ItemKey | undefined, config: RuntimeItemSchema): void; - _removeRuntimeItem(key: ItemKey | undefined, config: RuntimeItemSchema): void; - _removeRuntimeItemByName(key: ItemKey, name: string): void; - _toggleRuntimeItem(key: ItemKey | undefined, data: RuntimeItemSchema, isAdding: boolean): void; - toggleResult(data: RuntimeItemSchema, isAdding: boolean): void; - toggleMonitor(data: RuntimeItemSchema, isAdding: boolean): void; - togglePreProcessor(data: RuntimeItemSchema, isAdding: boolean): void; - togglePostProcessor(data: RuntimeItemSchema, isAdding: boolean): void; - readonly resultNames: string[]; - readonly monitorNames: string[]; - readonly postProcessorNames: string[]; - readonly preProcessorNames: string[]; - getResultByName(name: string): NameResultSchema | undefined; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): AnyObject; - toJSONSafe(exclude?: string[]): AnyObject; - toJSONQuick(exclude?: string[]): AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: AnyObject): AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - defaultResults?: NameResultSchema[]; - defaultMonitors?: NameResultSchema[]; - defaultPreProcessors?: NameResultSchema[]; - defaultPostProcessors?: NameResultSchema[]; - results: NameResultSchema[]; - monitors: NameResultSchema[]; - preProcessors: NameResultSchema[]; - postProcessors: NameResultSchema[]; - hashObjectFromRuntimeItems: { - results: NameResultSchema[]; - preProcessors: NameResultSchema[]; - postProcessors: NameResultSchema[]; - }; - }; -} & T; -export declare function RuntimeItemsUIAllowedMixin(superclass: T): { - new (...args: any[]): { - readonly allowedResults: never[]; - readonly allowedMonitors: never[]; - readonly allowedPostProcessors: never[]; - _json: AnyObject; - prop(name: string, defaultValue: T_1): T_1; - prop(name: string): T_1 | undefined; - requiredProp(name: string): T_1; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): AnyObject; - toJSONSafe(exclude?: string[]): AnyObject; - toJSONQuick(exclude?: string[]): AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: AnyObject): AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & T; diff --git a/dist/js/entity/mixins/runtime_items.js b/dist/js/entity/mixins/runtime_items.js deleted file mode 100644 index 83e5fe83..00000000 --- a/dist/js/entity/mixins/runtime_items.js +++ /dev/null @@ -1,157 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || (function () { - var ownKeys = function(o) { - ownKeys = Object.getOwnPropertyNames || function (o) { - var ar = []; - for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; - return ar; - }; - return ownKeys(o); - }; - return function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); - __setModuleDefault(result, mod); - return result; - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ItemKey = exports.RuntimeItemsMixin = void 0; -exports.RuntimeItemsUILogicMixin = RuntimeItemsUILogicMixin; -exports.RuntimeItemsUIAllowedMixin = RuntimeItemsUIAllowedMixin; -const object_1 = require("../../utils/object"); -const RuntimeItemsMixin_1 = __importStar(require("./RuntimeItemsMixin")); -exports.RuntimeItemsMixin = RuntimeItemsMixin_1.default; -Object.defineProperty(exports, "ItemKey", { enumerable: true, get: function () { return RuntimeItemsMixin_1.ItemKey; } }); -const allKeys = [ - RuntimeItemsMixin_1.ItemKey.results, - RuntimeItemsMixin_1.ItemKey.monitors, - RuntimeItemsMixin_1.ItemKey.postProcessors, - RuntimeItemsMixin_1.ItemKey.preProcessors, -]; -function RuntimeItemsUILogicMixin(superclass) { - return class extends (0, RuntimeItemsMixin_1.default)(superclass) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...params) { - super(...params); - const config = params[0]; - this._initRuntimeItems(allKeys, config); - } - getDefaultsByKey(key) { - if (key === RuntimeItemsMixin_1.ItemKey.results) { - return this.defaultResults; - } - if (key === RuntimeItemsMixin_1.ItemKey.monitors) { - return this.defaultMonitors; - } - if (key === RuntimeItemsMixin_1.ItemKey.preProcessors) { - return this.defaultPreProcessors; - } - return this.defaultPostProcessors; - } - setRuntimeItemsToDefaultValues() { - allKeys.forEach((name) => this.setProp(name, this.getDefaultsByKey(name))); - } - /** - * @summary Must pass config for subclasses to override and use initialization logic - * @private - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _initRuntimeItems(keys, _config) { - // keeping this separate from constructor so that it can be overridden in mixing (eg. in `ExecutionUnit`) - // eslint-disable-next-line @typescript-eslint/no-this-alias - const me = this; - keys.forEach((key) => { - if (!me._json[key]) { - me._json[key] = me.getDefaultsByKey(key); - } - }); - } - // eslint-disable-next-line default-param-last - _addRuntimeItem(key = RuntimeItemsMixin_1.ItemKey.results, config) { - const runtimeItems = this._json[key]; - if (!runtimeItems) { - throw new Error("not found"); - } - runtimeItems.push((0, object_1.safeMakeObject)(config)); - } - // eslint-disable-next-line default-param-last - _removeRuntimeItem(key = RuntimeItemsMixin_1.ItemKey.results, config) { - const newConfig = (0, object_1.safeMakeObject)(config); - this._removeRuntimeItemByName(key, (newConfig === null || newConfig === void 0 ? void 0 : newConfig.name) || ""); - } - _removeRuntimeItemByName(key, name) { - this._json[key] = this._json[key].filter((x) => x.name !== name); - } - _toggleRuntimeItem( - // eslint-disable-next-line default-param-last - key = RuntimeItemsMixin_1.ItemKey.results, data, isAdding) { - if (isAdding) { - this._addRuntimeItem(key, data); - } - else { - this._removeRuntimeItem(key, data); - } - } - toggleResult(data, isAdding) { - this._toggleRuntimeItem(RuntimeItemsMixin_1.ItemKey.results, data, isAdding); - } - toggleMonitor(data, isAdding) { - this._toggleRuntimeItem(RuntimeItemsMixin_1.ItemKey.monitors, data, isAdding); - } - togglePreProcessor(data, isAdding) { - this._toggleRuntimeItem(RuntimeItemsMixin_1.ItemKey.preProcessors, data, isAdding); - } - togglePostProcessor(data, isAdding) { - this._toggleRuntimeItem(RuntimeItemsMixin_1.ItemKey.postProcessors, data, isAdding); - } - get resultNames() { - return this.results.map((r) => { - return r && r.name; - }); - } - get monitorNames() { - return this.monitors.map((r) => r === null || r === void 0 ? void 0 : r.name); - } - get postProcessorNames() { - return this.postProcessors.map((r) => r === null || r === void 0 ? void 0 : r.name); - } - get preProcessorNames() { - return this.preProcessors.map((r) => r === null || r === void 0 ? void 0 : r.name); - } - getResultByName(name) { - return this.results.find((r) => (r === null || r === void 0 ? void 0 : r.name) === name); - } - }; -} -// "Placeholder" mixin. Used to indicate the presence of the fields in parent class. -function RuntimeItemsUIAllowedMixin(superclass) { - return class extends superclass { - get allowedResults() { - return []; - } - get allowedMonitors() { - return []; - } - get allowedPostProcessors() { - return []; - } - }; -} diff --git a/dist/js/entity/other.d.ts b/dist/js/entity/other.d.ts index 2632604d..73c0ac32 100644 --- a/dist/js/entity/other.d.ts +++ b/dist/js/entity/other.d.ts @@ -7,7 +7,7 @@ type DefaultableBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstruc type NamedBase = typeof InMemoryEntity & NamedInMemoryEntityConstructor; type NamedDefaultableBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstructor & NamedInMemoryEntityConstructor; type HasMetadataNamedDefaultableBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstructor & NamedInMemoryEntityConstructor & HasMetadataInMemoryEntityConstructor; -type HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntityBase = typeof HasMetadataNamedDefaultableInMemoryEntity & HasConsistencyChecksInMemoryEntityConstructor; +type HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntityBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstructor & NamedInMemoryEntityConstructor & HasConsistencyChecksInMemoryEntityConstructor; declare const DefaultableInMemoryEntity_base: DefaultableBase; export declare class DefaultableInMemoryEntity extends DefaultableInMemoryEntity_base { } @@ -23,398 +23,4 @@ export declare class HasMetadataNamedDefaultableInMemoryEntity extends HasMetada declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base: HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntityBase; export declare class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base { } -export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: { - new (...args: any[]): { - readonly important: any; - setImportant(key: string, value: unknown): void; - readonly importantSettingsProviders: import("./mixins/context").ContextProvider[]; - isImportantEdited: boolean | undefined; - _contextProviders: import("./mixins/context").ContextProvider[]; - readonly contextProviders: import("./mixins/context").ContextProvider[]; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: import("./mixins/repetition").HasRepetition[]; - workflows: import("./mixins/repetition").HasRepetition[]; - subworkflows: import("./mixins/repetition").HasRepetition[]; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & typeof NamedDefaultableInMemoryEntity; -export declare const NamedDefaultableRepetitionContextAndRenderInMemoryEntity: { - new (...params: any[]): { - _context: import("./mixins/context").Context; - context: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - updateContext(ctx?: {}, executeRender?: boolean): void; - getPersistentContext(): object | undefined; - updatePersistentContext(ctx?: object): void; - getCombinedContext(): { - [x: string]: unknown; - }; - render(_context?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: import("./mixins/repetition").HasRepetition[]; - workflows: import("./mixins/repetition").HasRepetition[]; - subworkflows: import("./mixins/repetition").HasRepetition[]; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & typeof NamedDefaultableInMemoryEntity; -export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity: { - new (...args: any[]): { - getHashObject(): {}; - calculateHash(): string; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...params: any[]): { - _context: import("./mixins/context").Context; - context: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - updateContext(ctx?: {}, executeRender?: boolean): void; - getPersistentContext(): object | undefined; - updatePersistentContext(ctx?: object): void; - getCombinedContext(): { - [x: string]: unknown; - }; - render(_context?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - readonly important: any; - setImportant(key: string, value: unknown): void; - readonly importantSettingsProviders: import("./mixins/context").ContextProvider[]; - isImportantEdited: boolean | undefined; - _contextProviders: import("./mixins/context").ContextProvider[]; - readonly contextProviders: import("./mixins/context").ContextProvider[]; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - readonly allowedResults: never[]; - readonly allowedMonitors: never[]; - readonly allowedPostProcessors: never[]; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...params: any): { - _json: import("./mixins/runtime_items").RuntimeItemsUILogicJSON; - getDefaultsByKey(key: import("./mixins/RuntimeItemsMixin").ItemKey): import("@mat3ra/esse/dist/js/types").NameResultSchema[] | undefined; - setRuntimeItemsToDefaultValues(): void; - _initRuntimeItems(keys: import("./mixins/RuntimeItemsMixin").ItemKey[], _config: object): void; - _addRuntimeItem(key: import("./mixins/RuntimeItemsMixin").ItemKey | undefined, config: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema): void; - _removeRuntimeItem(key: import("./mixins/RuntimeItemsMixin").ItemKey | undefined, config: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema): void; - _removeRuntimeItemByName(key: import("./mixins/RuntimeItemsMixin").ItemKey, name: string): void; - _toggleRuntimeItem(key: import("./mixins/RuntimeItemsMixin").ItemKey | undefined, data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - toggleResult(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - toggleMonitor(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - togglePreProcessor(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - togglePostProcessor(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - readonly resultNames: string[]; - readonly monitorNames: string[]; - readonly postProcessorNames: string[]; - readonly preProcessorNames: string[]; - getResultByName(name: string): import("@mat3ra/esse/dist/js/types").NameResultSchema | undefined; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - defaultResults?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - defaultMonitors?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - defaultPreProcessors?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - defaultPostProcessors?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - results: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - monitors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - preProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - postProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - hashObjectFromRuntimeItems: { - results: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - preProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - postProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - }; - }; -} & { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: import("./mixins/repetition").HasRepetition[]; - workflows: import("./mixins/repetition").HasRepetition[]; - subworkflows: import("./mixins/repetition").HasRepetition[]; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & typeof NamedDefaultableInMemoryEntity; export {}; diff --git a/dist/js/entity/other.js b/dist/js/entity/other.js index 7ef78a29..c37b2165 100644 --- a/dist/js/entity/other.js +++ b/dist/js/entity/other.js @@ -1,36 +1,49 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.DefaultableInMemoryEntity = void 0; +exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.DefaultableInMemoryEntity = void 0; const in_memory_1 = require("./in_memory"); -const context_1 = require("./mixins/context"); const DefaultableMixin_1 = require("./mixins/DefaultableMixin"); const HasConsistencyChecksMixin_1 = require("./mixins/HasConsistencyChecksMixin"); -const hash_1 = require("./mixins/hash"); const HasMetadataMixin_1 = require("./mixins/HasMetadataMixin"); const NamedEntityMixin_1 = require("./mixins/NamedEntityMixin"); -const repetition_1 = require("./mixins/repetition"); -const runtime_items_1 = require("./mixins/runtime_items"); class DefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.DefaultableInMemoryEntity = DefaultableInMemoryEntity; -(0, DefaultableMixin_1.defaultableEntityMixin)(DefaultableInMemoryEntity.prototype); -(0, DefaultableMixin_1.defaultableEntityStaticMixin)(DefaultableInMemoryEntity); +(0, DefaultableMixin_1.defaultableEntityMixin)(DefaultableInMemoryEntity); class NamedInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.NamedInMemoryEntity = NamedInMemoryEntity; (0, NamedEntityMixin_1.namedEntityMixin)(NamedInMemoryEntity.prototype); -class NamedDefaultableInMemoryEntity extends DefaultableInMemoryEntity { +class NamedDefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.NamedDefaultableInMemoryEntity = NamedDefaultableInMemoryEntity; (0, NamedEntityMixin_1.namedEntityMixin)(NamedDefaultableInMemoryEntity.prototype); -class HasMetadataNamedDefaultableInMemoryEntity extends NamedDefaultableInMemoryEntity { +(0, DefaultableMixin_1.defaultableEntityMixin)(NamedDefaultableInMemoryEntity); +class HasMetadataNamedDefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.HasMetadataNamedDefaultableInMemoryEntity = HasMetadataNamedDefaultableInMemoryEntity; +(0, NamedEntityMixin_1.namedEntityMixin)(HasMetadataNamedDefaultableInMemoryEntity.prototype); +(0, DefaultableMixin_1.defaultableEntityMixin)(HasMetadataNamedDefaultableInMemoryEntity); (0, HasMetadataMixin_1.hasMetadataMixin)(HasMetadataNamedDefaultableInMemoryEntity.prototype); -class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends HasMetadataNamedDefaultableInMemoryEntity { +class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity; +(0, NamedEntityMixin_1.namedEntityMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity.prototype); +(0, DefaultableMixin_1.defaultableEntityMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity); +(0, HasMetadataMixin_1.hasMetadataMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity.prototype); (0, HasConsistencyChecksMixin_1.hasConsistencyChecksMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity.prototype); -exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = (0, context_1.ImportantSettingsProviderMixin)((0, repetition_1.HasRepetitionMixin)(NamedDefaultableInMemoryEntity)); -exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = (0, context_1.ContextAndRenderFieldsMixin)((0, repetition_1.HasRepetitionMixin)(NamedDefaultableInMemoryEntity)); -exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = (0, hash_1.HashedEntityMixin)((0, context_1.ContextAndRenderFieldsMixin)((0, context_1.ImportantSettingsProviderMixin)((0, runtime_items_1.RuntimeItemsUIAllowedMixin)((0, runtime_items_1.RuntimeItemsUILogicMixin)((0, repetition_1.HasRepetitionMixin)(NamedDefaultableInMemoryEntity)))))); +// export const NamedDefaultableRepetitionImportantSettingsInMemoryEntity = +// ImportantSettingsProviderMixin(HasRepetitionMixin(NamedDefaultableInMemoryEntity)); +// export const NamedDefaultableRepetitionContextAndRenderInMemoryEntity = ContextAndRenderFieldsMixin( +// HasRepetitionMixin(NamedDefaultableInMemoryEntity), +// ); +// export const NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = +// HashedEntityMixin( +// ContextAndRenderFieldsMixin( +// ImportantSettingsProviderMixin( +// RuntimeItemsUIAllowedMixin( +// RuntimeItemsUILogicMixin(HasRepetitionMixin(NamedDefaultableInMemoryEntity)), +// ), +// ), +// ), +// ); diff --git a/dist/js/generateSchemaMixin.d.ts b/dist/js/generateSchemaMixin.d.ts index ddb4f4fa..09714f4c 100644 --- a/dist/js/generateSchemaMixin.d.ts +++ b/dist/js/generateSchemaMixin.d.ts @@ -6,9 +6,10 @@ import type { JSONSchema7 } from "json-schema"; * @param outputPaths - Object mapping schema IDs to output file paths * @param skipFields - Array of field names to skip during generation * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Object with success and error counts */ -declare function generateShemaMixin(schemas: JSONSchema7[], outputPaths: Record, skipFields?: string[], from?: string): { +declare function generateShemaMixin(schemas: JSONSchema7[], outputPaths: Record, skipFields?: string[], from?: string, entityFrom?: string): { successCount: number; errorCount: number; }; diff --git a/dist/js/generateSchemaMixin.js b/dist/js/generateSchemaMixin.js index d65c0612..06774519 100644 --- a/dist/js/generateSchemaMixin.js +++ b/dist/js/generateSchemaMixin.js @@ -68,9 +68,10 @@ function extractSchemaProperties(schema) { * @param entityTypeName - Name of the entity type * @param skipFields - Array of field names to skip * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Generated TypeScript code */ -function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields = [], from = "@mat3ra/esse/dist/js/types") { +function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields = [], from = "@mat3ra/esse/dist/js/types", entityFrom = "@mat3ra/code/dist/js/entity") { // Convert mixin type name to camelCase for function name const functionName = mixinTypeName.charAt(0).toLowerCase() + mixinTypeName.slice(1); // Extract properties, handling allOf if present @@ -80,14 +81,21 @@ function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName } // Filter out skip fields const propertyEntries = Object.entries(properties).filter(([propertyName]) => !skipFields.includes(propertyName)); - let code = `import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";\n`; + let code = `import type { InMemoryEntity } from "${entityFrom}";\n`; code += `import type { ${schemaName} } from "${from}";\n\n`; - // Generate the mixin type using Omit utility - const skipFieldNames = skipFields.map((field) => `"${field}"`).join(" | "); - code += `export type ${mixinTypeName} = Omit<${schemaName}, ${skipFieldNames}>;\n\n`; + // Generate the mixin type - only use Omit if skipFields has values + if (skipFields && skipFields.length > 0) { + const skipFieldNames = skipFields.map((field) => `"${field}"`).join(" | "); + code += `export type ${mixinTypeName} = Omit<${schemaName}, ${skipFieldNames}>;\n\n`; + } + else { + code += `export type ${mixinTypeName} = ${schemaName};\n\n`; + } // Generate the entity type code += `export type ${entityTypeName} = InMemoryEntity & ${mixinTypeName};\n\n`; - code += `export function ${functionName}(item: InMemoryEntity) {\n`; + code += `export function ${functionName}(\n`; + code += ` item: InMemoryEntity,\n`; + code += `): asserts item is T & ${mixinTypeName} {\n`; code += ` // @ts-expect-error\n`; code += ` const properties: InMemoryEntity & ${mixinTypeName} = {\n`; for (let i = 0; i < propertyEntries.length; i++) { @@ -97,6 +105,9 @@ function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName const typeAnnotation = generateTypeAnnotation(propertyName, schemaName); code += `get ${propertyName}() {\n`; code += `return this.${methodName}<${typeAnnotation}>("${propertyName}");\n`; + code += `},\n`; + code += `set ${propertyName}(value: ${typeAnnotation}) {\n`; + code += `this.setProp("${propertyName}", value);\n`; code += `}`; // Add comma for all properties except the last one if (i < propertyEntries.length - 1) { @@ -117,9 +128,10 @@ function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName * @param outputPath - The output file path * @param skipFields - Array of field names to skip * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Generated TypeScript code */ -function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = "@mat3ra/esse/dist/js/types") { +function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = "@mat3ra/esse/dist/js/types", entityFrom = "@mat3ra/code/dist/js/entity") { var _a, _b; // Get the resolved schema by ID const schema = JSONSchemasInterface_1.default.getSchemaById(schemaId); @@ -151,7 +163,7 @@ function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = const mixinTypeName = fileName; const entityTypeName = fileName.replace("SchemaMixin", "InMemoryEntity"); // Generate the complete mixin function - return generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields, from); + return generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields, from, entityFrom); } /** * Runs ESLint autofix on generated files @@ -177,9 +189,10 @@ function runESLintAutofix(filePaths) { * @param outputPaths - Object mapping schema IDs to output file paths * @param skipFields - Array of field names to skip during generation * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Object with success and error counts */ -function generateShemaMixin(schemas, outputPaths, skipFields = [], from = "@mat3ra/esse/dist/js/types") { +function generateShemaMixin(schemas, outputPaths, skipFields = [], from = "@mat3ra/esse/dist/js/types", entityFrom = "@mat3ra/code/dist/js/entity") { // Setup schemas JSONSchemasInterface_1.default.setSchemas(schemas); console.log("Generating mixin properties for all schemas..."); @@ -194,7 +207,7 @@ function generateShemaMixin(schemas, outputPaths, skipFields = [], from = "@mat3 if (!outputPath) { throw new Error(`No output path defined for schema: ${schemaId}`); } - const generatedCode = generateMixinFromSchemaId(schemaId, outputPath, skipFields, from); + const generatedCode = generateMixinFromSchemaId(schemaId, outputPath, skipFields, from, entityFrom); // Ensure the directory exists const dir = outputPath.substring(0, outputPath.lastIndexOf("/")); if (!fs_1.default.existsSync(dir)) { diff --git a/dist/js/generated/DefaultableSchemaMixin.d.ts b/dist/js/generated/DefaultableSchemaMixin.d.ts new file mode 100644 index 00000000..e254e5c4 --- /dev/null +++ b/dist/js/generated/DefaultableSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { DefaultableEntitySchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type DefaultableSchemaMixin = DefaultableEntitySchema; +export type DefaultableInMemoryEntity = InMemoryEntity & DefaultableSchemaMixin; +export declare function defaultableSchemaMixin(item: InMemoryEntity): asserts item is T & DefaultableSchemaMixin; diff --git a/dist/js/generated/DefaultableSchemaMixin.js b/dist/js/generated/DefaultableSchemaMixin.js new file mode 100644 index 00000000..c9c276f1 --- /dev/null +++ b/dist/js/generated/DefaultableSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.defaultableSchemaMixin = defaultableSchemaMixin; +function defaultableSchemaMixin(item) { + // @ts-expect-error + const properties = { + get isDefault() { + return this.prop("isDefault"); + }, + set isDefault(value) { + this.setProp("isDefault", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/HasConsistencyChecksSchemaMixin.d.ts b/dist/js/generated/HasConsistencyChecksSchemaMixin.d.ts new file mode 100644 index 00000000..9266913b --- /dev/null +++ b/dist/js/generated/HasConsistencyChecksSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { HasConsistencyCheckSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type HasConsistencyChecksSchemaMixin = HasConsistencyCheckSchema; +export type HasConsistencyChecksInMemoryEntity = InMemoryEntity & HasConsistencyChecksSchemaMixin; +export declare function hasConsistencyChecksSchemaMixin(item: InMemoryEntity): asserts item is T & HasConsistencyChecksSchemaMixin; diff --git a/dist/js/generated/HasConsistencyChecksSchemaMixin.js b/dist/js/generated/HasConsistencyChecksSchemaMixin.js new file mode 100644 index 00000000..5db5cf1e --- /dev/null +++ b/dist/js/generated/HasConsistencyChecksSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hasConsistencyChecksSchemaMixin = hasConsistencyChecksSchemaMixin; +function hasConsistencyChecksSchemaMixin(item) { + // @ts-expect-error + const properties = { + get consistencyChecks() { + return this.prop("consistencyChecks"); + }, + set consistencyChecks(value) { + this.setProp("consistencyChecks", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/HasDescriptionSchemaMixin.d.ts b/dist/js/generated/HasDescriptionSchemaMixin.d.ts new file mode 100644 index 00000000..5fbec77d --- /dev/null +++ b/dist/js/generated/HasDescriptionSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { DescriptionSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type HasDescriptionSchemaMixin = DescriptionSchema; +export type HasDescriptionInMemoryEntity = InMemoryEntity & HasDescriptionSchemaMixin; +export declare function hasDescriptionSchemaMixin(item: InMemoryEntity): asserts item is T & HasDescriptionSchemaMixin; diff --git a/dist/js/generated/HasDescriptionSchemaMixin.js b/dist/js/generated/HasDescriptionSchemaMixin.js new file mode 100644 index 00000000..78f97154 --- /dev/null +++ b/dist/js/generated/HasDescriptionSchemaMixin.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hasDescriptionSchemaMixin = hasDescriptionSchemaMixin; +function hasDescriptionSchemaMixin(item) { + // @ts-expect-error + const properties = { + get description() { + return this.prop("description"); + }, + set description(value) { + this.setProp("description", value); + }, + get descriptionObject() { + return this.prop("descriptionObject"); + }, + set descriptionObject(value) { + this.setProp("descriptionObject", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/NamedEntitySchemaMixin.d.ts b/dist/js/generated/NamedEntitySchemaMixin.d.ts new file mode 100644 index 00000000..441041c5 --- /dev/null +++ b/dist/js/generated/NamedEntitySchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { NameEntitySchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type NamedEntitySchemaMixin = NameEntitySchema; +export type NamedEntityInMemoryEntity = InMemoryEntity & NamedEntitySchemaMixin; +export declare function namedEntitySchemaMixin(item: InMemoryEntity): asserts item is T & NamedEntitySchemaMixin; diff --git a/dist/js/generated/NamedEntitySchemaMixin.js b/dist/js/generated/NamedEntitySchemaMixin.js new file mode 100644 index 00000000..6b701eb9 --- /dev/null +++ b/dist/js/generated/NamedEntitySchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.namedEntitySchemaMixin = namedEntitySchemaMixin; +function namedEntitySchemaMixin(item) { + // @ts-expect-error + const properties = { + get name() { + return this.requiredProp("name"); + }, + set name(value) { + this.setProp("name", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/RuntimeItemsSchemaMixin.d.ts b/dist/js/generated/RuntimeItemsSchemaMixin.d.ts new file mode 100644 index 00000000..7de1b3d1 --- /dev/null +++ b/dist/js/generated/RuntimeItemsSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { RuntimeItemsSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type RuntimeItemsSchemaMixin = RuntimeItemsSchema; +export type RuntimeItemsInMemoryEntity = InMemoryEntity & RuntimeItemsSchemaMixin; +export declare function runtimeItemsSchemaMixin(item: InMemoryEntity): asserts item is T & RuntimeItemsSchemaMixin; diff --git a/dist/js/generated/RuntimeItemsSchemaMixin.js b/dist/js/generated/RuntimeItemsSchemaMixin.js new file mode 100644 index 00000000..88ea0b29 --- /dev/null +++ b/dist/js/generated/RuntimeItemsSchemaMixin.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.runtimeItemsSchemaMixin = runtimeItemsSchemaMixin; +function runtimeItemsSchemaMixin(item) { + // @ts-expect-error + const properties = { + get preProcessors() { + return this.requiredProp("preProcessors"); + }, + set preProcessors(value) { + this.setProp("preProcessors", value); + }, + get postProcessors() { + return this.requiredProp("postProcessors"); + }, + set postProcessors(value) { + this.setProp("postProcessors", value); + }, + get monitors() { + return this.requiredProp("monitors"); + }, + set monitors(value) { + this.setProp("monitors", value); + }, + get results() { + return this.requiredProp("results"); + }, + set results(value) { + this.setProp("results", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/TaggableSchemaMixin.d.ts b/dist/js/generated/TaggableSchemaMixin.d.ts new file mode 100644 index 00000000..a2ced7e6 --- /dev/null +++ b/dist/js/generated/TaggableSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { EntityTagsSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type TaggableSchemaMixin = EntityTagsSchema; +export type TaggableInMemoryEntity = InMemoryEntity & TaggableSchemaMixin; +export declare function taggableSchemaMixin(item: InMemoryEntity): asserts item is T & TaggableSchemaMixin; diff --git a/dist/js/generated/TaggableSchemaMixin.js b/dist/js/generated/TaggableSchemaMixin.js new file mode 100644 index 00000000..86018a67 --- /dev/null +++ b/dist/js/generated/TaggableSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.taggableSchemaMixin = taggableSchemaMixin; +function taggableSchemaMixin(item) { + // @ts-expect-error + const properties = { + get tags() { + return this.prop("tags"); + }, + set tags(value) { + this.setProp("tags", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/utils/object.d.ts b/dist/js/utils/object.d.ts index 64eece16..ec2bde55 100644 --- a/dist/js/utils/object.d.ts +++ b/dist/js/utils/object.d.ts @@ -1,4 +1,6 @@ -import { NameResultSchema } from "@mat3ra/esse/dist/js/types"; +export type NameResultSchema = { + name: string; +}; /** * @summary Safely convert input to { name: str } if it is not already * @param name {String|Object} the input to convert diff --git a/package-lock.json b/package-lock.json index f11afb16..446598b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "@babel/register": "^7.25.7", "@babel/runtime-corejs3": "^7.25.7", "@exabyte-io/eslint-config": "^2025.1.15-0", - "@mat3ra/esse": "git+https://github.com/Exabyte-io/esse#ca7bfd433dd1612fe27f2b8d39853c755359836d", + "@mat3ra/esse": "git+https://github.com/Exabyte-io/esse#75ec994043d2dfadfff0c36a23ec9f6fbcf214e4", "@mat3ra/tsconfig": "2024.6.3-0", "@types/chai": "^4.3.20", "@types/crypto-js": "^4.2.2", @@ -2755,8 +2755,8 @@ }, "node_modules/@mat3ra/esse": { "version": "0.0.0", - "resolved": "git+ssh://git@github.com/Exabyte-io/esse.git#ca7bfd433dd1612fe27f2b8d39853c755359836d", - "integrity": "sha512-t3Rbx0Wwi3pZCeD8WrvQPxNadBCCQVMjB7PCbFCcLsJofN/K1VevS8g0Ax0v7OPzTAOtDwQ0Mk/T/+1+ZdpuXQ==", + "resolved": "git+ssh://git@github.com/Exabyte-io/esse.git#75ec994043d2dfadfff0c36a23ec9f6fbcf214e4", + "integrity": "sha512-qQl96uFmRcA1bP7fxQjSIbt5YtAJ5tcWQEQLgtcPXb1k6COrrc/HqkI5a8QyMxC8NclNosIAzM9myj5sQ+AK0w==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -2769,7 +2769,7 @@ "@babel/preset-typescript": "^7.27.0", "@babel/register": "^7.25.9", "@babel/runtime-corejs3": "^7.27.0", - "@mat3ra/utils": "^2025.11.20-0", + "@mat3ra/utils": "2026.3.7-0", "@types/chai": "^4.3.20", "@types/js-yaml": "^4.0.9", "@types/json-schema-merge-allof": "^0.6.5", @@ -2819,9 +2819,9 @@ } }, "node_modules/@mat3ra/utils": { - "version": "2025.11.20-0", - "resolved": "https://registry.npmjs.org/@mat3ra/utils/-/utils-2025.11.20-0.tgz", - "integrity": "sha512-igkswFIPrvIsOKiGdLE6ifgKGa3nruepjq2pPs9us+gHRn4tCaFNsBJqHw3ysw1dLgCtoYhHyYbMdpQu46+FCw==", + "version": "2026.3.7-0", + "resolved": "https://registry.npmjs.org/@mat3ra/utils/-/utils-2026.3.7-0.tgz", + "integrity": "sha512-qUxsyzo4s1G8MjHYbF+QHdXq0KgymJ3ey3x+dswCak69WiB0w8OuO5IOqyXS0RWoEB2mj7Ccm4ZN7uTSWZLHxw==", "dev": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 732a1fc7..0f7181b3 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@babel/register": "^7.25.7", "@babel/runtime-corejs3": "^7.25.7", "@exabyte-io/eslint-config": "^2025.1.15-0", - "@mat3ra/esse": "git+https://github.com/Exabyte-io/esse#ca7bfd433dd1612fe27f2b8d39853c755359836d", + "@mat3ra/esse": "git+https://github.com/Exabyte-io/esse#75ec994043d2dfadfff0c36a23ec9f6fbcf214e4", "@mat3ra/tsconfig": "2024.6.3-0", "@types/chai": "^4.3.20", "@types/crypto-js": "^4.2.2", diff --git a/src/js/entity/in_memory.ts b/src/js/entity/in_memory.ts index e4403875..c4d3065a 100644 --- a/src/js/entity/in_memory.ts +++ b/src/js/entity/in_memory.ts @@ -46,10 +46,14 @@ export class InMemoryEntity implements BaseInMemoryEntitySchema { _json: AnyObject = {}; - constructor(config = {}) { - this._json = (this.constructor as typeof InMemoryEntity)._isDeepCloneRequired - ? deepClone(config) - : clone(config); + constructor(config: object | InMemoryEntity = {}) { + if (config instanceof InMemoryEntity) { + this._json = config.toJSON(); + } else { + this._json = (this.constructor as typeof InMemoryEntity)._isDeepCloneRequired + ? deepClone(config) + : clone(config); + } } prop(name: string, defaultValue: T): T; diff --git a/src/js/entity/index.ts b/src/js/entity/index.ts index 4bc9370b..6644ec7d 100644 --- a/src/js/entity/index.ts +++ b/src/js/entity/index.ts @@ -1,15 +1,10 @@ import { InMemoryEntity } from "./in_memory"; -import { RuntimeContextFieldMixin } from "./mixins/context_runtime"; -// import { RuntimeItemsMixin } from "./mixins/runtime_items"; import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedInMemoryEntity, - // NamedDefaultableRepetitionContextAndRenderInMemoryEntity, - // NamedDefaultableRepetitionImportantSettingsInMemoryEntity, - // NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, } from "./other"; import { InMemoryEntitySet } from "./set"; import { ENTITY_SET_TYPES } from "./set/enums"; @@ -27,12 +22,7 @@ export { DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, - // NamedDefaultableRepetitionContextAndRenderInMemoryEntity, - // NamedDefaultableRepetitionImportantSettingsInMemoryEntity, - // NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, - // RuntimeItemsMixin, - RuntimeContextFieldMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, diff --git a/src/js/entity/mixins/HasDescriptionMixin.ts b/src/js/entity/mixins/HasDescriptionMixin.ts index 1c4ba046..3b6e99fb 100644 --- a/src/js/entity/mixins/HasDescriptionMixin.ts +++ b/src/js/entity/mixins/HasDescriptionMixin.ts @@ -5,4 +5,4 @@ import { export type HasDescription = HasDescriptionSchemaMixin; -export const hasDescriptionPropertiesMixin = hasDescriptionSchemaMixin; +export const hasDescriptionMixin = hasDescriptionSchemaMixin; diff --git a/src/js/entity/mixins/HasRepetitionMixin.ts b/src/js/entity/mixins/HasRepetitionMixin.ts deleted file mode 100644 index e4d834ff..00000000 --- a/src/js/entity/mixins/HasRepetitionMixin.ts +++ /dev/null @@ -1,46 +0,0 @@ -import type { InMemoryEntity } from "../in_memory"; - -export interface HasRepetition { - _repetition: number; - _totalRepetitions: number; - repetition: number; - totalRepetitions: number; - setRepetition: (repetition: number) => void; - setTotalRepetitions: (totalRepetition: number) => void; -} - -export function hasRepetitionMixin( - item: T, -): asserts item is T & HasRepetition { - // @ts-expect-error - const properties: InMemoryEntity & HasRepetition = { - _repetition: 0, - - _totalRepetitions: 0, - - get repetition() { - return this._repetition; - }, - set repetition(repetition: number) { - this._repetition = repetition; - }, - get totalRepetitions() { - return this._totalRepetitions || 1; - }, - setRepetition(repetition: number) { - this.repetition = repetition; - // if (["Subworkflow", "Workflow"].find((n) => this.constructor.name === n)) { - // this.units.forEach((u) => u.setRepetition(repetition)); - // } - - // if (this.constructor.name === "Workflow") { - // this.subworkflows.forEach((sw) => sw.setRepetition(repetition)); - // this.workflows.forEach((wf) => wf.setRepetition(repetition)); - // } - }, - setTotalRepetitions(totalRepetition: number) { - this._totalRepetitions = totalRepetition; - }, - }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); -} diff --git a/src/js/entity/mixins/context.ts b/src/js/entity/mixins/context.ts deleted file mode 100644 index f2f2bac5..00000000 --- a/src/js/entity/mixins/context.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; - -import { deepClone } from "../../utils/clone"; -import { InMemoryEntityConstructor } from "../in_memory"; - -// TODO: clarify interface -export type Context = AnyObject; - -export function ContextAndRenderFieldsMixin(superclass: T) { - return class extends superclass { - _context: Context; - - /** - * @see https://stackoverflow.com/questions/64396668/why-do-typescript-mixins-require-a-constructor-with-a-single-rest-parameter-any - * */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...params: any[]) { - super(...params); - - this._context = params[0].context || {}; - } - - // in-memory, or "volatile" context that is reset when the `parent` object is destroyed - get context() { - return this._context; - } - - set context(newContext) { - this._context = newContext; - } - - updateContext(ctx = {}, executeRender = false) { - this._context = { ...this.context, ...ctx }; - if (executeRender) this.render(); - } - - // to get "persistent" context, that is stored in database and further should be provided to constructor - // when the `parent` object is re-created - getPersistentContext() { - return this.prop("context"); - } - - // to make context persistent in `_json` - updatePersistentContext(ctx: object = {}) { - this.setProp("context", { ...ctx }); - } - - // to get persistent and volatile context combined - getCombinedContext() { - return { ...this.getPersistentContext(), ...this.context }; - } - - // override in subclasses - // eslint-disable-next-line @typescript-eslint/no-unused-vars - render(_context = this.context) { - throw new Error("RenderInitMixin: render not implemented in derived class"); - } - }; -} - -export interface ContextProvider { - domain: string; -} - -/* - * @summary Handles logic for domain-specific context, eg. "important settings". - * Important settings are stored inside "important" property and have context providers associated with it. - */ -export function DomainContextProviderMixin(superclass: T) { - return class extends superclass { - _contextProviders: ContextProvider[]; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...args: any[]) { - super(...args); - this._contextProviders = []; - } - - get contextProviders() { - // override in children - return this._contextProviders; - } - }; -} - -export function ImportantSettingsProviderMixin(superclass: T) { - return class extends DomainContextProviderMixin(superclass) { - get important() { - return deepClone(this._json.important || {}); - } - - setImportant(key: string, value: unknown) { - this.setProp("important", { [key]: value }); - } - - get importantSettingsProviders() { - return this.contextProviders.filter((p) => p.domain === "important"); - } - - get isImportantEdited() { - return this.prop("important.isEdited"); - } - - set isImportantEdited(bool) { - this.setProp("important", Object.assign(this.important, { isEdited: bool })); - } - }; -} diff --git a/src/js/entity/mixins/context_runtime.ts b/src/js/entity/mixins/context_runtime.ts deleted file mode 100644 index 2e39a7bd..00000000 --- a/src/js/entity/mixins/context_runtime.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { JobBaseSchema } from "@mat3ra/esse/dist/js/types"; - -import { InMemoryEntityConstructor } from "../in_memory"; - -type RuntimeContext = Required["runtimeContext"]; - -export function RuntimeContextFieldMixin(superclass: T) { - return class extends superclass { - _runtimeContext: RuntimeContext; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...args: any[]) { - super(...args); - - const config = args[0]; - - this._runtimeContext = config.runtimeContext || {}; - } - - // in-memory, or "volatile" runtimeContext that is reset when the `parent` object is destroyed - get runtimeContext() { - return this._runtimeContext; - } - - set runtimeContext(newContext: RuntimeContext) { - this._runtimeContext = newContext; - } - - updateRuntimeContext(ctx: RuntimeContext = {}) { - this.runtimeContext = Object.assign(this._runtimeContext, ctx); - } - - toJSON(exclude: string[] = []) { - return { ...super.toJSON(exclude), runtimeContext: this._runtimeContext }; - } - }; -} diff --git a/src/js/entity/mixins/repetition.ts b/src/js/entity/mixins/repetition.ts deleted file mode 100644 index 5de0f653..00000000 --- a/src/js/entity/mixins/repetition.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { InMemoryEntityConstructor } from "../in_memory"; - -export interface HasRepetition { - setRepetition: (repetition: number) => void; -} - -type Units = HasRepetition[]; -type Workflows = HasRepetition[]; -type Subworkflows = HasRepetition[]; - -export function HasRepetitionMixin(superclass: T) { - return class extends superclass { - _repetition = 0; - - _totalRepetitions = 0; - - // TODO: has to be moved somewhere - declare units: Units; - - declare workflows: Workflows; - - declare subworkflows: Subworkflows; - - get repetition() { - return this._repetition || 0; - } - - // TODO: make abstract and move to workflow/subworkflow classes? - setRepetition(repetition: number) { - this._repetition = repetition; - - if (["Subworkflow", "Workflow"].find((n) => this.constructor.name === n)) { - this.units.forEach((u) => u.setRepetition(repetition)); - } - - if (this.constructor.name === "Workflow") { - this.subworkflows.forEach((sw) => sw.setRepetition(repetition)); - this.workflows.forEach((wf) => wf.setRepetition(repetition)); - } - } - - get totalRepetitions() { - return this._totalRepetitions || 1; - } - - setTotalRepetitions(totalRepetition: number) { - this._totalRepetitions = totalRepetition; - } - }; -} diff --git a/src/js/entity/mixins/runtime_items.ts b/src/js/entity/mixins/runtime_items.ts deleted file mode 100644 index 3ea5facb..00000000 --- a/src/js/entity/mixins/runtime_items.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* eslint-disable class-methods-use-this */ -import { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; -import { NameResultSchema, RuntimeItemSchema } from "@mat3ra/esse/dist/js/types"; -import type { Constructor } from "src/js/utils/types"; - -import { safeMakeObject } from "../../utils/object"; -import { InMemoryEntityConstructor } from "../in_memory"; -import RuntimeItemsMixin, { - type BaseRuntimeItemsInMemoryEntity, - ItemKey, -} from "./RuntimeItemsMixin"; - -export { RuntimeItemsMixin, ItemKey }; - -export interface RuntimeItemsUILogicJSON extends AnyObject { - results?: NameResultSchema[]; - monitors?: NameResultSchema[]; - preProcessors?: NameResultSchema[]; - postProcessors?: NameResultSchema[]; -} - -const allKeys: ItemKey[] = [ - ItemKey.results, - ItemKey.monitors, - ItemKey.postProcessors, - ItemKey.preProcessors, -]; - -export function RuntimeItemsUILogicMixin>( - superclass: T, -) { - return class extends RuntimeItemsMixin(superclass) { - declare _json: RuntimeItemsUILogicJSON; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...params: any) { - super(...params); - - const config = params[0]; - - this._initRuntimeItems(allKeys, config); - } - - getDefaultsByKey(key: ItemKey) { - if (key === ItemKey.results) { - return this.defaultResults; - } - if (key === ItemKey.monitors) { - return this.defaultMonitors; - } - if (key === ItemKey.preProcessors) { - return this.defaultPreProcessors; - } - return this.defaultPostProcessors; - } - - setRuntimeItemsToDefaultValues() { - allKeys.forEach((name) => this.setProp(name, this.getDefaultsByKey(name))); - } - - /** - * @summary Must pass config for subclasses to override and use initialization logic - * @private - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _initRuntimeItems(keys: ItemKey[], _config: object) { - // keeping this separate from constructor so that it can be overridden in mixing (eg. in `ExecutionUnit`) - // eslint-disable-next-line @typescript-eslint/no-this-alias - const me = this; - keys.forEach((key) => { - if (!me._json[key]) { - me._json[key] = me.getDefaultsByKey(key); - } - }); - } - - // eslint-disable-next-line default-param-last - _addRuntimeItem(key: ItemKey = ItemKey.results, config: RuntimeItemSchema) { - const runtimeItems = this._json[key]; - if (!runtimeItems) { - throw new Error("not found"); - } - runtimeItems.push(safeMakeObject(config)); - } - - // eslint-disable-next-line default-param-last - _removeRuntimeItem(key: ItemKey = ItemKey.results, config: RuntimeItemSchema) { - const newConfig = safeMakeObject(config); - this._removeRuntimeItemByName(key, newConfig?.name || ""); - } - - _removeRuntimeItemByName(key: ItemKey, name: string) { - this._json[key] = (this._json[key] as NameResultSchema[]).filter( - (x) => x.name !== name, - ); - } - - _toggleRuntimeItem( - // eslint-disable-next-line default-param-last - key: ItemKey = ItemKey.results, - data: RuntimeItemSchema, - isAdding: boolean, - ) { - if (isAdding) { - this._addRuntimeItem(key, data); - } else { - this._removeRuntimeItem(key, data); - } - } - - toggleResult(data: RuntimeItemSchema, isAdding: boolean) { - this._toggleRuntimeItem(ItemKey.results, data, isAdding); - } - - toggleMonitor(data: RuntimeItemSchema, isAdding: boolean) { - this._toggleRuntimeItem(ItemKey.monitors, data, isAdding); - } - - togglePreProcessor(data: RuntimeItemSchema, isAdding: boolean) { - this._toggleRuntimeItem(ItemKey.preProcessors, data, isAdding); - } - - togglePostProcessor(data: RuntimeItemSchema, isAdding: boolean) { - this._toggleRuntimeItem(ItemKey.postProcessors, data, isAdding); - } - - get resultNames() { - return this.results.map((r) => { - return r && r.name; - }); - } - - get monitorNames() { - return this.monitors.map((r) => r?.name); - } - - get postProcessorNames() { - return this.postProcessors.map((r) => r?.name); - } - - get preProcessorNames() { - return this.preProcessors.map((r) => r?.name); - } - - getResultByName(name: string) { - return this.results.find((r) => r?.name === name); - } - }; -} - -// "Placeholder" mixin. Used to indicate the presence of the fields in parent class. -export function RuntimeItemsUIAllowedMixin(superclass: T) { - return class extends superclass { - get allowedResults() { - return []; - } - - get allowedMonitors() { - return []; - } - - get allowedPostProcessors() { - return []; - } - }; -} diff --git a/tests/js/mixin.flowchart.tests.ts b/tests/js/mixin.flowchart.tests.ts deleted file mode 100644 index 6a29fa87..00000000 --- a/tests/js/mixin.flowchart.tests.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { expect } from "chai"; - -import { FlowchartEntityMixin, FlowchartItemMixin, InMemoryEntity } from "../../src/js/entity"; - -const FlowchartEntity = FlowchartEntityMixin(InMemoryEntity); - -const FlowchartItem = FlowchartItemMixin(InMemoryEntity); - -function assertString(prop: unknown): prop is string { - expect(prop).to.be.a("string"); - return typeof prop === "string"; -} - -describe("Flowchart Mixins", () => { - it("flowchart item can be added", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - expect(entity.units.length).to.be.equal(1); - }); - - it("flowchart item can be added between two other units", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - expect(entity.units[0].next).to.be.equal(entity.units[1].flowchartId); - const item = new FlowchartItem(); - entity.addUnit(item, 1); - expect(entity.units[1].flowchartId).to.be.equal(item.flowchartId); - expect(entity.units[1].next).to.be.equal(entity.units[2].flowchartId); - }); - - it("flowchart item points to correct target after removal of the in-between unit", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - - if (assertString(entity.units[1].flowchartId)) { - entity.removeUnit(entity.units[1].flowchartId); - } - - expect(entity.units[0].next).to.be.equal(entity.units[1].flowchartId); - }); - - it("flowchart item points to correct target after removal of last unit", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - if (assertString(entity.units[2].flowchartId)) { - entity.removeUnit(entity.units[2].flowchartId); - } - // eslint-disable-next-line no-unused-expressions - expect(entity.units[1].next).to.be.undefined; - }); - - it("flowchart item can be removed", () => { - const entity = new FlowchartEntity(); - const item = new FlowchartItem(); - entity.addUnit(item); - entity.removeUnit(item.flowchartId); - expect(entity.units.length).to.be.equal(0); - }); - - it("flowchart item can be replaced between two other units", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - const unitsBeforeReplace = entity.units.length; - const item = new FlowchartItem(); - entity.replaceUnit(item, 1); - expect(entity.units[1].flowchartId).to.be.equal(item.flowchartId); - expect(entity.units.length).to.be.equal(unitsBeforeReplace); - }); - - it("flowchart item can be accessed by flowchart Id", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - const item = new FlowchartItem(); - entity.addUnit(item); - const fetchedUnit = entity.getUnit(item.flowchartId); - expect(fetchedUnit).to.be.instanceof(FlowchartItem); - expect(fetchedUnit?.flowchartId).to.be.equal(item.flowchartId); - }); - - it("flowchart item index can be found by flowchart Id", () => { - const entity = new FlowchartEntity(); - entity.addUnit(new FlowchartItem()); - entity.addUnit(new FlowchartItem()); - const item = new FlowchartItem(); - entity.addUnit(item); - const index = entity.getUnitIndexByFlowchartId(item.flowchartId); - expect(index).to.be.equal(entity.units.length - 1); // last unit - }); -});