Skip to content

SOF-7640: small mixins cleanups #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: chore/SOF-7644
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions dist/js/entity/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { InMemoryEntity } from "./in_memory";
import { ContextAndRenderFieldsMixin } from "./mixins/context";
import { RuntimeContextFieldMixin } from "./mixins/context_runtime";
import { FlowchartEntityMixin, FlowchartItemMixin } from "./mixins/flowchart";
import { HashedInputArrayMixin } from "./mixins/hash";
import { DefaultableMixin, HasConsistencyChecksMixin, HasDescriptionMixin, HasMetadataMixin, HasScopeTrackMixin, NamedEntityMixin, TaggableMixin } from "./mixins/props";
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";
Expand All @@ -12,4 +11,4 @@ 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, HasConsistencyChecksMixin, DefaultableMixin, HasDescriptionMixin, HasMetadataMixin, TaggableMixin, HasScopeTrackMixin, NamedEntityMixin, RuntimeItemsMixin, RuntimeContextFieldMixin, HashedInputArrayMixin, InMemoryEntitySet, ENTITY_SET_TYPES, constructEntitySetFactoryByConfig, selectorsForEntitySet, InMemoryEntitySetMixin, InMemoryEntityInSetMixin, OrderedInMemoryEntitySetMixin, OrderedInMemoryEntityInSetMixin, ContextAndRenderFieldsMixin, FlowchartEntityMixin, FlowchartItemMixin, };
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, };
10 changes: 1 addition & 9 deletions dist/js/entity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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.HashedInputArrayMixin = exports.RuntimeContextFieldMixin = exports.RuntimeItemsMixin = exports.NamedEntityMixin = exports.HasScopeTrackMixin = exports.TaggableMixin = exports.HasMetadataMixin = exports.HasDescriptionMixin = exports.DefaultableMixin = exports.HasConsistencyChecksMixin = exports.HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableRepetitionRuntimeItemsImportantSettingsContextAndRenderHashedInMemoryEntity = exports.NamedDefaultableRepetitionImportantSettingsInMemoryEntity = exports.NamedDefaultableRepetitionContextAndRenderInMemoryEntity = exports.HasMetadataNamedDefaultableInMemoryEntity = exports.NamedDefaultableInMemoryEntity = exports.DefaultableInMemoryEntity = exports.NamedInMemoryEntity = exports.InMemoryEntity = void 0;
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;
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");
Expand All @@ -43,16 +43,8 @@ Object.defineProperty(exports, "RuntimeContextFieldMixin", { enumerable: true, g
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 hash_1 = require("./mixins/hash");
Object.defineProperty(exports, "HashedInputArrayMixin", { enumerable: true, get: function () { return hash_1.HashedInputArrayMixin; } });
const props_1 = require("./mixins/props");
Object.defineProperty(exports, "DefaultableMixin", { enumerable: true, get: function () { return props_1.DefaultableMixin; } });
Object.defineProperty(exports, "HasConsistencyChecksMixin", { enumerable: true, get: function () { return props_1.HasConsistencyChecksMixin; } });
Object.defineProperty(exports, "HasDescriptionMixin", { enumerable: true, get: function () { return props_1.HasDescriptionMixin; } });
Object.defineProperty(exports, "HasMetadataMixin", { enumerable: true, get: function () { return props_1.HasMetadataMixin; } });
Object.defineProperty(exports, "HasScopeTrackMixin", { enumerable: true, get: function () { return props_1.HasScopeTrackMixin; } });
Object.defineProperty(exports, "NamedEntityMixin", { enumerable: true, get: function () { return props_1.NamedEntityMixin; } });
Object.defineProperty(exports, "TaggableMixin", { enumerable: true, get: function () { return props_1.TaggableMixin; } });
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");
Expand Down
18 changes: 6 additions & 12 deletions dist/js/entity/mixins/DefaultableMixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import type { Constructor } from "../../utils/types";
import { InMemoryEntity } from "../in_memory";
type ClassBase = Constructor<InMemoryEntity> & {
export declare function defaultableEntityMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & DefaultableInMemoryEntity;
export declare function defaultableEntityStaticMixin(Item: Constructor<InMemoryEntity>): DefaultableInMemoryStaticEntity & Constructor<InMemoryEntity> & Constructor<DefaultableInMemoryEntity> & {
defaultConfig?: object | null;
};
export declare function defaultableMixinProps<T extends InMemoryEntity>(item: T): {
export type DefaultableInMemoryEntity = {
isDefault: boolean;
};
declare const staticProperties: {
createDefault<T extends ClassBase>(this: T): InstanceType<T> & DefaultableInMemoryEntity;
export type DefaultableInMemoryStaticEntity = {
createDefault: () => InMemoryEntity & DefaultableInMemoryEntity;
};
export declare function defaultableMixinStaticProps<T extends ClassBase>(Item: T): {
createDefault<T_1 extends ClassBase>(this: T_1): InstanceType<T_1> & DefaultableInMemoryEntity;
};
export type DefaultableInMemoryEntity = ReturnType<typeof defaultableMixinProps>;
export type DefaultableInMemoryEntityConstructor = Constructor<DefaultableInMemoryEntity>;
export type DefaultableConstructor = DefaultableInMemoryEntityConstructor & typeof staticProperties;
export default function DefaultableMixin<S extends ClassBase>(superclass: S): S & DefaultableConstructor;
export {};
export type DefaultableInMemoryEntityConstructor = Constructor<DefaultableInMemoryEntity> & DefaultableInMemoryStaticEntity;
36 changes: 14 additions & 22 deletions dist/js/entity/mixins/DefaultableMixin.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
"use strict";
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultableMixinProps = defaultableMixinProps;
exports.defaultableMixinStaticProps = defaultableMixinStaticProps;
exports.default = DefaultableMixin;
function defaultableMixinProps(item) {
exports.defaultableEntityMixin = defaultableEntityMixin;
exports.defaultableEntityStaticMixin = defaultableEntityStaticMixin;
function defaultableEntityMixin(item) {
// @ts-expect-error
const properties = {
get isDefault() {
return item.prop("isDefault", false);
return this.prop("isDefault", false);
},
set isDefault(isDefault) {
item.setProp("isDefault", isDefault);
this.setProp("isDefault", isDefault);
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
return properties;
}
const staticProperties = {
createDefault() {
return new this(this.defaultConfig);
},
};
function defaultableMixinStaticProps(Item) {
function defaultableEntityStaticMixin(Item) {
// @ts-expect-error
const staticProperties = {
createDefault() {
return new this(this.defaultConfig);
},
};
Object.defineProperties(Item, Object.getOwnPropertyDescriptors(staticProperties));
return staticProperties;
}
function DefaultableMixin(superclass) {
class DefaultableMixin extends superclass {
constructor(...args) {
super(...args);
defaultableMixinProps(this);
}
}
defaultableMixinStaticProps(DefaultableMixin);
return DefaultableMixin;
}
9 changes: 4 additions & 5 deletions dist/js/entity/mixins/HasConsistencyChecksMixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ConsistencyCheck } from "@mat3ra/esse/dist/js/types";
import type { Constructor } from "../../utils/types";
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
export declare function hasConsistencyChecksMixin(item: InMemoryEntity): {
addConsistencyChecks(array: ConsistencyCheck[]): void;
import { InMemoryEntity } from "../in_memory";
export declare function hasConsistencyChecksMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & HasConsistencyChecksInMemoryEntity;
export type HasConsistencyChecksInMemoryEntity = {
consistencyChecks: ConsistencyCheck[];
addConsistencyChecks: (array: ConsistencyCheck[]) => void;
};
export type HasConsistencyChecksInMemoryEntity = ReturnType<typeof hasConsistencyChecksMixin>;
export type HasConsistencyChecksInMemoryEntityConstructor = Constructor<HasConsistencyChecksInMemoryEntity>;
export default function HasConsistencyChecksMixin<S extends InMemoryEntityConstructor>(superclass: S): S & HasConsistencyChecksInMemoryEntityConstructor;
34 changes: 6 additions & 28 deletions dist/js/entity/mixins/HasConsistencyChecksMixin.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasConsistencyChecksMixin = hasConsistencyChecksMixin;
exports.default = HasConsistencyChecksMixin;
function schemaMixin(item) {
const schema = {
function hasConsistencyChecksMixin(item) {
// @ts-expect-error
const properties = {
get consistencyChecks() {
return item.prop("consistencyChecks", []);
return this.prop("consistencyChecks", []);
},
set consistencyChecks(array) {
item.setProp("consistencyChecks", array);
this.setProp("consistencyChecks", array);
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
return schema;
}
function propertiesMixin(item) {
const properties = {
addConsistencyChecks(array) {
item.consistencyChecks = [...(item.consistencyChecks || []), ...array];
this.consistencyChecks = [...(this.consistencyChecks || []), ...array];
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
return properties;
}
function hasConsistencyChecksMixin(item) {
return {
...schemaMixin(item),
...propertiesMixin(item),
};
}
function HasConsistencyChecksMixin(superclass) {
class HasConsistencyChecksMixin extends superclass {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(...args) {
super(...args);
hasConsistencyChecksMixin(this);
}
}
return HasConsistencyChecksMixin;
}
7 changes: 3 additions & 4 deletions dist/js/entity/mixins/HasDescriptionMixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { DescriptionSchema } from "@mat3ra/esse/dist/js/types";
import type { Constructor } from "../../utils/types";
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
export declare function hasDescriptionMixin(item: InMemoryEntity): {
import { InMemoryEntity } from "../in_memory";
export declare function hasDescriptionMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & HasDescriptionInMemoryEntity;
export type HasDescriptionInMemoryEntity = {
description: string;
descriptionObject: DescriptionSchema["descriptionObject"];
};
export type HasDescriptionInMemoryEntity = ReturnType<typeof hasDescriptionMixin>;
export type HasDescriptionInMemoryEntityConstructor = Constructor<HasDescriptionInMemoryEntity>;
export default function HasDescriptionMixin<S extends InMemoryEntityConstructor>(superclass: S): S & HasDescriptionInMemoryEntityConstructor;
31 changes: 9 additions & 22 deletions dist/js/entity/mixins/HasDescriptionMixin.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasDescriptionMixin = hasDescriptionMixin;
exports.default = HasDescriptionMixin;
function schemaMixin(item) {
const schema = {
function hasDescriptionMixin(item) {
// @ts-expect-error
const properties = {
get description() {
return item.prop("description", "");
return this.prop("description", "");
},
set description(string) {
item.setProp("description", string);
this.setProp("description", string);
},
get descriptionObject() {
return item.prop("descriptionObject");
return this.prop("descriptionObject");
},
set descriptionObject(obj) {
item.setProp("descriptionObject", obj);
this.setProp("descriptionObject", obj);
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
return schema;
}
function hasDescriptionMixin(item) {
return schemaMixin(item);
}
function HasDescriptionMixin(superclass) {
class HasDescriptionMixin extends superclass {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(...args) {
super(...args);
hasDescriptionMixin(this);
}
}
return HasDescriptionMixin;
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
return properties;
}
9 changes: 4 additions & 5 deletions dist/js/entity/mixins/HasMetadataMixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Constructor } from "../../utils/types";
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
export declare function hasMetadataMixin(item: InMemoryEntity): {
updateMetadata(object: object): void;
import { InMemoryEntity } from "../in_memory";
export declare function hasMetadataMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & HasMetadataInMemoryEntity;
export type HasMetadataInMemoryEntity = {
metadata: object;
updateMetadata: (object: object) => void;
};
export type HasMetadataInMemoryEntity = ReturnType<typeof hasMetadataMixin>;
export type HasMetadataInMemoryEntityConstructor = Constructor<HasMetadataInMemoryEntity>;
export default function HasMetadataMixin<S extends InMemoryEntityConstructor>(superclass: S): S & HasMetadataInMemoryEntityConstructor;
34 changes: 6 additions & 28 deletions dist/js/entity/mixins/HasMetadataMixin.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasMetadataMixin = hasMetadataMixin;
exports.default = HasMetadataMixin;
function schemaMixin(item) {
const schema = {
function hasMetadataMixin(item) {
// @ts-expect-error
const properties = {
get metadata() {
return item.prop("metadata", {});
return this.prop("metadata", {});
},
set metadata(object) {
item.setProp("metadata", object);
this.setProp("metadata", object);
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(schema));
return schema;
}
function propertiesMixin(item) {
const properties = {
updateMetadata(object) {
item.metadata = { ...item.metadata, ...object };
this.metadata = { ...this.metadata, ...object };
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
return properties;
}
function hasMetadataMixin(item) {
return {
...schemaMixin(item),
...propertiesMixin(item),
};
}
function HasMetadataMixin(superclass) {
class HasMetadataMixin extends superclass {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(...args) {
super(...args);
hasMetadataMixin(this);
}
}
return HasMetadataMixin;
}
9 changes: 4 additions & 5 deletions dist/js/entity/mixins/NamedEntityMixin.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Constructor } from "../../utils/types";
import { InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
export declare function namedEntityMixin(item: InMemoryEntity): {
setName(name: string): void;
import { InMemoryEntity } from "../in_memory";
export declare function namedEntityMixin<T extends InMemoryEntity>(item: T): InMemoryEntity & NamedInMemoryEntity;
export type NamedInMemoryEntity = {
name: string;
setName: (name: string) => void;
};
export type NamedInMemoryEntity = ReturnType<typeof namedEntityMixin>;
export type NamedInMemoryEntityConstructor = Constructor<NamedInMemoryEntity>;
export default function NamedEntityMixin<S extends InMemoryEntityConstructor>(superclass: S): S & NamedInMemoryEntityConstructor;
Loading
Loading