Skip to content
Merged
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/context/mixins.d.ts → dist/js/context/mixins.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationSchemaBase, JobSchema, MaterialSchema, WorkflowSchema } from "@mat3ra/esse/lib/js/types";
import { ApplicationSchemaBase, JobSchema, MaterialSchema, WorkflowSchema } from "@mat3ra/esse/dist/js/types";
import { InMemoryEntity } from "../entity";
type Constructor<T = any> = new (...args: any[]) => T;
export declare function ApplicationContextMixin<T extends Constructor>(superclass: T): {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions dist/entity/in_memory.d.ts → dist/js/entity/in_memory.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSONSchema } from "@mat3ra/esse/lib/js/esse/utils";
import { EntityReferenceSchema } from "@mat3ra/esse/lib/js/types";
import { JSONSchema } from "@mat3ra/esse/dist/js/esse/utils";
import { EntityReferenceSchema } from "@mat3ra/esse/dist/js/types";
export declare enum ValidationErrorCode {
IN_MEMORY_ENTITY_DATA_INVALID = "IN_MEMORY_ENTITY_DATA_INVALID"
}
Expand Down Expand Up @@ -36,6 +36,11 @@ export declare class InMemoryEntity {
* @summary Remove a prop
*/
unsetProp(name: string): void;
/**
* Updates internal JSON. Works the same as Mongo's $set operator
* @see https://www.mongodb.com/docs/manual/reference/operator/update/set/#-set
*/
setProps(json?: AnyObject): this;
/**
* @summary Array of fields to exclude from resulted JSON
*/
Expand Down
32 changes: 27 additions & 5 deletions dist/entity/in_memory.js → dist/js/entity/in_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryEntity = exports.EntityError = exports.ValidationErrorCode = void 0;
const ajv = __importStar(require("@mat3ra/esse/lib/js/utils/ajv"));
const ajv = __importStar(require("@mat3ra/esse/dist/js/utils/ajv"));
const get_1 = __importDefault(require("lodash/get"));
const omit_1 = __importDefault(require("lodash/omit"));
const set_1 = __importDefault(require("lodash/set"));
const clone_1 = require("../utils/clone");
var ValidationErrorCode;
(function (ValidationErrorCode) {
Expand Down Expand Up @@ -64,14 +65,23 @@ class InMemoryEntity {
* @summary Set a prop
*/
setProp(name, value) {
this._json[name] = value;
// lodash.set is required to support dot-notation in keys (e.g. "compute.cluster.fqdn")
(0, set_1.default)(this._json, name, value);
}
/**
* @summary Remove a prop
*/
unsetProp(name) {
delete this._json[name];
}
/**
* Updates internal JSON. Works the same as Mongo's $set operator
* @see https://www.mongodb.com/docs/manual/reference/operator/update/set/#-set
*/
setProps(json = {}) {
Object.entries(json).forEach(([key, value]) => this.setProp(key, value));
return this;
}
/**
* @summary Array of fields to exclude from resulted JSON
*/
Expand All @@ -90,11 +100,10 @@ class InMemoryEntity {
* @summary Clone this entity
*/
clone(extraContext) {
const object = new this.constructor({
return new this.constructor({
...this.toJSON(),
...extraContext,
});
return object;
}
static validateData(data, clean = false) {
if (!this.jsonSchema) {
Expand Down Expand Up @@ -127,7 +136,20 @@ class InMemoryEntity {
}
}
clean(config) {
return this.constructor.validateData(config, true);
var _a, _b, _c;
try {
return this.constructor.validateData(config, true);
}
catch (err) {
if (err instanceof EntityError) {
console.error({
error: JSON.stringify((_a = err.details) === null || _a === void 0 ? void 0 : _a.error),
json: JSON.stringify((_b = err.details) === null || _b === void 0 ? void 0 : _b.json),
schema: JSON.stringify((_c = err.details) === null || _c === void 0 ? void 0 : _c.schema),
});
}
throw err;
}
}
isValid() {
try {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export declare function ContextAndRenderFieldsMixin<T extends InMemoryEntityCons
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: AnyObject): any;
toJSON(exclude?: string[]): AnyObject;
toJSONSafe(exclude?: string[]): AnyObject;
toJSONQuick(exclude?: string[]): AnyObject;
Expand All @@ -28,7 +29,7 @@ export declare function ContextAndRenderFieldsMixin<T extends InMemoryEntityCons
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
Expand All @@ -44,6 +45,7 @@ export declare function DomainContextProviderMixin<T extends InMemoryEntityConst
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: AnyObject): any;
toJSON(exclude?: string[]): AnyObject;
toJSONSafe(exclude?: string[]): AnyObject;
toJSONQuick(exclude?: string[]): AnyObject;
Expand All @@ -56,7 +58,7 @@ export declare function DomainContextProviderMixin<T extends InMemoryEntityConst
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
Expand All @@ -73,6 +75,7 @@ export declare function ImportantSettingsProviderMixin<T extends InMemoryEntityC
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: AnyObject): any;
toJSON(exclude?: string[]): AnyObject;
toJSONSafe(exclude?: string[]): AnyObject;
toJSONQuick(exclude?: string[]): AnyObject;
Expand All @@ -85,7 +88,7 @@ export declare function ImportantSettingsProviderMixin<T extends InMemoryEntityC
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JobBaseSchema } from "@mat3ra/esse/lib/js/types";
import { JobBaseSchema } from "@mat3ra/esse/dist/js/types";
import { InMemoryEntityConstructor } from "../in_memory";
type RuntimeContext = Required<JobBaseSchema>["runtimeContext"];
export declare function RuntimeContextFieldMixin<T extends InMemoryEntityConstructor>(superclass: T): {
Expand All @@ -14,6 +14,7 @@ export declare function RuntimeContextFieldMixin<T extends InMemoryEntityConstru
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("../in_memory").AnyObject): any;
toJSONSafe(exclude?: string[]): import("../in_memory").AnyObject;
toJSONQuick(exclude?: string[]): import("../in_memory").AnyObject;
clone(extraContext?: object | undefined): any;
Expand All @@ -25,7 +26,7 @@ export declare function RuntimeContextFieldMixin<T extends InMemoryEntityConstru
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export declare function FlowchartItemMixin<T extends InMemoryEntityConstructor>(
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("../in_memory").AnyObject): any;
toJSON(exclude?: string[]): import("../in_memory").AnyObject;
toJSONSafe(exclude?: string[]): import("../in_memory").AnyObject;
toJSONQuick(exclude?: string[]): import("../in_memory").AnyObject;
Expand All @@ -22,7 +23,7 @@ export declare function FlowchartItemMixin<T extends InMemoryEntityConstructor>(
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
Expand All @@ -41,6 +42,7 @@ export declare function FlowchartEntityMixin<T extends InMemoryEntityConstructor
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("../in_memory").AnyObject): any;
toJSON(exclude?: string[]): import("../in_memory").AnyObject;
toJSONSafe(exclude?: string[]): import("../in_memory").AnyObject;
toJSONQuick(exclude?: string[]): import("../in_memory").AnyObject;
Expand All @@ -53,7 +55,7 @@ export declare function FlowchartEntityMixin<T extends InMemoryEntityConstructor
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecutionUnitInputItemSchemaForPhysicsBasedSimulationEngines } from "@mat3ra/esse/lib/js/types";
import { ExecutionUnitInputItemSchemaForPhysicsBasedSimulationEngines } from "@mat3ra/esse/dist/js/types";
import { InMemoryEntityConstructor } from "../in_memory";
export declare function HashedEntityMixin<T extends InMemoryEntityConstructor>(superclass: T): {
new (...args: any[]): {
Expand All @@ -14,6 +14,7 @@ export declare function HashedEntityMixin<T extends InMemoryEntityConstructor>(s
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("../in_memory").AnyObject): any;
toJSON(exclude?: string[]): import("../in_memory").AnyObject;
toJSONSafe(exclude?: string[]): import("../in_memory").AnyObject;
toJSONQuick(exclude?: string[]): import("../in_memory").AnyObject;
Expand All @@ -26,7 +27,7 @@ export declare function HashedEntityMixin<T extends InMemoryEntityConstructor>(s
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
Expand All @@ -39,6 +40,7 @@ export declare function HashedInputArrayMixin<T extends InMemoryEntityConstructo
prop<T_2 = undefined>(name: string): T_2 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("../in_memory").AnyObject): any;
toJSON(exclude?: string[]): import("../in_memory").AnyObject;
toJSONSafe(exclude?: string[]): import("../in_memory").AnyObject;
toJSONQuick(exclude?: string[]): import("../in_memory").AnyObject;
Expand All @@ -51,7 +53,7 @@ export declare function HashedInputArrayMixin<T extends InMemoryEntityConstructo
getClsName(): string;
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/lib/js/types").EntityReferenceSchema;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & T;
File renamed without changes.
Loading