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..0ae8658d 100644 --- a/dist/js/entity/index.d.ts +++ b/dist/js/entity/index.d.ts @@ -1,14 +1,8 @@ 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 { InMemoryEntitySet } from "./set"; +import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedInMemoryEntity } from "./other"; 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 { InMemoryEntitySetMixin } from "./set/mixins"; +import { orderedEntityInSetMixin, orderedEntitySetMixin } 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, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, orderedEntitySetMixin, orderedEntityInSetMixin, }; diff --git a/dist/js/entity/index.js b/dist/js/entity/index.js index 3cc2997e..6f2f0045 100644 --- a/dist/js/entity/index.js +++ b/dist/js/entity/index.js @@ -33,40 +33,23 @@ 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.orderedEntityInSetMixin = exports.orderedEntitySetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = 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; } }); const enums_1 = require("./set/enums"); Object.defineProperty(exports, "ENTITY_SET_TYPES", { enumerable: true, get: function () { return enums_1.ENTITY_SET_TYPES; } }); const factory_1 = require("./set/factory"); Object.defineProperty(exports, "constructEntitySetFactoryByConfig", { enumerable: true, get: function () { return factory_1.constructEntitySetFactoryByConfig; } }); const mixins_1 = require("./set/mixins"); -Object.defineProperty(exports, "InMemoryEntityInSetMixin", { enumerable: true, get: function () { return mixins_1.InMemoryEntityInSetMixin; } }); Object.defineProperty(exports, "InMemoryEntitySetMixin", { enumerable: true, get: function () { return mixins_1.InMemoryEntitySetMixin; } }); const mixins_2 = require("./set/ordered/mixins"); -Object.defineProperty(exports, "OrderedInMemoryEntityInSetMixin", { enumerable: true, get: function () { return mixins_2.OrderedInMemoryEntityInSetMixin; } }); -Object.defineProperty(exports, "OrderedInMemoryEntitySetMixin", { enumerable: true, get: function () { return mixins_2.OrderedInMemoryEntitySetMixin; } }); +Object.defineProperty(exports, "orderedEntityInSetMixin", { enumerable: true, get: function () { return mixins_2.orderedEntityInSetMixin; } }); +Object.defineProperty(exports, "orderedEntitySetMixin", { enumerable: true, get: function () { return mixins_2.orderedEntitySetMixin; } }); const selectorsForEntitySet = __importStar(require("./set/selectors")); exports.selectorsForEntitySet = selectorsForEntitySet; 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/HasScopeTrackMixin.d.ts b/dist/js/entity/mixins/HasScopeTrackMixin.d.ts index ca217a15..8e9df8fa 100644 --- a/dist/js/entity/mixins/HasScopeTrackMixin.d.ts +++ b/dist/js/entity/mixins/HasScopeTrackMixin.d.ts @@ -1,8 +1,8 @@ -import type { Constructor } from "../../utils/types"; -import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory"; -export declare function hasScopeTrackMixin(item: InMemoryEntity): { - scopeTrack: unknown[]; +import { InMemoryEntity } from "../in_memory"; +type ScopeTrackDescriptor = { + get scopeTrack(): unknown[]; + set scopeTrack(array: unknown[]); }; +export declare function hasScopeTrackMixin(item: InMemoryEntity): InMemoryEntity & ScopeTrackDescriptor; export type HasScopeTrackInMemoryEntity = ReturnType; -export type HasScopeTrackInMemoryEntityConstructor = Constructor; -export default function HasScopeTrackMixin(superclass: S): S & HasScopeTrackInMemoryEntityConstructor; +export {}; diff --git a/dist/js/entity/mixins/HasScopeTrackMixin.js b/dist/js/entity/mixins/HasScopeTrackMixin.js index 2d5d1bd9..11b85ab2 100644 --- a/dist/js/entity/mixins/HasScopeTrackMixin.js +++ b/dist/js/entity/mixins/HasScopeTrackMixin.js @@ -1,29 +1,19 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasScopeTrackMixin = hasScopeTrackMixin; -exports.default = HasScopeTrackMixin; function schemaMixin(item) { - const schema = { + // @ts-expect-error + const properties = { get scopeTrack() { - return item.prop("scopeTrack", []); + return this.prop("scopeTrack", []); }, set scopeTrack(array) { - item.setProp("scopeTrack", array); + this.setProp("scopeTrack", array); }, }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema)); - return schema; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); + return properties; } function hasScopeTrackMixin(item) { return schemaMixin(item); } -function HasScopeTrackMixin(superclass) { - class HasScopeTrackMixin extends superclass { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...args) { - super(...args); - hasScopeTrackMixin(this); - } - } - return HasScopeTrackMixin; -} 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/hash.js b/dist/js/entity/mixins/HashedEntityMixin.js similarity index 50% rename from dist/js/entity/mixins/hash.js rename to dist/js/entity/mixins/HashedEntityMixin.js index 2963706e..d365abc1 100644 --- a/dist/js/entity/mixins/hash.js +++ b/dist/js/entity/mixins/HashedEntityMixin.js @@ -1,24 +1,19 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.HashedEntityMixin = HashedEntityMixin; +exports.hashedEntityMixin = hashedEntityMixin; const hash_1 = require("../../utils/hash"); -function HashedEntityMixin(superclass) { - return class extends superclass { - /* - * @summary Returns an object based on meaningful fields for this unit, that will be used to calculate the hash - * Must be overridden. - */ - // eslint-disable-next-line class-methods-use-this - getHashObject() { - return {}; - } +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() { - return (0, hash_1.calculateHashFromObject)(this.getHashObject()); - } + 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/flowchart.d.ts b/dist/js/entity/mixins/flowchart.d.ts deleted file mode 100644 index c6f9d797..00000000 --- a/dist/js/entity/mixins/flowchart.d.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { UnitEntity } from "../../utils/graph"; -import { InMemoryEntityConstructor } from "../in_memory"; -export declare function FlowchartItemMixin(superclass: T): { - new (...params: any[]): { - readonly flowchartId: string; - head: boolean; - next: string | undefined; - _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 declare function FlowchartEntityMixin(superclass: T): { - new (...params: any[]): { - _units: UnitEntity[]; - readonly units: UnitEntity[]; - setUnits(units: UnitEntity[]): void; - addUnit(unit: UnitEntity, index?: number): void; - removeUnit(flowchartId: string): void; - replaceUnit(unit: UnitEntity, index: number): void; - getUnit(flowchartId: string): UnitEntity | undefined; - getUnitIndexByFlowchartId(flowchartId: string): number; - _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; diff --git a/dist/js/entity/mixins/flowchart.js b/dist/js/entity/mixins/flowchart.js deleted file mode 100644 index e2710de6..00000000 --- a/dist/js/entity/mixins/flowchart.js +++ /dev/null @@ -1,69 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.FlowchartItemMixin = FlowchartItemMixin; -exports.FlowchartEntityMixin = FlowchartEntityMixin; -const findIndex_1 = __importDefault(require("lodash/findIndex")); -const utils_1 = require("../../utils"); -function FlowchartItemMixin(superclass) { - return class extends superclass { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...params) { - super(...params); - const config = params[0]; - if (!(config === null || config === void 0 ? void 0 : config.flowchartId)) { - this.setProp("flowchartId", (0, utils_1.getUUID)()); - } - } - get flowchartId() { - return this.prop("flowchartId", ""); - } - get head() { - return this.prop("head", false); - } - set head(bool) { - this.setProp("head", bool); - } - get next() { - return this.prop("next"); - } - set next(flowchartId) { - this.setProp("next", flowchartId); - } - }; -} -function FlowchartEntityMixin(superclass) { - return class extends superclass { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...params) { - var _a; - super(...params); - this._units = ((_a = params[0]) === null || _a === void 0 ? void 0 : _a.units) || []; - } - get units() { - return this._units; - } - setUnits(units) { - this._units = units; - } - addUnit(unit, index = -1) { - this._units = (0, utils_1.addUnit)(this.units, unit, index); - } - removeUnit(flowchartId) { - this._units = (0, utils_1.removeUnit)(this.units, flowchartId); - } - replaceUnit(unit, index) { - this._units = (0, utils_1.replaceUnit)(this.units, unit, index); - } - getUnit(flowchartId) { - return this.units.find((x) => x.flowchartId === flowchartId); - } - getUnitIndexByFlowchartId(flowchartId) { - return (0, findIndex_1.default)(this.units, (unit) => { - return unit.flowchartId === flowchartId; - }); - } - }; -} diff --git a/dist/js/entity/mixins/hash.d.ts b/dist/js/entity/mixins/hash.d.ts deleted file mode 100644 index 2bd9bc90..00000000 --- a/dist/js/entity/mixins/hash.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { InMemoryEntityConstructor } from "../in_memory"; -export declare function HashedEntityMixin(superclass: T): { - new (...args: any[]): { - getHashObject(): {}; - /** - * @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(): string; - _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; diff --git a/dist/js/entity/mixins/props.d.ts b/dist/js/entity/mixins/props.d.ts deleted file mode 100644 index 5cea781e..00000000 --- a/dist/js/entity/mixins/props.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import HasScopeTrackMixin from "./HasScopeTrackMixin"; -export { HasScopeTrackMixin }; diff --git a/dist/js/entity/mixins/props.js b/dist/js/entity/mixins/props.js deleted file mode 100644 index d8e7ae1c..00000000 --- a/dist/js/entity/mixins/props.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.HasScopeTrackMixin = void 0; -const HasScopeTrackMixin_1 = __importDefault(require("./HasScopeTrackMixin")); -exports.HasScopeTrackMixin = HasScopeTrackMixin_1.default; 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..a093c094 100644 --- a/dist/js/entity/other.js +++ b/dist/js/entity/other.js @@ -1,36 +1,34 @@ "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)))))); diff --git a/dist/js/entity/set.d.ts b/dist/js/entity/set.d.ts deleted file mode 100644 index b00a3e97..00000000 --- a/dist/js/entity/set.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { InMemoryEntity } from "./in_memory"; -declare const InMemoryEntitySet_base: typeof InMemoryEntity & import("./set/InMemoryEntitySetBaseMixin").InMemoryEntitySetBaseConstructor & import("./set/InMemoryEntityInSetMixin").InMemoryEntityInSetConstructor & import("./set/InMemoryEntitySetMixin").InMemoryEntitySetConstructor; -export declare class InMemoryEntitySet extends InMemoryEntitySet_base { -} -export {}; diff --git a/dist/js/entity/set.js b/dist/js/entity/set.js deleted file mode 100644 index 54b2f537..00000000 --- a/dist/js/entity/set.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.InMemoryEntitySet = void 0; -const in_memory_1 = require("./in_memory"); -const InMemoryEntitySetBaseMixin_1 = __importDefault(require("./set/InMemoryEntitySetBaseMixin")); -const mixins_1 = require("./set/mixins"); -class InMemoryEntitySet extends (0, mixins_1.InMemoryEntitySetMixin)((0, mixins_1.InMemoryEntityInSetMixin)((0, InMemoryEntitySetBaseMixin_1.default)(in_memory_1.InMemoryEntity))) { -} -exports.InMemoryEntitySet = InMemoryEntitySet; diff --git a/dist/js/entity/set/InMemoryEntityInSetMixin.d.ts b/dist/js/entity/set/InMemoryEntityInSetMixin.d.ts index e0f8ce53..785474f9 100644 --- a/dist/js/entity/set/InMemoryEntityInSetMixin.d.ts +++ b/dist/js/entity/set/InMemoryEntityInSetMixin.d.ts @@ -1,15 +1,10 @@ import { SystemInSetSchema } from "@mat3ra/esse/dist/js/types"; -import type { Constructor } from "../../utils/types"; import { type InMemoryEntity } from "../in_memory"; export type SystemInSet = Required; export type InSet = SystemInSet["inSet"][0]; -export declare function inMemoryEntityInSetMixin(item: E): void; +export declare function inMemoryEntityInSetMixin(item: E): asserts item is E & InMemoryEntityInSet; export type InSetPropertiesInMemoryEntity = { getInSetFilteredByCls: (cls: string) => InSet[]; parentEntitySetReference: InSet | undefined; }; export type InMemoryEntityInSet = SystemInSet & InSetPropertiesInMemoryEntity; -export type InMemoryEntityInSetConstructor = Constructor; -type Base = Constructor; -export default function InMemoryEntityInSetMixin(superclass: S): S & InMemoryEntityInSetConstructor; -export {}; diff --git a/dist/js/entity/set/InMemoryEntityInSetMixin.js b/dist/js/entity/set/InMemoryEntityInSetMixin.js index 65474110..e1fd21d9 100644 --- a/dist/js/entity/set/InMemoryEntityInSetMixin.js +++ b/dist/js/entity/set/InMemoryEntityInSetMixin.js @@ -1,16 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.inMemoryEntityInSetMixin = inMemoryEntityInSetMixin; -exports.default = InMemoryEntityInSetMixin; +const InSetSchemaMixin_1 = require("../../generated/InSetSchemaMixin"); function inMemoryEntityInSetMixin(item) { + (0, InSetSchemaMixin_1.inSetSchemaMixin)(item); // @ts-expect-error const properties = { - get inSet() { - return this.prop("inSet", []); - }, - set inSet(inSet) { - this.setProp("inSet", inSet); - }, getInSetFilteredByCls(cls) { return this.inSet.filter((ref) => ref.cls === cls); }, @@ -22,9 +17,3 @@ function inMemoryEntityInSetMixin(item) { }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); } -function InMemoryEntityInSetMixin(superclass) { - class InMemoryEntityInSetMixin extends superclass { - } - inMemoryEntityInSetMixin(InMemoryEntityInSetMixin.prototype); - return InMemoryEntityInSetMixin; -} diff --git a/dist/js/entity/set/InMemoryEntitySetBaseMixin.d.ts b/dist/js/entity/set/InMemoryEntitySetBaseMixin.d.ts index 1519fc11..0b937881 100644 --- a/dist/js/entity/set/InMemoryEntitySetBaseMixin.d.ts +++ b/dist/js/entity/set/InMemoryEntitySetBaseMixin.d.ts @@ -1,5 +1,4 @@ import { type EntitySetSchema, SystemInSetSchema } from "@mat3ra/esse/dist/js/types"; -import type { Constructor } from "../../utils/types"; import { type InMemoryEntity } from "../in_memory"; export type SystemInSet = Required; export type InSet = SystemInSet["inSet"][0]; @@ -7,21 +6,14 @@ export declare enum EntitySetType { ordered = "ordered", unordered = "unordered" } -declare function schemaMixin(item: E): { - readonly isEntitySet: boolean; - readonly entitySetType: EntitySetType; - readonly entityCls: string | undefined; -}; -declare function methodsMixin(item: E & EntitySetSchema): { - readonly cls: string; +declare function schemaMixin(item: E): InMemoryEntity & EntitySetSchema; +type EntitySetBaseMethodsDescriptor = { toJSONForInclusionInEntity(): { _id: string; type: string; }; }; -export declare function inMemoryEntitySetBaseMixin(item: T): void; +declare function methodsMixin(item: E & EntitySetSchema): InMemoryEntity & EntitySetSchema & EntitySetBaseMethodsDescriptor; export type InMemoryEntitySetBase = ReturnType & ReturnType; -export type InMemoryEntitySetBaseConstructor = Constructor; -type Base = Constructor; -export default function InMemoryEntitySetBaseMixin(superclass: S): S & InMemoryEntitySetBaseConstructor; +export declare function inMemoryEntitySetBaseMixin(item: T): asserts item is T & InMemoryEntitySetBase; export {}; diff --git a/dist/js/entity/set/InMemoryEntitySetBaseMixin.js b/dist/js/entity/set/InMemoryEntitySetBaseMixin.js index 33b57c06..d2995b6b 100644 --- a/dist/js/entity/set/InMemoryEntitySetBaseMixin.js +++ b/dist/js/entity/set/InMemoryEntitySetBaseMixin.js @@ -2,51 +2,43 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.EntitySetType = void 0; exports.inMemoryEntitySetBaseMixin = inMemoryEntitySetBaseMixin; -exports.default = InMemoryEntitySetBaseMixin; var EntitySetType; (function (EntitySetType) { EntitySetType["ordered"] = "ordered"; EntitySetType["unordered"] = "unordered"; })(EntitySetType || (exports.EntitySetType = EntitySetType = {})); function schemaMixin(item) { - const schema = { + // @ts-expect-error + const properties = { get isEntitySet() { - return item.prop("isEntitySet", false); + return this.prop("isEntitySet", false); }, get entitySetType() { - return item.prop("entitySetType", EntitySetType.unordered); + return this.prop("entitySetType", EntitySetType.unordered); }, get entityCls() { - return item.prop("entityCls"); + return this.prop("entityCls"); }, }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema)); - return schema; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); + return properties; } function methodsMixin(item) { const originalCls = item.cls; - const methods = { + // @ts-expect-error + const properties = { get cls() { - return item.entityCls || originalCls; + return this.entityCls || originalCls; }, toJSONForInclusionInEntity() { - const { _id, type } = item.toJSON(); + const { _id, type } = this.toJSON(); return { _id, type }; }, }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(methods)); - return methods; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); + return properties; } function inMemoryEntitySetBaseMixin(item) { schemaMixin(item); methodsMixin(item); } -function InMemoryEntitySetBaseMixin(superclass) { - class InMemoryEntitySetBaseMixin extends superclass { - constructor(...args) { - super(...args); - inMemoryEntitySetBaseMixin(this); - } - } - return InMemoryEntitySetBaseMixin; -} diff --git a/dist/js/entity/set/InMemoryEntitySetMixin.d.ts b/dist/js/entity/set/InMemoryEntitySetMixin.d.ts index 03d327e2..4d16c78f 100644 --- a/dist/js/entity/set/InMemoryEntitySetMixin.d.ts +++ b/dist/js/entity/set/InMemoryEntitySetMixin.d.ts @@ -1,13 +1,8 @@ import { SystemInSetSchema } from "@mat3ra/esse/dist/js/types"; -import type { Constructor } from "../../utils/types"; import { type InMemoryEntity } from "../in_memory"; export type SystemInSet = Required; export type InSet = SystemInSet["inSet"][0]; -export declare function inMemoryEntitySetMixin(item: T): { - containsEntity(entity?: T_1): boolean; +export type InMemoryEntitySet = { + containsEntity(entity?: SystemInSetSchema): boolean; }; -export type InMemoryEntitySet = ReturnType; -export type InMemoryEntitySetConstructor = Constructor; -type Base = Constructor; -export default function InMemoryEntitySetMixin(superclass: S): S & InMemoryEntitySetConstructor; -export {}; +export declare function inMemoryEntitySetMixin(item: T): InMemoryEntity & InMemoryEntitySet; diff --git a/dist/js/entity/set/InMemoryEntitySetMixin.js b/dist/js/entity/set/InMemoryEntitySetMixin.js index ed183bc1..42e2b0d2 100644 --- a/dist/js/entity/set/InMemoryEntitySetMixin.js +++ b/dist/js/entity/set/InMemoryEntitySetMixin.js @@ -1,23 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.inMemoryEntitySetMixin = inMemoryEntitySetMixin; -exports.default = InMemoryEntitySetMixin; function inMemoryEntitySetMixin(item) { + // @ts-expect-error const properties = { containsEntity(entity) { var _a; - return Boolean((_a = entity === null || entity === void 0 ? void 0 : entity.inSet) === null || _a === void 0 ? void 0 : _a.some((ref) => ref._id === item.id)); + return Boolean((_a = entity === null || entity === void 0 ? void 0 : entity.inSet) === null || _a === void 0 ? void 0 : _a.some((ref) => ref._id === this.id)); }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); return properties; } -function InMemoryEntitySetMixin(superclass) { - class InMemoryEntitySetMixin extends superclass { - constructor(...args) { - super(...args); - inMemoryEntitySetMixin(this); - } - } - return InMemoryEntitySetMixin; -} diff --git a/dist/js/entity/set/enums.d.ts b/dist/js/entity/set/enums.d.ts index e0b2a425..30ed93b5 100644 --- a/dist/js/entity/set/enums.d.ts +++ b/dist/js/entity/set/enums.d.ts @@ -1,4 +1,4 @@ export declare const ENTITY_SET_TYPES: { - unordered: string; - ordered: string; + readonly unordered: "unordered"; + readonly ordered: "ordered"; }; diff --git a/dist/js/entity/set/factory.d.ts b/dist/js/entity/set/factory.d.ts index 818770f1..400063c7 100644 --- a/dist/js/entity/set/factory.d.ts +++ b/dist/js/entity/set/factory.d.ts @@ -1,7 +1,6 @@ import { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; import { EntitySetSchema } from "@mat3ra/esse/dist/js/types"; -import { InMemoryEntitySet } from "../set"; -export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, orderedEntitySetCls }: { - entitySetCls?: typeof InMemoryEntitySet | undefined; - orderedEntitySetCls?: (typeof InMemoryEntitySet & import("./ordered/OrderedInMemoryEntityInSetMixin").OrderedInMemoryEntityInSetConstructor & import("./ordered/OrderedInMemoryEntitySetMixin").OrderedInMemoryEntitySetConstructor) | undefined; -}) => (config: AnyObject, entityCls: EntitySetSchema["entityCls"]) => InMemoryEntitySet; +import { InMemoryEntity } from "../in_memory"; +export declare const constructEntitySetFactoryByConfig: ({ entitySetCls }: { + entitySetCls?: typeof InMemoryEntity | undefined; +}) => (config: AnyObject, entityCls: EntitySetSchema["entityCls"]) => InMemoryEntity; diff --git a/dist/js/entity/set/factory.js b/dist/js/entity/set/factory.js index 627e395a..7c8c6f25 100644 --- a/dist/js/entity/set/factory.js +++ b/dist/js/entity/set/factory.js @@ -1,11 +1,9 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.constructEntitySetFactoryByConfig = void 0; -const set_1 = require("../set"); -const enums_1 = require("./enums"); -const ordered_1 = require("./ordered"); -const constructEntitySetFactoryByConfig = ({ entitySetCls = set_1.InMemoryEntitySet, orderedEntitySetCls = ordered_1.OrderedInMemoryEntitySet }) => (config, entityCls) => { - const Cls = config.entitySetType === enums_1.ENTITY_SET_TYPES.ordered ? orderedEntitySetCls : entitySetCls; +const in_memory_1 = require("../in_memory"); +const constructEntitySetFactoryByConfig = ({ entitySetCls = in_memory_1.InMemoryEntity }) => (config, entityCls) => { + const Cls = entitySetCls; return new Cls({ ...config, entityCls, diff --git a/dist/js/entity/set/mixins.d.ts b/dist/js/entity/set/mixins.d.ts index a5314582..204e09f4 100644 --- a/dist/js/entity/set/mixins.d.ts +++ b/dist/js/entity/set/mixins.d.ts @@ -1,3 +1 @@ -import InMemoryEntityInSetMixin from "./InMemoryEntityInSetMixin"; -import InMemoryEntitySetMixin from "./InMemoryEntitySetMixin"; -export { InMemoryEntityInSetMixin, InMemoryEntitySetMixin }; +export { inMemoryEntitySetMixin, inMemoryEntitySetMixin as InMemoryEntitySetMixin, } from "./InMemoryEntitySetMixin"; diff --git a/dist/js/entity/set/mixins.js b/dist/js/entity/set/mixins.js index 4628b23d..17e87381 100644 --- a/dist/js/entity/set/mixins.js +++ b/dist/js/entity/set/mixins.js @@ -1,11 +1,6 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.InMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = void 0; -/* eslint-disable @typescript-eslint/no-explicit-any */ -const InMemoryEntityInSetMixin_1 = __importDefault(require("./InMemoryEntityInSetMixin")); -exports.InMemoryEntityInSetMixin = InMemoryEntityInSetMixin_1.default; -const InMemoryEntitySetMixin_1 = __importDefault(require("./InMemoryEntitySetMixin")); -exports.InMemoryEntitySetMixin = InMemoryEntitySetMixin_1.default; +exports.InMemoryEntitySetMixin = exports.inMemoryEntitySetMixin = void 0; +var InMemoryEntitySetMixin_1 = require("./InMemoryEntitySetMixin"); +Object.defineProperty(exports, "inMemoryEntitySetMixin", { enumerable: true, get: function () { return InMemoryEntitySetMixin_1.inMemoryEntitySetMixin; } }); +Object.defineProperty(exports, "InMemoryEntitySetMixin", { enumerable: true, get: function () { return InMemoryEntitySetMixin_1.inMemoryEntitySetMixin; } }); diff --git a/dist/js/entity/set/ordered.d.ts b/dist/js/entity/set/ordered.d.ts deleted file mode 100644 index e7d6a3c6..00000000 --- a/dist/js/entity/set/ordered.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { InMemoryEntitySet } from "../set"; -export declare const OrderedInMemoryEntitySet: typeof InMemoryEntitySet & import("./ordered/OrderedInMemoryEntityInSetMixin").OrderedInMemoryEntityInSetConstructor & import("./ordered/OrderedInMemoryEntitySetMixin").OrderedInMemoryEntitySetConstructor; diff --git a/dist/js/entity/set/ordered.js b/dist/js/entity/set/ordered.js deleted file mode 100644 index a786b0c3..00000000 --- a/dist/js/entity/set/ordered.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.OrderedInMemoryEntitySet = void 0; -const set_1 = require("../set"); -const mixins_1 = require("./ordered/mixins"); -exports.OrderedInMemoryEntitySet = (0, mixins_1.OrderedInMemoryEntitySetMixin)((0, mixins_1.OrderedInMemoryEntityInSetMixin)(set_1.InMemoryEntitySet)); diff --git a/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.d.ts b/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.d.ts index 96569d34..82724c32 100644 --- a/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.d.ts +++ b/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.d.ts @@ -1,11 +1,6 @@ -import type { Constructor } from "../../../utils/types"; import { type InMemoryEntity } from "../../in_memory"; -import type { InMemoryEntityInSet, InMemoryEntityInSetConstructor } from "../InMemoryEntityInSetMixin"; -export declare function orderedEntityInSetMixin(item: InMemoryEntity & InMemoryEntityInSet): { +import type { InMemoryEntityInSet } from "../InMemoryEntityInSetMixin"; +export type OrderedInMemoryEntityInSet = { getIndexByIdInOrderedSet(setId: string): number; }; -export type OrderedInMemoryEntityInSet = ReturnType; -export type OrderedInMemoryEntityInSetConstructor = Constructor; -type Base = Constructor & InMemoryEntityInSetConstructor; -export default function OrderedInMemoryEntityInSetMixin(superclass: S): S & OrderedInMemoryEntityInSetConstructor; -export {}; +export declare function orderedEntityInSetMixin(item: T): asserts item is T & OrderedInMemoryEntityInSet; diff --git a/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.js b/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.js index a2afcde9..ba6a355e 100644 --- a/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.js +++ b/dist/js/entity/set/ordered/OrderedInMemoryEntityInSetMixin.js @@ -1,24 +1,13 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.orderedEntityInSetMixin = orderedEntityInSetMixin; -exports.default = OrderedInMemoryEntityInSetMixin; function orderedEntityInSetMixin(item) { + // @ts-expect-error const properties = { getIndexByIdInOrderedSet(setId) { - const setData = item.inSet.find((s) => s._id === setId); + const setData = this.inSet.find((s) => s._id === setId); return (setData === null || setData === void 0 ? void 0 : setData.index) || 0; }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; -} -function OrderedInMemoryEntityInSetMixin(superclass) { - class OrderedInMemoryEntityInSetMixin extends superclass { - constructor(...args) { - super(...args); - orderedEntityInSetMixin(this); - } - } - return OrderedInMemoryEntityInSetMixin; } diff --git a/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.d.ts b/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.d.ts index 557c471b..32526ca1 100644 --- a/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.d.ts +++ b/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.d.ts @@ -1,11 +1,6 @@ -import type { Constructor } from "../../../utils/types"; import { type InMemoryEntity } from "../../in_memory"; -import type { InMemoryEntitySetBase, InMemoryEntitySetBaseConstructor } from "../InMemoryEntitySetBaseMixin"; -export declare function orderedEntitySetMixin(item: InMemoryEntity & InMemoryEntitySetBase): { - readonly isOrderedSet: boolean; +import type { InMemoryEntitySetBase } from "../InMemoryEntitySetBaseMixin"; +export type OrderedInMemoryEntitySet = { + get isOrderedSet(): boolean; }; -export type OrderedInMemoryEntitySet = ReturnType; -export type OrderedInMemoryEntitySetConstructor = Constructor; -type Base = Constructor & InMemoryEntitySetBaseConstructor; -export default function OrderedInMemoryEntitySetMixin(superclass: S): S & OrderedInMemoryEntitySetConstructor; -export {}; +export declare function orderedEntitySetMixin(item: T): asserts item is T & OrderedInMemoryEntitySet; diff --git a/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.js b/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.js index c805be20..1eea8a0b 100644 --- a/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.js +++ b/dist/js/entity/set/ordered/OrderedInMemoryEntitySetMixin.js @@ -1,24 +1,13 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.orderedEntitySetMixin = orderedEntitySetMixin; -exports.default = OrderedInMemoryEntitySetMixin; const enums_1 = require("../enums"); function orderedEntitySetMixin(item) { + // @ts-expect-error const properties = { get isOrderedSet() { - return item.entitySetType === enums_1.ENTITY_SET_TYPES.ordered; + return this.entitySetType === enums_1.ENTITY_SET_TYPES.ordered; }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; -} -function OrderedInMemoryEntitySetMixin(superclass) { - class OrderedInMemoryEntitySetMixin extends superclass { - constructor(...args) { - super(...args); - orderedEntitySetMixin(this); - } - } - return OrderedInMemoryEntitySetMixin; } diff --git a/dist/js/entity/set/ordered/mixins.d.ts b/dist/js/entity/set/ordered/mixins.d.ts index 87fcffb9..ecadbc4b 100644 --- a/dist/js/entity/set/ordered/mixins.d.ts +++ b/dist/js/entity/set/ordered/mixins.d.ts @@ -1,3 +1,3 @@ -import OrderedInMemoryEntityInSetMixin from "./OrderedInMemoryEntityInSetMixin"; -import OrderedInMemoryEntitySetMixin from "./OrderedInMemoryEntitySetMixin"; -export { OrderedInMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin }; +import { orderedEntityInSetMixin } from "./OrderedInMemoryEntityInSetMixin"; +import { orderedEntitySetMixin } from "./OrderedInMemoryEntitySetMixin"; +export { orderedEntityInSetMixin, orderedEntitySetMixin }; diff --git a/dist/js/entity/set/ordered/mixins.js b/dist/js/entity/set/ordered/mixins.js index 26bb85be..98576112 100644 --- a/dist/js/entity/set/ordered/mixins.js +++ b/dist/js/entity/set/ordered/mixins.js @@ -1,10 +1,7 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.OrderedInMemoryEntitySetMixin = exports.OrderedInMemoryEntityInSetMixin = void 0; -const OrderedInMemoryEntityInSetMixin_1 = __importDefault(require("./OrderedInMemoryEntityInSetMixin")); -exports.OrderedInMemoryEntityInSetMixin = OrderedInMemoryEntityInSetMixin_1.default; -const OrderedInMemoryEntitySetMixin_1 = __importDefault(require("./OrderedInMemoryEntitySetMixin")); -exports.OrderedInMemoryEntitySetMixin = OrderedInMemoryEntitySetMixin_1.default; +exports.orderedEntitySetMixin = exports.orderedEntityInSetMixin = void 0; +const OrderedInMemoryEntityInSetMixin_1 = require("./OrderedInMemoryEntityInSetMixin"); +Object.defineProperty(exports, "orderedEntityInSetMixin", { enumerable: true, get: function () { return OrderedInMemoryEntityInSetMixin_1.orderedEntityInSetMixin; } }); +const OrderedInMemoryEntitySetMixin_1 = require("./OrderedInMemoryEntitySetMixin"); +Object.defineProperty(exports, "orderedEntitySetMixin", { enumerable: true, get: function () { return OrderedInMemoryEntitySetMixin_1.orderedEntitySetMixin; } }); 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..44a775ce 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); @@ -129,10 +141,13 @@ function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = // Extract schema name from title for import let schemaName; if (schema.title) { - // Convert title to proper schema name + // Split on spaces and hyphens so titles like "System in-set schema" become SystemInSetSchema, + // not SystemIn-setSchema (hyphens are not valid in TS identifiers). schemaName = schema.title .split(/\s+/) - .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .flatMap((word) => word.split("-")) + .filter((segment) => segment.length > 0) + .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)) .join(""); } else { @@ -151,7 +166,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 +192,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 +210,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..a5f3e02c --- /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/InSetSchemaMixin.d.ts b/dist/js/generated/InSetSchemaMixin.d.ts new file mode 100644 index 00000000..21c2022f --- /dev/null +++ b/dist/js/generated/InSetSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { SystemInSetSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type InSetSchemaMixin = SystemInSetSchema; +export type InSetInMemoryEntity = InMemoryEntity & InSetSchemaMixin; +export declare function inSetSchemaMixin(item: InMemoryEntity): asserts item is T & InSetSchemaMixin; diff --git a/dist/js/generated/InSetSchemaMixin.js b/dist/js/generated/InSetSchemaMixin.js new file mode 100644 index 00000000..d1a14a22 --- /dev/null +++ b/dist/js/generated/InSetSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.inSetSchemaMixin = inSetSchemaMixin; +function inSetSchemaMixin(item) { + // @ts-expect-error + const properties = { + get inSet() { + return this.requiredProp("inSet"); + }, + set inSet(value) { + this.setProp("inSet", 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..fb57c06a --- /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/class.d.ts b/dist/js/utils/class.d.ts index 299281f0..14881af0 100644 --- a/dist/js/utils/class.d.ts +++ b/dist/js/utils/class.d.ts @@ -1,20 +1 @@ export function cloneClass(classToClone: any): any; -/** - * Extends a child class with the parent class. - * Note: this function does not handle static functions. - * Note: this function does not quite handle custom constructor logic like one might expect. - * The workaround is to follow the convention established as in Application classes. - * @param childClass {Object} child class. - * @param parentClass {Object} parent class. - * @param excludedProps {Array} properties to exclude. - * @param args {Array} args to pass to the constructor of the parent class. - */ -export function extendClass(childClass: Object, parentClass: Object, excludedProps?: any[], ...args: any[]): void; -export function extendClassStaticProps(childClass: any, parentClass: any, excludedProps?: any[]): void; -/** - * Slightly different implementation of extendClass assuming excludedProps - * is contained within the child-most class definition and assigning only - * the most recent props rather than the most distant props. - * See extendClass. - */ -export function extendThis(childClass: any, parentClass: any, config: any): void; diff --git a/dist/js/utils/class.js b/dist/js/utils/class.js index bbc6c2f6..33539174 100644 --- a/dist/js/utils/class.js +++ b/dist/js/utils/class.js @@ -1,81 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cloneClass = cloneClass; -exports.extendClass = extendClass; -exports.extendClassStaticProps = extendClassStaticProps; -exports.extendThis = extendThis; function cloneClass(classToClone) { return Object.assign(Object.create(Object.getPrototypeOf(classToClone)), classToClone); } -/** - * Extends a child class with the parent class. - * Note: this function does not handle static functions. - * Note: this function does not quite handle custom constructor logic like one might expect. - * The workaround is to follow the convention established as in Application classes. - * @param childClass {Object} child class. - * @param parentClass {Object} parent class. - * @param excludedProps {Array} properties to exclude. - * @param args {Array} args to pass to the constructor of the parent class. - */ -function extendClass(childClass, parentClass, excludedProps = [], ...args) { - const parentNonStaticProps = Object.getOwnPropertyNames(parentClass.prototype); - parentNonStaticProps - .filter((p) => !excludedProps.includes(p)) - .forEach((prop) => { - if (prop === "constructor") { - Object.assign(childClass.prototype, new parentClass.prototype.constructor(...args)); - } - else { - const get = parentClass.prototype.__lookupGetter__(prop); - const set = parentClass.prototype.__lookupSetter__(prop); - if (get || set) { - Object.defineProperty(childClass.prototype, prop, { get, set }); - } - else { - childClass.prototype[prop] = parentClass.prototype[prop]; - } - } - }); -} -function extendClassStaticProps(childClass, parentClass, excludedProps = []) { - const parentStaticProps = Object.getOwnPropertyNames(parentClass).filter((p) => !["length", "name", "prototype"].includes(p)); - parentStaticProps - .filter((p) => !excludedProps.includes(p)) - .forEach((prop) => { - childClass[prop] = parentClass[prop]; - }); -} -/** - * Slightly different implementation of extendClass assuming excludedProps - * is contained within the child-most class definition and assigning only - * the most recent props rather than the most distant props. - * See extendClass. - */ -function extendThis(childClass, parentClass, config) { - let props, protos; - let obj = new parentClass.prototype.constructor(config); - const exclude = ["constructor", ...Object.getOwnPropertyNames(childClass.prototype)]; - const seen = []; // remember most recent occurrence of prop name (like inheritance) - while (Object.getPrototypeOf(obj)) { - protos = Object.getPrototypeOf(obj); - props = Object.getOwnPropertyNames(protos); - props - .filter((p) => !exclude.includes(p)) - // eslint-disable-next-line no-loop-func - .map((prop) => { - if (seen.includes(prop)) - return; - const get = protos.__lookupGetter__(prop); - const set = protos.__lookupSetter__(prop); - if (get || set) { - Object.defineProperty(childClass.prototype, prop, { get, set }); - } - else { - childClass.prototype[prop] = protos[prop]; - } - seen.push(prop); // don't override with older definition in hierarchy - return null; - }); - obj = protos; - } -} diff --git a/dist/js/utils/clone.js b/dist/js/utils/clone.js index 682c7fb2..a8c6fa50 100644 --- a/dist/js/utils/clone.js +++ b/dist/js/utils/clone.js @@ -2,9 +2,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.deepClone = deepClone; exports.clone = clone; -// TODO: consider other options for performance reasons - http://jsben.ch/bWfk9 function deepClone(obj) { - return JSON.parse(JSON.stringify(obj)); + return structuredClone(obj); } function clone(obj) { return { ...obj }; diff --git a/dist/js/utils/index.d.ts b/dist/js/utils/index.d.ts index 47deecd6..9ccec6ca 100644 --- a/dist/js/utils/index.d.ts +++ b/dist/js/utils/index.d.ts @@ -1,6 +1,6 @@ import { compareEntitiesInOrderedSetForSorting } from "../entity/set/ordered/utils"; import { convertToCompactCSVArrayOfObjects, safeMakeArray } from "./array"; -import { cloneClass, extendClass, extendClassStaticProps, extendThis } from "./class"; +import { cloneClass } from "./class"; import { deepClone } from "./clone"; import { refreshCodeMirror } from "./codemirror"; import { createObjectPathFromFilePath, formatFileSize, getDirectories, getFilesInDirectory, getProgrammingLanguageFromFileExtension } from "./file"; @@ -16,4 +16,4 @@ import { mapTree } from "./tree"; import { containsEncodedComponents } from "./url"; import { getUUID } from "./uuid"; import { JsYamlAllSchemas, JsYamlTypes } from "./yaml"; -export { compareEntitiesInOrderedSetForSorting, safeMakeArray, convertToCompactCSVArrayOfObjects, cloneClass, extendThis, extendClass, extendClassStaticProps, deepClone, refreshCodeMirror, getOneMatchFromObject, safeMakeObject, convertKeysToCamelCaseForObject, flattenObject, renameKeysForObject, sortKeysDeepForObject, stringifyObject, getProgrammingLanguageFromFileExtension, formatFileSize, calculateHashFromObject, calculateHashFromString, removeTimestampableKeysFromConfig, removeNewLinesAndExtraSpaces, randomAlphanumeric, removeEmptyLinesFromString, removeCommentsFromSourceCode, toFixedLocale, getUUID, getSearchQuerySelector, containsEncodedComponents, convertArabicToRoman, setUnitsHead, setNextLinks, addUnit, removeUnit, replaceUnit, mapTree, getSchemaWithDependencies, mergeTerminalNodes, JsYamlTypes, JsYamlAllSchemas, renderTextWithSubstitutes, filterEntityList, getFilesInDirectory, getDirectories, createObjectPathFromFilePath, buildNamedEntitySchema, findPreviousVersion, fetchFilesFromGitHubAPI, }; +export { compareEntitiesInOrderedSetForSorting, safeMakeArray, convertToCompactCSVArrayOfObjects, cloneClass, deepClone, refreshCodeMirror, getOneMatchFromObject, safeMakeObject, convertKeysToCamelCaseForObject, flattenObject, renameKeysForObject, sortKeysDeepForObject, stringifyObject, getProgrammingLanguageFromFileExtension, formatFileSize, calculateHashFromObject, calculateHashFromString, removeTimestampableKeysFromConfig, removeNewLinesAndExtraSpaces, randomAlphanumeric, removeEmptyLinesFromString, removeCommentsFromSourceCode, toFixedLocale, getUUID, getSearchQuerySelector, containsEncodedComponents, convertArabicToRoman, setUnitsHead, setNextLinks, addUnit, removeUnit, replaceUnit, mapTree, getSchemaWithDependencies, mergeTerminalNodes, JsYamlTypes, JsYamlAllSchemas, renderTextWithSubstitutes, filterEntityList, getFilesInDirectory, getDirectories, createObjectPathFromFilePath, buildNamedEntitySchema, findPreviousVersion, fetchFilesFromGitHubAPI, }; diff --git a/dist/js/utils/index.js b/dist/js/utils/index.js index fb6f53f6..2e62ca03 100644 --- a/dist/js/utils/index.js +++ b/dist/js/utils/index.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.fetchFilesFromGitHubAPI = exports.findPreviousVersion = exports.buildNamedEntitySchema = exports.createObjectPathFromFilePath = exports.getDirectories = exports.getFilesInDirectory = exports.filterEntityList = exports.renderTextWithSubstitutes = exports.JsYamlAllSchemas = exports.JsYamlTypes = exports.mergeTerminalNodes = exports.getSchemaWithDependencies = exports.mapTree = exports.replaceUnit = exports.removeUnit = exports.addUnit = exports.setNextLinks = exports.setUnitsHead = exports.convertArabicToRoman = exports.containsEncodedComponents = exports.getSearchQuerySelector = exports.getUUID = exports.toFixedLocale = exports.removeCommentsFromSourceCode = exports.removeEmptyLinesFromString = exports.randomAlphanumeric = exports.removeNewLinesAndExtraSpaces = exports.removeTimestampableKeysFromConfig = exports.calculateHashFromString = exports.calculateHashFromObject = exports.formatFileSize = exports.getProgrammingLanguageFromFileExtension = exports.stringifyObject = exports.sortKeysDeepForObject = exports.renameKeysForObject = exports.flattenObject = exports.convertKeysToCamelCaseForObject = exports.safeMakeObject = exports.getOneMatchFromObject = exports.refreshCodeMirror = exports.deepClone = exports.extendClassStaticProps = exports.extendClass = exports.extendThis = exports.cloneClass = exports.convertToCompactCSVArrayOfObjects = exports.safeMakeArray = exports.compareEntitiesInOrderedSetForSorting = void 0; +exports.fetchFilesFromGitHubAPI = exports.findPreviousVersion = exports.buildNamedEntitySchema = exports.createObjectPathFromFilePath = exports.getDirectories = exports.getFilesInDirectory = exports.filterEntityList = exports.renderTextWithSubstitutes = exports.JsYamlAllSchemas = exports.JsYamlTypes = exports.mergeTerminalNodes = exports.getSchemaWithDependencies = exports.mapTree = exports.replaceUnit = exports.removeUnit = exports.addUnit = exports.setNextLinks = exports.setUnitsHead = exports.convertArabicToRoman = exports.containsEncodedComponents = exports.getSearchQuerySelector = exports.getUUID = exports.toFixedLocale = exports.removeCommentsFromSourceCode = exports.removeEmptyLinesFromString = exports.randomAlphanumeric = exports.removeNewLinesAndExtraSpaces = exports.removeTimestampableKeysFromConfig = exports.calculateHashFromString = exports.calculateHashFromObject = exports.formatFileSize = exports.getProgrammingLanguageFromFileExtension = exports.stringifyObject = exports.sortKeysDeepForObject = exports.renameKeysForObject = exports.flattenObject = exports.convertKeysToCamelCaseForObject = exports.safeMakeObject = exports.getOneMatchFromObject = exports.refreshCodeMirror = exports.deepClone = exports.cloneClass = exports.convertToCompactCSVArrayOfObjects = exports.safeMakeArray = exports.compareEntitiesInOrderedSetForSorting = void 0; const utils_1 = require("../entity/set/ordered/utils"); Object.defineProperty(exports, "compareEntitiesInOrderedSetForSorting", { enumerable: true, get: function () { return utils_1.compareEntitiesInOrderedSetForSorting; } }); const array_1 = require("./array"); @@ -8,9 +8,6 @@ Object.defineProperty(exports, "convertToCompactCSVArrayOfObjects", { enumerable Object.defineProperty(exports, "safeMakeArray", { enumerable: true, get: function () { return array_1.safeMakeArray; } }); const class_1 = require("./class"); Object.defineProperty(exports, "cloneClass", { enumerable: true, get: function () { return class_1.cloneClass; } }); -Object.defineProperty(exports, "extendClass", { enumerable: true, get: function () { return class_1.extendClass; } }); -Object.defineProperty(exports, "extendClassStaticProps", { enumerable: true, get: function () { return class_1.extendClassStaticProps; } }); -Object.defineProperty(exports, "extendThis", { enumerable: true, get: function () { return class_1.extendThis; } }); const clone_1 = require("./clone"); Object.defineProperty(exports, "deepClone", { enumerable: true, get: function () { return clone_1.deepClone; } }); const codemirror_1 = require("./codemirror"); 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