Skip to content

Commit 9e262b2

Browse files
authored
Merge pull request #108 from Exabyte-io/chore/SOF-7579
SOF-7579: better in_memory TS definition
2 parents 1922da6 + 5233d81 commit 9e262b2

File tree

16 files changed

+257
-64
lines changed

16 files changed

+257
-64
lines changed

dist/js/entity/in_memory.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
22
import { JSONSchema } from "@mat3ra/esse/dist/js/esse/utils";
33
import { BaseInMemoryEntitySchema, EntityReferenceSchema } from "@mat3ra/esse/dist/js/types";
44
export declare enum ValidationErrorCode {
5-
IN_MEMORY_ENTITY_DATA_INVALID = "IN_MEMORY_ENTITY_DATA_INVALID"
5+
IN_MEMORY_ENTITY_DATA_INVALID = "IN_MEMORY_ENTITY_DATA_INVALID",
6+
ENTITY_REFERENCE_ERROR = "ENTITY_REFERENCE_ERROR"
67
}
78
interface ErrorDetails {
89
error?: object | null;
@@ -64,7 +65,10 @@ export declare class InMemoryEntity implements BaseInMemoryEntitySchema {
6465
* @param byIdOnly if true, return only the id
6566
* @returns identifying data
6667
*/
67-
getAsEntityReference(byIdOnly?: boolean): EntityReferenceSchema;
68+
getAsEntityReference(byIdOnly: true): {
69+
_id: string;
70+
};
71+
getAsEntityReference(byIdOnly: false): Required<EntityReferenceSchema>;
6872
/**
6973
* @summary Pluck an entity from a collection by name.
7074
* If no name is provided and no entity has prop isDefault, return the first entity

dist/js/entity/in_memory.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const clone_1 = require("../utils/clone");
4545
var ValidationErrorCode;
4646
(function (ValidationErrorCode) {
4747
ValidationErrorCode["IN_MEMORY_ENTITY_DATA_INVALID"] = "IN_MEMORY_ENTITY_DATA_INVALID";
48+
ValidationErrorCode["ENTITY_REFERENCE_ERROR"] = "ENTITY_REFERENCE_ERROR";
4849
})(ValidationErrorCode || (exports.ValidationErrorCode = ValidationErrorCode = {}));
4950
class EntityError extends Error {
5051
constructor({ code, details }) {
@@ -180,12 +181,16 @@ class InMemoryEntity {
180181
getClsName() {
181182
return this.constructor.name;
182183
}
183-
/**
184-
* @summary get small identifying payload of object
185-
* @param byIdOnly if true, return only the id
186-
* @returns identifying data
187-
*/
188184
getAsEntityReference(byIdOnly = false) {
185+
if (!this.id) {
186+
throw new EntityError({
187+
code: ValidationErrorCode.ENTITY_REFERENCE_ERROR,
188+
details: {
189+
json: this._json,
190+
schema: this.constructor.jsonSchema || {},
191+
},
192+
});
193+
}
189194
if (byIdOnly) {
190195
return { _id: this.id };
191196
}

dist/js/entity/mixins/context.d.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export declare function ContextAndRenderFieldsMixin<T extends InMemoryEntityCons
2727
isValid(): boolean;
2828
readonly cls: string;
2929
getClsName(): string;
30-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
30+
getAsEntityReference(byIdOnly: true): {
31+
_id: string;
32+
};
33+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
3134
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
3235
id: string;
3336
_id: string;
@@ -59,7 +62,10 @@ export declare function DomainContextProviderMixin<T extends InMemoryEntityConst
5962
isValid(): boolean;
6063
readonly cls: string;
6164
getClsName(): string;
62-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
65+
getAsEntityReference(byIdOnly: true): {
66+
_id: string;
67+
};
68+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
6369
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
6470
id: string;
6571
_id: string;
@@ -92,7 +98,10 @@ export declare function ImportantSettingsProviderMixin<T extends InMemoryEntityC
9298
isValid(): boolean;
9399
readonly cls: string;
94100
getClsName(): string;
95-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
101+
getAsEntityReference(byIdOnly: true): {
102+
_id: string;
103+
};
104+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
96105
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
97106
id: string;
98107
_id: string;

dist/js/entity/mixins/context_runtime.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export declare function RuntimeContextFieldMixin<T extends InMemoryEntityConstru
2323
isValid(): boolean;
2424
readonly cls: string;
2525
getClsName(): string;
26-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
26+
getAsEntityReference(byIdOnly: true): {
27+
_id: string;
28+
};
29+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
2730
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
2831
id: string;
2932
_id: string;

dist/js/entity/mixins/flowchart.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export declare function FlowchartItemMixin<T extends InMemoryEntityConstructor>(
2020
isValid(): boolean;
2121
readonly cls: string;
2222
getClsName(): string;
23-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
23+
getAsEntityReference(byIdOnly: true): {
24+
_id: string;
25+
};
26+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
2427
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
2528
id: string;
2629
_id: string;
@@ -55,7 +58,10 @@ export declare function FlowchartEntityMixin<T extends InMemoryEntityConstructor
5558
isValid(): boolean;
5659
readonly cls: string;
5760
getClsName(): string;
58-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
61+
getAsEntityReference(byIdOnly: true): {
62+
_id: string;
63+
};
64+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
5965
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
6066
id: string;
6167
_id: string;

dist/js/entity/mixins/hash.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export declare function HashedEntityMixin<T extends InMemoryEntityConstructor>(s
2424
isValid(): boolean;
2525
readonly cls: string;
2626
getClsName(): string;
27-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
27+
getAsEntityReference(byIdOnly: true): {
28+
_id: string;
29+
};
30+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
2831
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
2932
id: string;
3033
_id: string;
@@ -53,7 +56,10 @@ export declare function HashedInputArrayMixin<T extends InMemoryEntityConstructo
5356
isValid(): boolean;
5457
readonly cls: string;
5558
getClsName(): string;
56-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
59+
getAsEntityReference(byIdOnly: true): {
60+
_id: string;
61+
};
62+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
5763
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
5864
id: string;
5965
_id: string;

dist/js/entity/mixins/props.d.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export declare function DefaultableMixin<T extends Constructor<InMemoryEntity> =
1919
isValid(): boolean;
2020
readonly cls: string;
2121
getClsName(): string;
22-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
22+
getAsEntityReference(byIdOnly: true): {
23+
_id: string;
24+
};
25+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
2326
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
2427
id: string;
2528
_id: string;
@@ -50,7 +53,10 @@ export declare function TaggableMixin<T extends InMemoryEntityConstructor>(super
5053
isValid(): boolean;
5154
readonly cls: string;
5255
getClsName(): string;
53-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
56+
getAsEntityReference(byIdOnly: true): {
57+
_id: string;
58+
};
59+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
5460
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
5561
id: string;
5662
_id: string;
@@ -78,7 +84,10 @@ export declare function HasScopeTrackMixin<T extends InMemoryEntityConstructor>(
7884
isValid(): boolean;
7985
readonly cls: string;
8086
getClsName(): string;
81-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
87+
getAsEntityReference(byIdOnly: true): {
88+
_id: string;
89+
};
90+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
8291
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
8392
id: string;
8493
_id: string;
@@ -107,7 +116,10 @@ export declare function HasMetadataMixin<T extends InMemoryEntityConstructor>(su
107116
isValid(): boolean;
108117
readonly cls: string;
109118
getClsName(): string;
110-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
119+
getAsEntityReference(byIdOnly: true): {
120+
_id: string;
121+
};
122+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
111123
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
112124
id: string;
113125
_id: string;
@@ -136,7 +148,10 @@ export declare function HasDescriptionMixin<T extends InMemoryEntityConstructor>
136148
isValid(): boolean;
137149
readonly cls: string;
138150
getClsName(): string;
139-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
151+
getAsEntityReference(byIdOnly: true): {
152+
_id: string;
153+
};
154+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
140155
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
141156
id: string;
142157
_id: string;
@@ -165,7 +180,10 @@ export declare function NamedEntityMixin<T extends InMemoryEntityConstructor>(su
165180
isValid(): boolean;
166181
readonly cls: string;
167182
getClsName(): string;
168-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
183+
getAsEntityReference(byIdOnly: true): {
184+
_id: string;
185+
};
186+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
169187
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
170188
id: string;
171189
_id: string;
@@ -194,7 +212,10 @@ export declare function HasConsistencyChecksMixin<T extends InMemoryEntityConstr
194212
isValid(): boolean;
195213
readonly cls: string;
196214
getClsName(): string;
197-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
215+
getAsEntityReference(byIdOnly: true): {
216+
_id: string;
217+
};
218+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
198219
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
199220
id: string;
200221
_id: string;

dist/js/entity/mixins/repetition.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export declare function HasRepetitionMixin<T extends InMemoryEntityConstructor>(
3131
isValid(): boolean;
3232
readonly cls: string;
3333
getClsName(): string;
34-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
34+
getAsEntityReference(byIdOnly: true): {
35+
_id: string;
36+
};
37+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
3538
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
3639
id: string;
3740
_id: string;

dist/js/entity/mixins/runtime_items.d.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export declare function RuntimeItemsMixin<T extends InMemoryEntityConstructor>(s
3737
isValid(): boolean;
3838
readonly cls: string;
3939
getClsName(): string;
40-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
40+
getAsEntityReference(byIdOnly: true): {
41+
_id: string;
42+
};
43+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
4144
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
4245
id: string;
4346
_id: string;
@@ -103,7 +106,10 @@ export declare function RuntimeItemsUILogicMixin<T extends InMemoryEntityConstru
103106
isValid(): boolean;
104107
readonly cls: string;
105108
getClsName(): string;
106-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
109+
getAsEntityReference(byIdOnly: true): {
110+
_id: string;
111+
};
112+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
107113
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
108114
id: string;
109115
_id: string;
@@ -133,7 +139,10 @@ export declare function RuntimeItemsUIAllowedMixin<T extends InMemoryEntityConst
133139
isValid(): boolean;
134140
readonly cls: string;
135141
getClsName(): string;
136-
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
142+
getAsEntityReference(byIdOnly: true): {
143+
_id: string;
144+
};
145+
getAsEntityReference(byIdOnly: false): Required<import("@mat3ra/esse/dist/js/types").EntityReferenceSchema>;
137146
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
138147
id: string;
139148
_id: string;

0 commit comments

Comments
 (0)