From 5233d81b2c4f83d4d3f49a222a74333426f707e3 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Tue, 25 Feb 2025 18:04:23 +0200 Subject: [PATCH] chore: better in_memory TS definition --- dist/js/entity/in_memory.d.ts | 8 +- dist/js/entity/in_memory.js | 15 ++- dist/js/entity/mixins/context.d.ts | 15 ++- dist/js/entity/mixins/context_runtime.d.ts | 5 +- dist/js/entity/mixins/flowchart.d.ts | 10 +- dist/js/entity/mixins/hash.d.ts | 10 +- dist/js/entity/mixins/props.d.ts | 35 ++++-- dist/js/entity/mixins/repetition.d.ts | 5 +- dist/js/entity/mixins/runtime_items.d.ts | 15 ++- dist/js/entity/other.d.ts | 135 ++++++++++++++++----- dist/js/entity/set.d.ts | 10 +- dist/js/entity/set/factory.d.ts | 10 +- dist/js/entity/set/mixins.d.ts | 10 +- dist/js/entity/set/ordered.d.ts | 10 +- dist/js/entity/set/ordered/mixins.d.ts | 10 +- src/js/entity/in_memory.ts | 18 ++- 16 files changed, 257 insertions(+), 64 deletions(-) diff --git a/dist/js/entity/in_memory.d.ts b/dist/js/entity/in_memory.d.ts index 48e03770..81feb6fd 100644 --- a/dist/js/entity/in_memory.d.ts +++ b/dist/js/entity/in_memory.d.ts @@ -2,7 +2,8 @@ import { AnyObject } from "@mat3ra/esse/dist/js/esse/types"; import { JSONSchema } from "@mat3ra/esse/dist/js/esse/utils"; import { BaseInMemoryEntitySchema, EntityReferenceSchema } from "@mat3ra/esse/dist/js/types"; export declare enum ValidationErrorCode { - IN_MEMORY_ENTITY_DATA_INVALID = "IN_MEMORY_ENTITY_DATA_INVALID" + IN_MEMORY_ENTITY_DATA_INVALID = "IN_MEMORY_ENTITY_DATA_INVALID", + ENTITY_REFERENCE_ERROR = "ENTITY_REFERENCE_ERROR" } interface ErrorDetails { error?: object | null; @@ -64,7 +65,10 @@ export declare class InMemoryEntity implements BaseInMemoryEntitySchema { * @param byIdOnly if true, return only the id * @returns identifying data */ - getAsEntityReference(byIdOnly?: boolean): EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; /** * @summary Pluck an entity from a collection by name. * If no name is provided and no entity has prop isDefault, return the first entity diff --git a/dist/js/entity/in_memory.js b/dist/js/entity/in_memory.js index 02a59d30..355e4a5e 100644 --- a/dist/js/entity/in_memory.js +++ b/dist/js/entity/in_memory.js @@ -45,6 +45,7 @@ const clone_1 = require("../utils/clone"); var ValidationErrorCode; (function (ValidationErrorCode) { ValidationErrorCode["IN_MEMORY_ENTITY_DATA_INVALID"] = "IN_MEMORY_ENTITY_DATA_INVALID"; + ValidationErrorCode["ENTITY_REFERENCE_ERROR"] = "ENTITY_REFERENCE_ERROR"; })(ValidationErrorCode || (exports.ValidationErrorCode = ValidationErrorCode = {})); class EntityError extends Error { constructor({ code, details }) { @@ -180,12 +181,16 @@ class InMemoryEntity { getClsName() { return this.constructor.name; } - /** - * @summary get small identifying payload of object - * @param byIdOnly if true, return only the id - * @returns identifying data - */ getAsEntityReference(byIdOnly = false) { + if (!this.id) { + throw new EntityError({ + code: ValidationErrorCode.ENTITY_REFERENCE_ERROR, + details: { + json: this._json, + schema: this.constructor.jsonSchema || {}, + }, + }); + } if (byIdOnly) { return { _id: this.id }; } diff --git a/dist/js/entity/mixins/context.d.ts b/dist/js/entity/mixins/context.d.ts index 8009d7d3..fac9ad31 100644 --- a/dist/js/entity/mixins/context.d.ts +++ b/dist/js/entity/mixins/context.d.ts @@ -27,7 +27,10 @@ export declare function ContextAndRenderFieldsMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -59,7 +62,10 @@ export declare function DomainContextProviderMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -92,7 +98,10 @@ export declare function ImportantSettingsProviderMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/mixins/context_runtime.d.ts b/dist/js/entity/mixins/context_runtime.d.ts index db2ce699..7d021507 100644 --- a/dist/js/entity/mixins/context_runtime.d.ts +++ b/dist/js/entity/mixins/context_runtime.d.ts @@ -23,7 +23,10 @@ export declare function RuntimeContextFieldMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/mixins/flowchart.d.ts b/dist/js/entity/mixins/flowchart.d.ts index 67b7ad39..b43d29f8 100644 --- a/dist/js/entity/mixins/flowchart.d.ts +++ b/dist/js/entity/mixins/flowchart.d.ts @@ -20,7 +20,10 @@ export declare function FlowchartItemMixin( isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -55,7 +58,10 @@ export declare function FlowchartEntityMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/mixins/hash.d.ts b/dist/js/entity/mixins/hash.d.ts index 07e856e4..be5f4cea 100644 --- a/dist/js/entity/mixins/hash.d.ts +++ b/dist/js/entity/mixins/hash.d.ts @@ -24,7 +24,10 @@ export declare function HashedEntityMixin(s isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -53,7 +56,10 @@ export declare function HashedInputArrayMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/mixins/props.d.ts b/dist/js/entity/mixins/props.d.ts index 5699b79d..9552931a 100644 --- a/dist/js/entity/mixins/props.d.ts +++ b/dist/js/entity/mixins/props.d.ts @@ -19,7 +19,10 @@ export declare function DefaultableMixin = isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -50,7 +53,10 @@ export declare function TaggableMixin(super isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -78,7 +84,10 @@ export declare function HasScopeTrackMixin( isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -107,7 +116,10 @@ export declare function HasMetadataMixin(su isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -136,7 +148,10 @@ export declare function HasDescriptionMixin isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -165,7 +180,10 @@ export declare function NamedEntityMixin(su isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -194,7 +212,10 @@ export declare function HasConsistencyChecksMixin; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/mixins/repetition.d.ts b/dist/js/entity/mixins/repetition.d.ts index 7d244075..adacdafa 100644 --- a/dist/js/entity/mixins/repetition.d.ts +++ b/dist/js/entity/mixins/repetition.d.ts @@ -31,7 +31,10 @@ export declare function HasRepetitionMixin( isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/mixins/runtime_items.d.ts b/dist/js/entity/mixins/runtime_items.d.ts index c75b0f28..87f6ead9 100644 --- a/dist/js/entity/mixins/runtime_items.d.ts +++ b/dist/js/entity/mixins/runtime_items.d.ts @@ -37,7 +37,10 @@ export declare function RuntimeItemsMixin(s isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -103,7 +106,10 @@ export declare function RuntimeItemsUILogicMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -133,7 +139,10 @@ export declare function RuntimeItemsUIAllowedMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/other.d.ts b/dist/js/entity/other.d.ts index 15412c98..fe7575c1 100644 --- a/dist/js/entity/other.d.ts +++ b/dist/js/entity/other.d.ts @@ -17,7 +17,10 @@ declare const DefaultableInMemoryEntity_base: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -50,7 +53,10 @@ export declare const NamedInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -79,7 +85,10 @@ export declare const NamedDefaultableInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -106,7 +115,10 @@ export declare const NamedDefaultableInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -137,7 +149,10 @@ export declare const HasMetadataNamedDefaultableInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -165,7 +180,10 @@ export declare const HasMetadataNamedDefaultableInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -192,7 +210,10 @@ export declare const HasMetadataNamedDefaultableInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -223,7 +244,10 @@ export declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEnti isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -251,7 +275,10 @@ export declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEnti isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -279,7 +306,10 @@ export declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEnti isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -306,7 +336,10 @@ export declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEnti isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -341,7 +374,10 @@ export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -376,7 +412,10 @@ export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -404,7 +443,10 @@ export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -431,7 +473,10 @@ export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -469,7 +514,10 @@ export declare const NamedDefaultableRepetitionContextAndRenderInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -504,7 +552,10 @@ export declare const NamedDefaultableRepetitionContextAndRenderInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -532,7 +583,10 @@ export declare const NamedDefaultableRepetitionContextAndRenderInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -559,7 +613,10 @@ export declare const NamedDefaultableRepetitionContextAndRenderInMemoryEntity: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -590,7 +647,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -625,7 +685,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -657,7 +720,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -686,7 +752,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -741,7 +810,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -776,7 +848,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -804,7 +879,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -831,7 +909,10 @@ export declare const NamedDefaultableRepetitionRuntimeItemsImportantSettingsCont isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/set.d.ts b/dist/js/entity/set.d.ts index a5d2e6bf..afd3fefe 100644 --- a/dist/js/entity/set.d.ts +++ b/dist/js/entity/set.d.ts @@ -17,7 +17,10 @@ declare const InMemoryEntitySet_base: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; @@ -58,7 +61,10 @@ declare const InMemoryEntitySet_base: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/set/factory.d.ts b/dist/js/entity/set/factory.d.ts index 4c0f913a..539455b1 100644 --- a/dist/js/entity/set/factory.d.ts +++ b/dist/js/entity/set/factory.d.ts @@ -22,7 +22,10 @@ export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, ordered isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity; id: string; _id: string; @@ -50,7 +53,10 @@ export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, ordered isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/set/mixins.d.ts b/dist/js/entity/set/mixins.d.ts index 089892a8..b7b6bc91 100644 --- a/dist/js/entity/set/mixins.d.ts +++ b/dist/js/entity/set/mixins.d.ts @@ -34,7 +34,10 @@ export declare function InMemoryEntityInSetMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; @@ -62,7 +65,10 @@ export declare function InMemoryEntitySetMixin; getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/set/ordered.d.ts b/dist/js/entity/set/ordered.d.ts index 4ffd9996..4fe46153 100644 --- a/dist/js/entity/set/ordered.d.ts +++ b/dist/js/entity/set/ordered.d.ts @@ -18,7 +18,10 @@ export declare const OrderedInMemoryEntitySet: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity; id: string; _id: string; @@ -46,7 +49,10 @@ export declare const OrderedInMemoryEntitySet: { isValid(): boolean; readonly cls: string; getClsName(): string; - getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema; + getAsEntityReference(byIdOnly: true): { + _id: string; + }; + getAsEntityReference(byIdOnly: false): Required; getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity; id: string; _id: string; diff --git a/dist/js/entity/set/ordered/mixins.d.ts b/dist/js/entity/set/ordered/mixins.d.ts index 983bb3d8..fb3b3c93 100644 --- a/dist/js/entity/set/ordered/mixins.d.ts +++ b/dist/js/entity/set/ordered/mixins.d.ts @@ -19,7 +19,10 @@ export declare function OrderedInMemoryEntitySetMixin; getEntityByName(entities: import("../../in_memory").InMemoryEntity[], entity: string, name: string): import("../../in_memory").InMemoryEntity; id: string; _id: string; @@ -52,7 +55,10 @@ export declare function OrderedInMemoryEntityInSetMixin; getEntityByName(entities: import("../../in_memory").InMemoryEntity[], entity: string, name: string): import("../../in_memory").InMemoryEntity; id: string; _id: string; diff --git a/src/js/entity/in_memory.ts b/src/js/entity/in_memory.ts index c52aecc9..3eb6f6c1 100644 --- a/src/js/entity/in_memory.ts +++ b/src/js/entity/in_memory.ts @@ -10,6 +10,7 @@ import { clone, deepClone } from "../utils/clone"; export enum ValidationErrorCode { IN_MEMORY_ENTITY_DATA_INVALID = "IN_MEMORY_ENTITY_DATA_INVALID", + ENTITY_REFERENCE_ERROR = "ENTITY_REFERENCE_ERROR", } interface ErrorDetails { @@ -192,10 +193,25 @@ export class InMemoryEntity implements BaseInMemoryEntitySchema { * @param byIdOnly if true, return only the id * @returns identifying data */ - getAsEntityReference(byIdOnly = false): EntityReferenceSchema { + getAsEntityReference(byIdOnly: true): { _id: string }; + + getAsEntityReference(byIdOnly: false): Required; + + getAsEntityReference(byIdOnly = false) { + if (!this.id) { + throw new EntityError({ + code: ValidationErrorCode.ENTITY_REFERENCE_ERROR, + details: { + json: this._json, + schema: (this.constructor as typeof InMemoryEntity).jsonSchema || {}, + }, + }); + } + if (byIdOnly) { return { _id: this.id }; } + return { _id: this.id, slug: this.slug,