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/index.d.ts b/dist/js/entity/index.d.ts index 2f14d49d..dd92a8de 100644 --- a/dist/js/entity/index.d.ts +++ b/dist/js/entity/index.d.ts @@ -1,14 +1,10 @@ import { InMemoryEntity } from "./in_memory"; -import { ContextAndRenderFieldsMixin } from "./mixins/context"; import { RuntimeContextFieldMixin } from "./mixins/context_runtime"; -import { FlowchartEntityMixin, FlowchartItemMixin } from "./mixins/flowchart"; -import { HasScopeTrackMixin } from "./mixins/props"; -import { RuntimeItemsMixin } from "./mixins/runtime_items"; -import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, NamedInMemoryEntity } from "./other"; +import { DefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, NamedInMemoryEntity } from "./other"; import { InMemoryEntitySet } from "./set"; import { ENTITY_SET_TYPES } from "./set/enums"; import { constructEntitySetFactoryByConfig } from "./set/factory"; import { InMemoryEntityInSetMixin, InMemoryEntitySetMixin } from "./set/mixins"; import { OrderedInMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin } from "./set/ordered/mixins"; import * as selectorsForEntitySet from "./set/selectors"; -export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, NamedDefaultableRepetitionContextAndRenderInMemoryEntity, NamedDefaultableRepetitionImportantSettingsInMemoryEntity, NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, HasScopeTrackMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, }; +export { InMemoryEntity, NamedInMemoryEntity, DefaultableInMemoryEntity, NamedDefaultableInMemoryEntity, HasMetadataNamedDefaultableInMemoryEntity, HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity, RuntimeContextFieldMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, }; diff --git a/dist/js/entity/index.js b/dist/js/entity/index.js index 3cc2997e..3ff147b3 100644 --- a/dist/js/entity/index.js +++ b/dist/js/entity/index.js @@ -33,28 +33,17 @@ var __importStar = (this && this.__importStar) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.FlowchartItemMixin = exports.FlowchartEntityMixin = exports.ContextAndRenderFieldsMixin = exports.OrderedInMemoryEntityInSetMixin = exports.OrderedInMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = exports.InMemoryEntitySet = exports.RuntimeContextFieldMixin = exports.RuntimeItemsMixin = exports.HasScopeTrackMixin = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.DefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.InMemoryEntity = void 0; +exports.OrderedInMemoryEntityInSetMixin = exports.OrderedInMemoryEntitySetMixin = exports.InMemoryEntityInSetMixin = exports.InMemoryEntitySetMixin = exports.selectorsForEntitySet = exports.constructEntitySetFactoryByConfig = exports.ENTITY_SET_TYPES = exports.InMemoryEntitySet = exports.RuntimeContextFieldMixin = 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; } }); +// import { RuntimeItemsMixin } from "./mixins/runtime_items"; const other_1 = require("./other"); Object.defineProperty(exports, "DefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.DefaultableInMemoryEntity; } }); Object.defineProperty(exports, "HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity; } }); Object.defineProperty(exports, "HasMetadataNamedDefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.HasMetadataNamedDefaultableInMemoryEntity; } }); Object.defineProperty(exports, "NamedDefaultableInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableInMemoryEntity; } }); -Object.defineProperty(exports, "NamedDefaultableRepetitionContextAndRenderInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableRepetitionContextAndRenderInMemoryEntity; } }); -Object.defineProperty(exports, "NamedDefaultableRepetitionImportantSettingsInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableRepetitionImportantSettingsInMemoryEntity; } }); -Object.defineProperty(exports, "NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity; } }); Object.defineProperty(exports, "NamedInMemoryEntity", { enumerable: true, get: function () { return other_1.NamedInMemoryEntity; } }); const set_1 = require("./set"); Object.defineProperty(exports, "InMemoryEntitySet", { enumerable: true, get: function () { return set_1.InMemoryEntitySet; } }); diff --git a/dist/js/entity/mixins/ContextAndRenderFieldsMixin.d.ts b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.d.ts new file mode 100644 index 00000000..2e41bca9 --- /dev/null +++ b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.d.ts @@ -0,0 +1,15 @@ +import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; +import type { InMemoryEntity } from "../in_memory"; +export type Context = AnyObject; +export type ContextAndRenderFields = { + context?: Context; + updateContext(ctx: Context): void; + getPersistentContext(): Context | undefined; + updatePersistentContext(ctx: Context): void; + getCombinedContext(): Context; +}; +type AbstractBase = { + render(ctx: Context): void; +}; +export declare function contextAndRenderFieldsMixin(item: T): asserts item is T & ContextAndRenderFields; +export {}; diff --git a/dist/js/entity/mixins/ContextAndRenderFieldsMixin.js b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.js new file mode 100644 index 00000000..7fe3a434 --- /dev/null +++ b/dist/js/entity/mixins/ContextAndRenderFieldsMixin.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.contextAndRenderFieldsMixin = contextAndRenderFieldsMixin; +function contextAndRenderFieldsMixin(item) { + // @ts-expect-error + const properties = { + updateContext(ctx) { + this.context = { ...this.context, ...ctx }; + }, + getPersistentContext() { + return this.prop("context"); + }, + updatePersistentContext(ctx) { + this.setProp("context", { ...ctx }); + }, + getCombinedContext() { + return { ...this.getPersistentContext(), ...this.context }; + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/DefaultableMixin.d.ts b/dist/js/entity/mixins/DefaultableMixin.d.ts index 17976383..ccc28681 100644 --- a/dist/js/entity/mixins/DefaultableMixin.d.ts +++ b/dist/js/entity/mixins/DefaultableMixin.d.ts @@ -1,13 +1,9 @@ -import type { Constructor } from "../../utils/types"; +import { type DefaultableSchemaMixin } from "../../generated/DefaultableSchemaMixin"; +import type { AbstractConstructor, Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function defaultableEntityMixin(item: T): InMemoryEntity & DefaultableInMemoryEntity; -export declare function defaultableEntityStaticMixin(Item: Constructor): DefaultableInMemoryStaticEntity & Constructor & Constructor & { - defaultConfig?: object | null; -}; -export type DefaultableInMemoryEntity = { - isDefault: boolean; -}; +export type Defaultable = DefaultableSchemaMixin; export type DefaultableInMemoryStaticEntity = { - createDefault: () => InMemoryEntity & DefaultableInMemoryEntity; + createDefault: () => InMemoryEntity & Defaultable; }; -export type DefaultableInMemoryEntityConstructor = Constructor & DefaultableInMemoryStaticEntity; +export type DefaultableInMemoryEntityConstructor = Constructor & DefaultableInMemoryStaticEntity; +export declare function defaultableEntityMixin(Item: AbstractConstructor): void; diff --git a/dist/js/entity/mixins/DefaultableMixin.js b/dist/js/entity/mixins/DefaultableMixin.js index afd926e4..af808ac6 100644 --- a/dist/js/entity/mixins/DefaultableMixin.js +++ b/dist/js/entity/mixins/DefaultableMixin.js @@ -2,20 +2,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultableEntityMixin = defaultableEntityMixin; -exports.defaultableEntityStaticMixin = defaultableEntityStaticMixin; -function defaultableEntityMixin(item) { - // @ts-expect-error - const properties = { - get isDefault() { - return this.prop("isDefault", false); - }, - set isDefault(isDefault) { - this.setProp("isDefault", isDefault); - }, - }; - Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; -} +const DefaultableSchemaMixin_1 = require("../../generated/DefaultableSchemaMixin"); function defaultableEntityStaticMixin(Item) { // @ts-expect-error const staticProperties = { @@ -26,3 +13,7 @@ function defaultableEntityStaticMixin(Item) { Object.defineProperties(Item, Object.getOwnPropertyDescriptors(staticProperties)); return staticProperties; } +function defaultableEntityMixin(Item) { + (0, DefaultableSchemaMixin_1.defaultableSchemaMixin)(Item.prototype); + defaultableEntityStaticMixin(Item); +} diff --git a/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts b/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts index be7326c1..2aa7725a 100644 --- a/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts +++ b/dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts @@ -1,9 +1,11 @@ import type { ConsistencyCheck } from "@mat3ra/esse/dist/js/types"; +import { type HasConsistencyChecksSchemaMixin } from "../../generated/HasConsistencyChecksSchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function hasConsistencyChecksMixin(item: T): InMemoryEntity & HasConsistencyChecksInMemoryEntity; -export type HasConsistencyChecksInMemoryEntity = { - consistencyChecks: ConsistencyCheck[]; +type HasConsistencyChecksProperties = { addConsistencyChecks: (array: ConsistencyCheck[]) => void; }; -export type HasConsistencyChecksInMemoryEntityConstructor = Constructor; +export type HasConsistencyChecks = HasConsistencyChecksSchemaMixin & HasConsistencyChecksProperties; +export type HasConsistencyChecksInMemoryEntityConstructor = Constructor; +export declare function hasConsistencyChecksMixin(item: T): asserts item is T & HasConsistencyChecks; +export {}; diff --git a/dist/js/entity/mixins/HasConsistencyChecksMixin.js b/dist/js/entity/mixins/HasConsistencyChecksMixin.js index f71cb3e9..1e4d7889 100644 --- a/dist/js/entity/mixins/HasConsistencyChecksMixin.js +++ b/dist/js/entity/mixins/HasConsistencyChecksMixin.js @@ -1,19 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasConsistencyChecksMixin = hasConsistencyChecksMixin; +const HasConsistencyChecksSchemaMixin_1 = require("../../generated/HasConsistencyChecksSchemaMixin"); function hasConsistencyChecksMixin(item) { + (0, HasConsistencyChecksSchemaMixin_1.hasConsistencyChecksSchemaMixin)(item); // @ts-expect-error const properties = { - get consistencyChecks() { - return this.prop("consistencyChecks", []); - }, - set consistencyChecks(array) { - this.setProp("consistencyChecks", array); - }, addConsistencyChecks(array) { this.consistencyChecks = [...(this.consistencyChecks || []), ...array]; }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; } diff --git a/dist/js/entity/mixins/HasDescriptionMixin.d.ts b/dist/js/entity/mixins/HasDescriptionMixin.d.ts index 520fe15a..4744e53a 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 hasDescriptionPropertiesMixin: typeof hasDescriptionSchemaMixin; diff --git a/dist/js/entity/mixins/HasDescriptionMixin.js b/dist/js/entity/mixins/HasDescriptionMixin.js index ce240947..926b8fd5 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.hasDescriptionPropertiesMixin = void 0; +const HasDescriptionSchemaMixin_1 = require("../../generated/HasDescriptionSchemaMixin"); +exports.hasDescriptionPropertiesMixin = 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/HasRepetitionMixin.d.ts b/dist/js/entity/mixins/HasRepetitionMixin.d.ts new file mode 100644 index 00000000..671178a0 --- /dev/null +++ b/dist/js/entity/mixins/HasRepetitionMixin.d.ts @@ -0,0 +1,10 @@ +import type { InMemoryEntity } from "../in_memory"; +export interface HasRepetition { + _repetition: number; + _totalRepetitions: number; + repetition: number; + totalRepetitions: number; + setRepetition: (repetition: number) => void; + setTotalRepetitions: (totalRepetition: number) => void; +} +export declare function hasRepetitionMixin(item: T): asserts item is T & HasRepetition; diff --git a/dist/js/entity/mixins/HasRepetitionMixin.js b/dist/js/entity/mixins/HasRepetitionMixin.js new file mode 100644 index 00000000..5d13ab78 --- /dev/null +++ b/dist/js/entity/mixins/HasRepetitionMixin.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hasRepetitionMixin = hasRepetitionMixin; +function hasRepetitionMixin(item) { + // @ts-expect-error + const properties = { + _repetition: 0, + _totalRepetitions: 0, + get repetition() { + return this._repetition; + }, + set repetition(repetition) { + this._repetition = repetition; + }, + get totalRepetitions() { + return this._totalRepetitions || 1; + }, + 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)); + // } + }, + setTotalRepetitions(totalRepetition) { + this._totalRepetitions = totalRepetition; + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/HashedEntityMixin.d.ts b/dist/js/entity/mixins/HashedEntityMixin.d.ts new file mode 100644 index 00000000..178b857b --- /dev/null +++ b/dist/js/entity/mixins/HashedEntityMixin.d.ts @@ -0,0 +1,8 @@ +import type { Constructor } from "../../utils/types"; +import { InMemoryEntity } from "../in_memory"; +export type HashedEntity = { + calculateHash(): string; + getHashObject?(): object; +}; +export type HashedInMemoryEntityConstructor = Constructor; +export declare function hashedEntityMixin(item: T): asserts item is T & HashedEntity; diff --git a/dist/js/entity/mixins/HashedEntityMixin.js b/dist/js/entity/mixins/HashedEntityMixin.js new file mode 100644 index 00000000..d365abc1 --- /dev/null +++ b/dist/js/entity/mixins/HashedEntityMixin.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hashedEntityMixin = hashedEntityMixin; +const hash_1 = require("../../utils/hash"); +function hashedEntityMixin(item) { + // @ts-expect-error + const properties = { + /** + * @summary Calculates hash based on meaningful fields and unit-specific fields. Unit-specific fields are + * separated into _typeSpecificHash function which can be overwritten by child classes. + * head and next are also important but not considered since they are included in subworkflow hash. + */ + calculateHash() { + var _a, _b; + return (0, hash_1.calculateHashFromObject)((_b = (_a = this.getHashObject) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {}); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/ImportantSettingsProviderMixin.d.ts b/dist/js/entity/mixins/ImportantSettingsProviderMixin.d.ts new file mode 100644 index 00000000..9cb5ce49 --- /dev/null +++ b/dist/js/entity/mixins/ImportantSettingsProviderMixin.d.ts @@ -0,0 +1,17 @@ +import type { Constructor } from "../../utils/types"; +import type { InMemoryEntity } from "../in_memory"; +export interface ContextProvider { + domain?: string; +} +export type ImportantSettingsProvider = { + important: object; + setImportant(key: string, value: unknown): void; + importantSettingsProviders: ContextProvider[]; + isImportantEdited: boolean | undefined; +}; +type AbstractBase = { + contextProviders: ContextProvider[]; +}; +export type ImportantSettingsProviderInMemoryEntityConstructor = Constructor; +export declare function importantSettingsProviderMixin(item: T): asserts item is T & ImportantSettingsProvider; +export {}; diff --git a/dist/js/entity/mixins/ImportantSettingsProviderMixin.js b/dist/js/entity/mixins/ImportantSettingsProviderMixin.js new file mode 100644 index 00000000..b4477d54 --- /dev/null +++ b/dist/js/entity/mixins/ImportantSettingsProviderMixin.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.importantSettingsProviderMixin = importantSettingsProviderMixin; +const clone_1 = require("../../utils/clone"); +function importantSettingsProviderMixin(item) { + // @ts-expect-error + const properties = { + get important() { + return (0, clone_1.deepClone)(this._json.important || {}); + }, + setImportant(key, value) { + this.setProp("important", { [key]: value }); + }, + get importantSettingsProviders() { + return this.contextProviders.filter((p) => p.domain === "important"); + }, + get isImportantEdited() { + return this.prop("important.isEdited"); + }, + set isImportantEdited(bool) { + this.setProp("important", Object.assign(this.important, { isEdited: bool })); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/entity/mixins/NamedEntityMixin.d.ts b/dist/js/entity/mixins/NamedEntityMixin.d.ts index 4ffdc6b8..e11a74f2 100644 --- a/dist/js/entity/mixins/NamedEntityMixin.d.ts +++ b/dist/js/entity/mixins/NamedEntityMixin.d.ts @@ -1,8 +1,10 @@ +import { type NamedEntitySchemaMixin } from "../../generated/NamedEntitySchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function namedEntityMixin(item: T): InMemoryEntity & NamedInMemoryEntity; -export type NamedInMemoryEntity = { - name: string; +type NamedEntityProperties = { setName: (name: string) => void; }; -export type NamedInMemoryEntityConstructor = Constructor; +export type NamedEntity = NamedEntitySchemaMixin & NamedEntityProperties; +export type NamedInMemoryEntityConstructor = Constructor; +export declare function namedEntityMixin(item: T): asserts item is T & NamedEntity; +export {}; diff --git a/dist/js/entity/mixins/NamedEntityMixin.js b/dist/js/entity/mixins/NamedEntityMixin.js index 1b153663..8884807d 100644 --- a/dist/js/entity/mixins/NamedEntityMixin.js +++ b/dist/js/entity/mixins/NamedEntityMixin.js @@ -1,19 +1,17 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.namedEntityMixin = namedEntityMixin; -function namedEntityMixin(item) { +const NamedEntitySchemaMixin_1 = require("../../generated/NamedEntitySchemaMixin"); +function namedEntityPropertiesMixin(item) { // @ts-expect-error const properties = { - get name() { - return this.prop("name", ""); - }, - set name(name) { - this.setProp("name", name); - }, setName(name) { this.setProp("name", name); }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; +} +function namedEntityMixin(item) { + (0, NamedEntitySchemaMixin_1.namedEntitySchemaMixin)(item); + namedEntityPropertiesMixin(item); } diff --git a/dist/js/entity/mixins/RuntimeItemsMixin.d.ts b/dist/js/entity/mixins/RuntimeItemsMixin.d.ts index 91521250..9bf97071 100644 --- a/dist/js/entity/mixins/RuntimeItemsMixin.d.ts +++ b/dist/js/entity/mixins/RuntimeItemsMixin.d.ts @@ -1,35 +1,14 @@ -import type { NameResultSchema } from "@mat3ra/esse/dist/js/types"; +import { type RuntimeItemsSchemaMixin } from "../../generated/RuntimeItemsSchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare enum ItemKey { - results = "results", - monitors = "monitors", - preProcessors = "preProcessors", - postProcessors = "postProcessors" -} -export type BaseRuntimeItemsInMemoryEntity = InMemoryEntity & { - _json: { - results?: NameResultSchema[]; - monitors?: NameResultSchema[]; - preProcessors?: NameResultSchema[]; - postProcessors?: NameResultSchema[]; - }; - defaultResults?: NameResultSchema[]; - defaultMonitors?: NameResultSchema[]; - defaultPreProcessors?: NameResultSchema[]; - defaultPostProcessors?: NameResultSchema[]; -}; -export declare function runtimeItemsMixin(item: BaseRuntimeItemsInMemoryEntity): void; -export type RuntimeItemsInMemoryEntity = { - results: NameResultSchema[]; - monitors: NameResultSchema[]; - preProcessors: NameResultSchema[]; - postProcessors: NameResultSchema[]; +type RuntimeItemsProperties = { hashObjectFromRuntimeItems: { - results: NameResultSchema[]; - preProcessors: NameResultSchema[]; - postProcessors: NameResultSchema[]; + results: RuntimeItemsSchemaMixin["results"]; + preProcessors: RuntimeItemsSchemaMixin["preProcessors"]; + postProcessors: RuntimeItemsSchemaMixin["postProcessors"]; }; }; -export type RuntimeItemsInMemoryEntityConstructor = Constructor; -export default function RuntimeItemsMixin>(superclass: S): S & RuntimeItemsInMemoryEntityConstructor; +export type RuntimeItems = RuntimeItemsSchemaMixin & RuntimeItemsProperties; +export type RuntimeItemsInMemoryEntityConstructor = Constructor; +export declare function runtimeItemsMixin(item: T): asserts item is T & RuntimeItems; +export {}; diff --git a/dist/js/entity/mixins/RuntimeItemsMixin.js b/dist/js/entity/mixins/RuntimeItemsMixin.js index 1634358b..28ebc9cf 100644 --- a/dist/js/entity/mixins/RuntimeItemsMixin.js +++ b/dist/js/entity/mixins/RuntimeItemsMixin.js @@ -1,41 +1,10 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.ItemKey = void 0; exports.runtimeItemsMixin = runtimeItemsMixin; -exports.default = RuntimeItemsMixin; -const object_1 = require("../../utils/object"); -var ItemKey; -(function (ItemKey) { - ItemKey["results"] = "results"; - ItemKey["monitors"] = "monitors"; - ItemKey["preProcessors"] = "preProcessors"; - ItemKey["postProcessors"] = "postProcessors"; -})(ItemKey || (exports.ItemKey = ItemKey = {})); -/* - * @summary Contains runtime items: results, monitors, pre/postProcessors - * Is meant to work with Entity, InMemoryEntity b/c of `prop` extraction from `_json`. - */ -function runtimeItemsMixin(item) { - // @ts-expect-error - this is a hack to get the properties of the item +const RuntimeItemsSchemaMixin_1 = require("../../generated/RuntimeItemsSchemaMixin"); +function runtimeItemsPropertiesMixin(item) { + // @ts-expect-error const properties = { - get results() { - var _a; - return this.prop("results", (_a = this.defaultResults) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, - get monitors() { - var _a; - return this.prop("monitors", (_a = this.defaultMonitors) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, - get preProcessors() { - var _a; - // TODO: safeMakeObject could return null. Should we throw an error here? - return this.prop("preProcessors", (_a = this.defaultPreProcessors) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, - get postProcessors() { - var _a; - // TODO: safeMakeObject could return null. Should we throw an error here? - return this.prop("postProcessors", (_a = this.defaultPostProcessors) !== null && _a !== void 0 ? _a : []).map(object_1.safeMakeObject); - }, get hashObjectFromRuntimeItems() { return { results: this.results, @@ -46,9 +15,7 @@ function runtimeItemsMixin(item) { }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); } -function RuntimeItemsMixin(superclass) { - class RuntimeItemsMixin extends superclass { - } - runtimeItemsMixin(RuntimeItemsMixin.prototype); - return RuntimeItemsMixin; +function runtimeItemsMixin(item) { + (0, RuntimeItemsSchemaMixin_1.runtimeItemsSchemaMixin)(item); + runtimeItemsPropertiesMixin(item); } diff --git a/dist/js/entity/mixins/TaggableMixin.d.ts b/dist/js/entity/mixins/TaggableMixin.d.ts index 55e7b0aa..a8b7cff5 100644 --- a/dist/js/entity/mixins/TaggableMixin.d.ts +++ b/dist/js/entity/mixins/TaggableMixin.d.ts @@ -1,8 +1,10 @@ +import { type TaggableSchemaMixin } from "../../generated/TaggableSchemaMixin"; import type { Constructor } from "../../utils/types"; import { InMemoryEntity } from "../in_memory"; -export declare function taggableMixin(item: T): InMemoryEntity & TaggableInMemoryEntity; -export type TaggableInMemoryEntity = { - tags: string[]; +type TaggableProperties = { setTags: (array: string[]) => void; }; -export type TaggableInMemoryEntityConstructor = Constructor; +export type Taggable = TaggableSchemaMixin & TaggableProperties; +export type TaggableInMemoryEntityConstructor = Constructor; +export declare function taggableMixin(item: T): asserts item is T & Taggable; +export {}; diff --git a/dist/js/entity/mixins/TaggableMixin.js b/dist/js/entity/mixins/TaggableMixin.js index eb3df3e6..a8bf3ab3 100644 --- a/dist/js/entity/mixins/TaggableMixin.js +++ b/dist/js/entity/mixins/TaggableMixin.js @@ -1,19 +1,17 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.taggableMixin = taggableMixin; -function taggableMixin(item) { +const TaggableSchemaMixin_1 = require("../../generated/TaggableSchemaMixin"); +function taggablePropertiesMixin(item) { // @ts-expect-error const properties = { - get tags() { - return this.prop("tags", []); - }, - set tags(array) { - this.setProp("tags", array); - }, setTags(array) { this.tags = array.filter((value, index, self) => self.indexOf(value) === index); }, }; Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); - return properties; +} +function taggableMixin(item) { + (0, TaggableSchemaMixin_1.taggableSchemaMixin)(item); + taggablePropertiesMixin(item); } diff --git a/dist/js/entity/other.d.ts b/dist/js/entity/other.d.ts index 2632604d..73c0ac32 100644 --- a/dist/js/entity/other.d.ts +++ b/dist/js/entity/other.d.ts @@ -7,7 +7,7 @@ type DefaultableBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstruc type NamedBase = typeof InMemoryEntity & NamedInMemoryEntityConstructor; type NamedDefaultableBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstructor & NamedInMemoryEntityConstructor; type HasMetadataNamedDefaultableBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstructor & NamedInMemoryEntityConstructor & HasMetadataInMemoryEntityConstructor; -type HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntityBase = typeof HasMetadataNamedDefaultableInMemoryEntity & HasConsistencyChecksInMemoryEntityConstructor; +type HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntityBase = typeof InMemoryEntity & DefaultableInMemoryEntityConstructor & NamedInMemoryEntityConstructor & HasConsistencyChecksInMemoryEntityConstructor; declare const DefaultableInMemoryEntity_base: DefaultableBase; export declare class DefaultableInMemoryEntity extends DefaultableInMemoryEntity_base { } @@ -23,398 +23,4 @@ export declare class HasMetadataNamedDefaultableInMemoryEntity extends HasMetada declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base: HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntityBase; export declare class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base { } -export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: { - new (...args: any[]): { - readonly important: any; - setImportant(key: string, value: unknown): void; - readonly importantSettingsProviders: import("./mixins/context").ContextProvider[]; - isImportantEdited: boolean | undefined; - _contextProviders: import("./mixins/context").ContextProvider[]; - readonly contextProviders: import("./mixins/context").ContextProvider[]; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: import("./mixins/repetition").HasRepetition[]; - workflows: import("./mixins/repetition").HasRepetition[]; - subworkflows: import("./mixins/repetition").HasRepetition[]; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & typeof NamedDefaultableInMemoryEntity; -export declare const NamedDefaultableRepetitionContextAndRenderInMemoryEntity: { - new (...params: any[]): { - _context: import("./mixins/context").Context; - context: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - updateContext(ctx?: {}, executeRender?: boolean): void; - getPersistentContext(): object | undefined; - updatePersistentContext(ctx?: object): void; - getCombinedContext(): { - [x: string]: unknown; - }; - render(_context?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: import("./mixins/repetition").HasRepetition[]; - workflows: import("./mixins/repetition").HasRepetition[]; - subworkflows: import("./mixins/repetition").HasRepetition[]; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & typeof NamedDefaultableInMemoryEntity; -export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity: { - new (...args: any[]): { - getHashObject(): {}; - calculateHash(): string; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...params: any[]): { - _context: import("./mixins/context").Context; - context: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - updateContext(ctx?: {}, executeRender?: boolean): void; - getPersistentContext(): object | undefined; - updatePersistentContext(ctx?: object): void; - getCombinedContext(): { - [x: string]: unknown; - }; - render(_context?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - readonly important: any; - setImportant(key: string, value: unknown): void; - readonly importantSettingsProviders: import("./mixins/context").ContextProvider[]; - isImportantEdited: boolean | undefined; - _contextProviders: import("./mixins/context").ContextProvider[]; - readonly contextProviders: import("./mixins/context").ContextProvider[]; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...args: any[]): { - readonly allowedResults: never[]; - readonly allowedMonitors: never[]; - readonly allowedPostProcessors: never[]; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & { - new (...params: any): { - _json: import("./mixins/runtime_items").RuntimeItemsUILogicJSON; - getDefaultsByKey(key: import("./mixins/RuntimeItemsMixin").ItemKey): import("@mat3ra/esse/dist/js/types").NameResultSchema[] | undefined; - setRuntimeItemsToDefaultValues(): void; - _initRuntimeItems(keys: import("./mixins/RuntimeItemsMixin").ItemKey[], _config: object): void; - _addRuntimeItem(key: import("./mixins/RuntimeItemsMixin").ItemKey | undefined, config: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema): void; - _removeRuntimeItem(key: import("./mixins/RuntimeItemsMixin").ItemKey | undefined, config: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema): void; - _removeRuntimeItemByName(key: import("./mixins/RuntimeItemsMixin").ItemKey, name: string): void; - _toggleRuntimeItem(key: import("./mixins/RuntimeItemsMixin").ItemKey | undefined, data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - toggleResult(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - toggleMonitor(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - togglePreProcessor(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - togglePostProcessor(data: import("@mat3ra/esse/dist/js/types").RuntimeItemSchema, isAdding: boolean): void; - readonly resultNames: string[]; - readonly monitorNames: string[]; - readonly postProcessorNames: string[]; - readonly preProcessorNames: string[]; - getResultByName(name: string): import("@mat3ra/esse/dist/js/types").NameResultSchema | undefined; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - defaultResults?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - defaultMonitors?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - defaultPreProcessors?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - defaultPostProcessors?: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - results: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - monitors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - preProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - postProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - hashObjectFromRuntimeItems: { - results: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - preProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - postProcessors: import("@mat3ra/esse/dist/js/types").NameResultSchema[]; - }; - }; -} & { - new (...args: any[]): { - _repetition: number; - _totalRepetitions: number; - units: import("./mixins/repetition").HasRepetition[]; - workflows: import("./mixins/repetition").HasRepetition[]; - subworkflows: import("./mixins/repetition").HasRepetition[]; - readonly repetition: number; - setRepetition(repetition: number): void; - readonly totalRepetitions: number; - setTotalRepetitions(totalRepetition: number): void; - _json: import("@mat3ra/esse/dist/js/esse/types").AnyObject; - prop(name: string, defaultValue: T): T; - prop(name: string): T | undefined; - requiredProp(name: string): T; - setProp(name: string, value: unknown): void; - unsetProp(name: string): void; - setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any; - toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - clone(extraContext?: object): /*elided*/ any; - validate(): void; - clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject; - isValid(): boolean; - readonly cls: string; - getClsName(): string; - getAsEntityReference(byIdOnly: true): { - _id: string; - }; - getAsEntityReference(byIdOnly?: false): Required; - getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; - id: string; - _id: string; - schemaVersion: string; - systemName: string; - readonly slug: string; - readonly isSystemEntity: boolean; - }; -} & typeof NamedDefaultableInMemoryEntity; export {}; diff --git a/dist/js/entity/other.js b/dist/js/entity/other.js index 7ef78a29..c37b2165 100644 --- a/dist/js/entity/other.js +++ b/dist/js/entity/other.js @@ -1,36 +1,49 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.DefaultableInMemoryEntity = void 0; +exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.DefaultableInMemoryEntity = void 0; const in_memory_1 = require("./in_memory"); -const context_1 = require("./mixins/context"); const DefaultableMixin_1 = require("./mixins/DefaultableMixin"); const HasConsistencyChecksMixin_1 = require("./mixins/HasConsistencyChecksMixin"); -const hash_1 = require("./mixins/hash"); const HasMetadataMixin_1 = require("./mixins/HasMetadataMixin"); const NamedEntityMixin_1 = require("./mixins/NamedEntityMixin"); -const repetition_1 = require("./mixins/repetition"); -const runtime_items_1 = require("./mixins/runtime_items"); class DefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.DefaultableInMemoryEntity = DefaultableInMemoryEntity; -(0, DefaultableMixin_1.defaultableEntityMixin)(DefaultableInMemoryEntity.prototype); -(0, DefaultableMixin_1.defaultableEntityStaticMixin)(DefaultableInMemoryEntity); +(0, DefaultableMixin_1.defaultableEntityMixin)(DefaultableInMemoryEntity); class NamedInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.NamedInMemoryEntity = NamedInMemoryEntity; (0, NamedEntityMixin_1.namedEntityMixin)(NamedInMemoryEntity.prototype); -class NamedDefaultableInMemoryEntity extends DefaultableInMemoryEntity { +class NamedDefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.NamedDefaultableInMemoryEntity = NamedDefaultableInMemoryEntity; (0, NamedEntityMixin_1.namedEntityMixin)(NamedDefaultableInMemoryEntity.prototype); -class HasMetadataNamedDefaultableInMemoryEntity extends NamedDefaultableInMemoryEntity { +(0, DefaultableMixin_1.defaultableEntityMixin)(NamedDefaultableInMemoryEntity); +class HasMetadataNamedDefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.HasMetadataNamedDefaultableInMemoryEntity = HasMetadataNamedDefaultableInMemoryEntity; +(0, NamedEntityMixin_1.namedEntityMixin)(HasMetadataNamedDefaultableInMemoryEntity.prototype); +(0, DefaultableMixin_1.defaultableEntityMixin)(HasMetadataNamedDefaultableInMemoryEntity); (0, HasMetadataMixin_1.hasMetadataMixin)(HasMetadataNamedDefaultableInMemoryEntity.prototype); -class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends HasMetadataNamedDefaultableInMemoryEntity { +class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends in_memory_1.InMemoryEntity { } exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity; +(0, NamedEntityMixin_1.namedEntityMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity.prototype); +(0, DefaultableMixin_1.defaultableEntityMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity); +(0, HasMetadataMixin_1.hasMetadataMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity.prototype); (0, HasConsistencyChecksMixin_1.hasConsistencyChecksMixin)(HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity.prototype); -exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = (0, context_1.ImportantSettingsProviderMixin)((0, repetition_1.HasRepetitionMixin)(NamedDefaultableInMemoryEntity)); -exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = (0, context_1.ContextAndRenderFieldsMixin)((0, repetition_1.HasRepetitionMixin)(NamedDefaultableInMemoryEntity)); -exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = (0, hash_1.HashedEntityMixin)((0, context_1.ContextAndRenderFieldsMixin)((0, context_1.ImportantSettingsProviderMixin)((0, runtime_items_1.RuntimeItemsUIAllowedMixin)((0, runtime_items_1.RuntimeItemsUILogicMixin)((0, repetition_1.HasRepetitionMixin)(NamedDefaultableInMemoryEntity)))))); +// export const NamedDefaultableRepetitionImportantSettingsInMemoryEntity = +// ImportantSettingsProviderMixin(HasRepetitionMixin(NamedDefaultableInMemoryEntity)); +// export const NamedDefaultableRepetitionContextAndRenderInMemoryEntity = ContextAndRenderFieldsMixin( +// HasRepetitionMixin(NamedDefaultableInMemoryEntity), +// ); +// export const NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = +// HashedEntityMixin( +// ContextAndRenderFieldsMixin( +// ImportantSettingsProviderMixin( +// RuntimeItemsUIAllowedMixin( +// RuntimeItemsUILogicMixin(HasRepetitionMixin(NamedDefaultableInMemoryEntity)), +// ), +// ), +// ), +// ); diff --git a/dist/js/generateSchemaMixin.d.ts b/dist/js/generateSchemaMixin.d.ts index ddb4f4fa..09714f4c 100644 --- a/dist/js/generateSchemaMixin.d.ts +++ b/dist/js/generateSchemaMixin.d.ts @@ -6,9 +6,10 @@ import type { JSONSchema7 } from "json-schema"; * @param outputPaths - Object mapping schema IDs to output file paths * @param skipFields - Array of field names to skip during generation * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Object with success and error counts */ -declare function generateShemaMixin(schemas: JSONSchema7[], outputPaths: Record, skipFields?: string[], from?: string): { +declare function generateShemaMixin(schemas: JSONSchema7[], outputPaths: Record, skipFields?: string[], from?: string, entityFrom?: string): { successCount: number; errorCount: number; }; diff --git a/dist/js/generateSchemaMixin.js b/dist/js/generateSchemaMixin.js index d65c0612..06774519 100644 --- a/dist/js/generateSchemaMixin.js +++ b/dist/js/generateSchemaMixin.js @@ -68,9 +68,10 @@ function extractSchemaProperties(schema) { * @param entityTypeName - Name of the entity type * @param skipFields - Array of field names to skip * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Generated TypeScript code */ -function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields = [], from = "@mat3ra/esse/dist/js/types") { +function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields = [], from = "@mat3ra/esse/dist/js/types", entityFrom = "@mat3ra/code/dist/js/entity") { // Convert mixin type name to camelCase for function name const functionName = mixinTypeName.charAt(0).toLowerCase() + mixinTypeName.slice(1); // Extract properties, handling allOf if present @@ -80,14 +81,21 @@ function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName } // Filter out skip fields const propertyEntries = Object.entries(properties).filter(([propertyName]) => !skipFields.includes(propertyName)); - let code = `import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";\n`; + let code = `import type { InMemoryEntity } from "${entityFrom}";\n`; code += `import type { ${schemaName} } from "${from}";\n\n`; - // Generate the mixin type using Omit utility - const skipFieldNames = skipFields.map((field) => `"${field}"`).join(" | "); - code += `export type ${mixinTypeName} = Omit<${schemaName}, ${skipFieldNames}>;\n\n`; + // Generate the mixin type - only use Omit if skipFields has values + if (skipFields && skipFields.length > 0) { + const skipFieldNames = skipFields.map((field) => `"${field}"`).join(" | "); + code += `export type ${mixinTypeName} = Omit<${schemaName}, ${skipFieldNames}>;\n\n`; + } + else { + code += `export type ${mixinTypeName} = ${schemaName};\n\n`; + } // Generate the entity type code += `export type ${entityTypeName} = InMemoryEntity & ${mixinTypeName};\n\n`; - code += `export function ${functionName}(item: InMemoryEntity) {\n`; + code += `export function ${functionName}(\n`; + code += ` item: InMemoryEntity,\n`; + code += `): asserts item is T & ${mixinTypeName} {\n`; code += ` // @ts-expect-error\n`; code += ` const properties: InMemoryEntity & ${mixinTypeName} = {\n`; for (let i = 0; i < propertyEntries.length; i++) { @@ -97,6 +105,9 @@ function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName const typeAnnotation = generateTypeAnnotation(propertyName, schemaName); code += `get ${propertyName}() {\n`; code += `return this.${methodName}<${typeAnnotation}>("${propertyName}");\n`; + code += `},\n`; + code += `set ${propertyName}(value: ${typeAnnotation}) {\n`; + code += `this.setProp("${propertyName}", value);\n`; code += `}`; // Add comma for all properties except the last one if (i < propertyEntries.length - 1) { @@ -117,9 +128,10 @@ function generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName * @param outputPath - The output file path * @param skipFields - Array of field names to skip * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Generated TypeScript code */ -function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = "@mat3ra/esse/dist/js/types") { +function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = "@mat3ra/esse/dist/js/types", entityFrom = "@mat3ra/code/dist/js/entity") { var _a, _b; // Get the resolved schema by ID const schema = JSONSchemasInterface_1.default.getSchemaById(schemaId); @@ -151,7 +163,7 @@ function generateMixinFromSchemaId(schemaId, outputPath, skipFields = [], from = const mixinTypeName = fileName; const entityTypeName = fileName.replace("SchemaMixin", "InMemoryEntity"); // Generate the complete mixin function - return generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields, from); + return generateMixinFunction(schema, schemaName, mixinTypeName, entityTypeName, skipFields, from, entityFrom); } /** * Runs ESLint autofix on generated files @@ -177,9 +189,10 @@ function runESLintAutofix(filePaths) { * @param outputPaths - Object mapping schema IDs to output file paths * @param skipFields - Array of field names to skip during generation * @param from - Import path for the schema type (default: "@mat3ra/esse/dist/js/types") + * @param entityFrom - Import path for the entity type (default: "@mat3ra/code/dist/js/entity") * @returns - Object with success and error counts */ -function generateShemaMixin(schemas, outputPaths, skipFields = [], from = "@mat3ra/esse/dist/js/types") { +function generateShemaMixin(schemas, outputPaths, skipFields = [], from = "@mat3ra/esse/dist/js/types", entityFrom = "@mat3ra/code/dist/js/entity") { // Setup schemas JSONSchemasInterface_1.default.setSchemas(schemas); console.log("Generating mixin properties for all schemas..."); @@ -194,7 +207,7 @@ function generateShemaMixin(schemas, outputPaths, skipFields = [], from = "@mat3 if (!outputPath) { throw new Error(`No output path defined for schema: ${schemaId}`); } - const generatedCode = generateMixinFromSchemaId(schemaId, outputPath, skipFields, from); + const generatedCode = generateMixinFromSchemaId(schemaId, outputPath, skipFields, from, entityFrom); // Ensure the directory exists const dir = outputPath.substring(0, outputPath.lastIndexOf("/")); if (!fs_1.default.existsSync(dir)) { diff --git a/dist/js/generated/DefaultableSchemaMixin.d.ts b/dist/js/generated/DefaultableSchemaMixin.d.ts new file mode 100644 index 00000000..e254e5c4 --- /dev/null +++ b/dist/js/generated/DefaultableSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { DefaultableEntitySchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type DefaultableSchemaMixin = DefaultableEntitySchema; +export type DefaultableInMemoryEntity = InMemoryEntity & DefaultableSchemaMixin; +export declare function defaultableSchemaMixin(item: InMemoryEntity): asserts item is T & DefaultableSchemaMixin; diff --git a/dist/js/generated/DefaultableSchemaMixin.js b/dist/js/generated/DefaultableSchemaMixin.js new file mode 100644 index 00000000..c9c276f1 --- /dev/null +++ b/dist/js/generated/DefaultableSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.defaultableSchemaMixin = defaultableSchemaMixin; +function defaultableSchemaMixin(item) { + // @ts-expect-error + const properties = { + get isDefault() { + return this.prop("isDefault"); + }, + set isDefault(value) { + this.setProp("isDefault", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/HasConsistencyChecksSchemaMixin.d.ts b/dist/js/generated/HasConsistencyChecksSchemaMixin.d.ts new file mode 100644 index 00000000..9266913b --- /dev/null +++ b/dist/js/generated/HasConsistencyChecksSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { HasConsistencyCheckSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type HasConsistencyChecksSchemaMixin = HasConsistencyCheckSchema; +export type HasConsistencyChecksInMemoryEntity = InMemoryEntity & HasConsistencyChecksSchemaMixin; +export declare function hasConsistencyChecksSchemaMixin(item: InMemoryEntity): asserts item is T & HasConsistencyChecksSchemaMixin; diff --git a/dist/js/generated/HasConsistencyChecksSchemaMixin.js b/dist/js/generated/HasConsistencyChecksSchemaMixin.js new file mode 100644 index 00000000..5db5cf1e --- /dev/null +++ b/dist/js/generated/HasConsistencyChecksSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hasConsistencyChecksSchemaMixin = hasConsistencyChecksSchemaMixin; +function hasConsistencyChecksSchemaMixin(item) { + // @ts-expect-error + const properties = { + get consistencyChecks() { + return this.prop("consistencyChecks"); + }, + set consistencyChecks(value) { + this.setProp("consistencyChecks", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/HasDescriptionSchemaMixin.d.ts b/dist/js/generated/HasDescriptionSchemaMixin.d.ts new file mode 100644 index 00000000..5fbec77d --- /dev/null +++ b/dist/js/generated/HasDescriptionSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { DescriptionSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type HasDescriptionSchemaMixin = DescriptionSchema; +export type HasDescriptionInMemoryEntity = InMemoryEntity & HasDescriptionSchemaMixin; +export declare function hasDescriptionSchemaMixin(item: InMemoryEntity): asserts item is T & HasDescriptionSchemaMixin; diff --git a/dist/js/generated/HasDescriptionSchemaMixin.js b/dist/js/generated/HasDescriptionSchemaMixin.js new file mode 100644 index 00000000..78f97154 --- /dev/null +++ b/dist/js/generated/HasDescriptionSchemaMixin.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hasDescriptionSchemaMixin = hasDescriptionSchemaMixin; +function hasDescriptionSchemaMixin(item) { + // @ts-expect-error + const properties = { + get description() { + return this.prop("description"); + }, + set description(value) { + this.setProp("description", value); + }, + get descriptionObject() { + return this.prop("descriptionObject"); + }, + set descriptionObject(value) { + this.setProp("descriptionObject", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/NamedEntitySchemaMixin.d.ts b/dist/js/generated/NamedEntitySchemaMixin.d.ts new file mode 100644 index 00000000..441041c5 --- /dev/null +++ b/dist/js/generated/NamedEntitySchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { NameEntitySchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type NamedEntitySchemaMixin = NameEntitySchema; +export type NamedEntityInMemoryEntity = InMemoryEntity & NamedEntitySchemaMixin; +export declare function namedEntitySchemaMixin(item: InMemoryEntity): asserts item is T & NamedEntitySchemaMixin; diff --git a/dist/js/generated/NamedEntitySchemaMixin.js b/dist/js/generated/NamedEntitySchemaMixin.js new file mode 100644 index 00000000..6b701eb9 --- /dev/null +++ b/dist/js/generated/NamedEntitySchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.namedEntitySchemaMixin = namedEntitySchemaMixin; +function namedEntitySchemaMixin(item) { + // @ts-expect-error + const properties = { + get name() { + return this.requiredProp("name"); + }, + set name(value) { + this.setProp("name", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/RuntimeItemsSchemaMixin.d.ts b/dist/js/generated/RuntimeItemsSchemaMixin.d.ts new file mode 100644 index 00000000..7de1b3d1 --- /dev/null +++ b/dist/js/generated/RuntimeItemsSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { RuntimeItemsSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type RuntimeItemsSchemaMixin = RuntimeItemsSchema; +export type RuntimeItemsInMemoryEntity = InMemoryEntity & RuntimeItemsSchemaMixin; +export declare function runtimeItemsSchemaMixin(item: InMemoryEntity): asserts item is T & RuntimeItemsSchemaMixin; diff --git a/dist/js/generated/RuntimeItemsSchemaMixin.js b/dist/js/generated/RuntimeItemsSchemaMixin.js new file mode 100644 index 00000000..88ea0b29 --- /dev/null +++ b/dist/js/generated/RuntimeItemsSchemaMixin.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.runtimeItemsSchemaMixin = runtimeItemsSchemaMixin; +function runtimeItemsSchemaMixin(item) { + // @ts-expect-error + const properties = { + get preProcessors() { + return this.requiredProp("preProcessors"); + }, + set preProcessors(value) { + this.setProp("preProcessors", value); + }, + get postProcessors() { + return this.requiredProp("postProcessors"); + }, + set postProcessors(value) { + this.setProp("postProcessors", value); + }, + get monitors() { + return this.requiredProp("monitors"); + }, + set monitors(value) { + this.setProp("monitors", value); + }, + get results() { + return this.requiredProp("results"); + }, + set results(value) { + this.setProp("results", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/generated/TaggableSchemaMixin.d.ts b/dist/js/generated/TaggableSchemaMixin.d.ts new file mode 100644 index 00000000..a2ced7e6 --- /dev/null +++ b/dist/js/generated/TaggableSchemaMixin.d.ts @@ -0,0 +1,5 @@ +import type { EntityTagsSchema } from "@mat3ra/esse/dist/js/types"; +import type { InMemoryEntity } from "../entity/in_memory"; +export type TaggableSchemaMixin = EntityTagsSchema; +export type TaggableInMemoryEntity = InMemoryEntity & TaggableSchemaMixin; +export declare function taggableSchemaMixin(item: InMemoryEntity): asserts item is T & TaggableSchemaMixin; diff --git a/dist/js/generated/TaggableSchemaMixin.js b/dist/js/generated/TaggableSchemaMixin.js new file mode 100644 index 00000000..86018a67 --- /dev/null +++ b/dist/js/generated/TaggableSchemaMixin.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.taggableSchemaMixin = taggableSchemaMixin; +function taggableSchemaMixin(item) { + // @ts-expect-error + const properties = { + get tags() { + return this.prop("tags"); + }, + set tags(value) { + this.setProp("tags", value); + }, + }; + Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties)); +} diff --git a/dist/js/utils/object.d.ts b/dist/js/utils/object.d.ts index 64eece16..ec2bde55 100644 --- a/dist/js/utils/object.d.ts +++ b/dist/js/utils/object.d.ts @@ -1,4 +1,6 @@ -import { NameResultSchema } from "@mat3ra/esse/dist/js/types"; +export type NameResultSchema = { + name: string; +}; /** * @summary Safely convert input to { name: str } if it is not already * @param name {String|Object} the input to convert