@twin.org/entity 0.0.2-next.20 → 0.0.2-next.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.cjs
CHANGED
|
@@ -300,7 +300,7 @@ class EntityConditions {
|
|
|
300
300
|
}
|
|
301
301
|
if ("conditions" in condition) {
|
|
302
302
|
// It's a group of comparisons, so check the individual items and combine with the logical operator
|
|
303
|
-
const results = condition.conditions.map(c =>
|
|
303
|
+
const results = condition.conditions.map(c => EntityConditions.check(entity, c));
|
|
304
304
|
if ((condition.logicalOperator ?? LogicalOperator.And) === LogicalOperator.And) {
|
|
305
305
|
return results.every(Boolean);
|
|
306
306
|
}
|
|
@@ -461,9 +461,8 @@ class EntityConditions {
|
|
|
461
461
|
class EntitySchemaHelper {
|
|
462
462
|
/**
|
|
463
463
|
* Runtime name for the class.
|
|
464
|
-
* @internal
|
|
465
464
|
*/
|
|
466
|
-
static
|
|
465
|
+
static CLASS_NAME = "EntitySchemaHelper";
|
|
467
466
|
/**
|
|
468
467
|
* Get the schema for the specified object.
|
|
469
468
|
* @param target The object to get the schema data for.
|
|
@@ -480,13 +479,13 @@ class EntitySchemaHelper {
|
|
|
480
479
|
* @throws If no primary key was found, or more than one.
|
|
481
480
|
*/
|
|
482
481
|
static getPrimaryKey(entitySchema) {
|
|
483
|
-
core.Guards.object(EntitySchemaHelper.
|
|
482
|
+
core.Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
484
483
|
const primaryKeys = (entitySchema.properties ?? [])?.filter(p => p.isPrimary);
|
|
485
484
|
if (primaryKeys.length === 0) {
|
|
486
|
-
throw new core.GeneralError(EntitySchemaHelper.
|
|
485
|
+
throw new core.GeneralError(EntitySchemaHelper.CLASS_NAME, "noIsPrimary");
|
|
487
486
|
}
|
|
488
487
|
if (primaryKeys.length > 1) {
|
|
489
|
-
throw new core.GeneralError(EntitySchemaHelper.
|
|
488
|
+
throw new core.GeneralError(EntitySchemaHelper.CLASS_NAME, "multipleIsPrimary");
|
|
490
489
|
}
|
|
491
490
|
return primaryKeys[0];
|
|
492
491
|
}
|
|
@@ -496,7 +495,7 @@ class EntitySchemaHelper {
|
|
|
496
495
|
* @returns The sort keys from the schema or undefined if there are none.
|
|
497
496
|
*/
|
|
498
497
|
static getSortProperties(entitySchema) {
|
|
499
|
-
core.Guards.object(EntitySchemaHelper.
|
|
498
|
+
core.Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
500
499
|
const sortFields = (entitySchema.properties ?? []).filter(p => !core.Is.undefined(p.sortDirection));
|
|
501
500
|
return sortFields.length > 0
|
|
502
501
|
? sortFields.map(p => ({
|
|
@@ -513,7 +512,7 @@ class EntitySchemaHelper {
|
|
|
513
512
|
* @returns The finalised sort keys.
|
|
514
513
|
*/
|
|
515
514
|
static buildSortProperties(entitySchema, overrideSortKeys) {
|
|
516
|
-
core.Guards.object(EntitySchemaHelper.
|
|
515
|
+
core.Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
517
516
|
let finalSortKeys;
|
|
518
517
|
if (core.Is.arrayValue(overrideSortKeys)) {
|
|
519
518
|
finalSortKeys = [];
|
|
@@ -540,11 +539,11 @@ class EntitySchemaHelper {
|
|
|
540
539
|
* @throws If the entity is invalid.
|
|
541
540
|
*/
|
|
542
541
|
static validateEntity(entity, entitySchema) {
|
|
543
|
-
core.Guards.object(EntitySchemaHelper.
|
|
544
|
-
core.Guards.object(EntitySchemaHelper.
|
|
542
|
+
core.Guards.object(EntitySchemaHelper.CLASS_NAME, "entity", entity);
|
|
543
|
+
core.Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
545
544
|
const properties = entitySchema.properties ?? [];
|
|
546
545
|
if (properties.length === 0 && core.Is.objectValue(entity)) {
|
|
547
|
-
throw new core.GeneralError(EntitySchemaHelper.
|
|
546
|
+
throw new core.GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidEntityProperties");
|
|
548
547
|
}
|
|
549
548
|
const allKeys = Object.keys(entity);
|
|
550
549
|
for (const prop of properties) {
|
|
@@ -556,7 +555,7 @@ class EntitySchemaHelper {
|
|
|
556
555
|
if (core.Is.empty(value)) {
|
|
557
556
|
// If the value is empty but the property is not optional, then it's invalid
|
|
558
557
|
if (!prop.optional) {
|
|
559
|
-
throw new core.GeneralError(EntitySchemaHelper.
|
|
558
|
+
throw new core.GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidOptional", {
|
|
560
559
|
property: prop.property,
|
|
561
560
|
type: prop.type
|
|
562
561
|
});
|
|
@@ -573,7 +572,7 @@ class EntitySchemaHelper {
|
|
|
573
572
|
else if (prop.type === "array" && core.Is.array(value)) ;
|
|
574
573
|
else if (prop.type !== typeof value) {
|
|
575
574
|
// The schema type does not match the value type
|
|
576
|
-
throw new core.GeneralError(EntitySchemaHelper.
|
|
575
|
+
throw new core.GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidEntityProperty", {
|
|
577
576
|
value,
|
|
578
577
|
property: prop.property,
|
|
579
578
|
type: prop.type
|
|
@@ -582,7 +581,7 @@ class EntitySchemaHelper {
|
|
|
582
581
|
}
|
|
583
582
|
if (allKeys.length > 0) {
|
|
584
583
|
// There are keys in the entity that are not in the schema
|
|
585
|
-
throw new core.GeneralError(EntitySchemaHelper.
|
|
584
|
+
throw new core.GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidEntityKeys", {
|
|
586
585
|
keys: allKeys.join(", ")
|
|
587
586
|
});
|
|
588
587
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -298,7 +298,7 @@ class EntityConditions {
|
|
|
298
298
|
}
|
|
299
299
|
if ("conditions" in condition) {
|
|
300
300
|
// It's a group of comparisons, so check the individual items and combine with the logical operator
|
|
301
|
-
const results = condition.conditions.map(c =>
|
|
301
|
+
const results = condition.conditions.map(c => EntityConditions.check(entity, c));
|
|
302
302
|
if ((condition.logicalOperator ?? LogicalOperator.And) === LogicalOperator.And) {
|
|
303
303
|
return results.every(Boolean);
|
|
304
304
|
}
|
|
@@ -459,9 +459,8 @@ class EntityConditions {
|
|
|
459
459
|
class EntitySchemaHelper {
|
|
460
460
|
/**
|
|
461
461
|
* Runtime name for the class.
|
|
462
|
-
* @internal
|
|
463
462
|
*/
|
|
464
|
-
static
|
|
463
|
+
static CLASS_NAME = "EntitySchemaHelper";
|
|
465
464
|
/**
|
|
466
465
|
* Get the schema for the specified object.
|
|
467
466
|
* @param target The object to get the schema data for.
|
|
@@ -478,13 +477,13 @@ class EntitySchemaHelper {
|
|
|
478
477
|
* @throws If no primary key was found, or more than one.
|
|
479
478
|
*/
|
|
480
479
|
static getPrimaryKey(entitySchema) {
|
|
481
|
-
Guards.object(EntitySchemaHelper.
|
|
480
|
+
Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
482
481
|
const primaryKeys = (entitySchema.properties ?? [])?.filter(p => p.isPrimary);
|
|
483
482
|
if (primaryKeys.length === 0) {
|
|
484
|
-
throw new GeneralError(EntitySchemaHelper.
|
|
483
|
+
throw new GeneralError(EntitySchemaHelper.CLASS_NAME, "noIsPrimary");
|
|
485
484
|
}
|
|
486
485
|
if (primaryKeys.length > 1) {
|
|
487
|
-
throw new GeneralError(EntitySchemaHelper.
|
|
486
|
+
throw new GeneralError(EntitySchemaHelper.CLASS_NAME, "multipleIsPrimary");
|
|
488
487
|
}
|
|
489
488
|
return primaryKeys[0];
|
|
490
489
|
}
|
|
@@ -494,7 +493,7 @@ class EntitySchemaHelper {
|
|
|
494
493
|
* @returns The sort keys from the schema or undefined if there are none.
|
|
495
494
|
*/
|
|
496
495
|
static getSortProperties(entitySchema) {
|
|
497
|
-
Guards.object(EntitySchemaHelper.
|
|
496
|
+
Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
498
497
|
const sortFields = (entitySchema.properties ?? []).filter(p => !Is.undefined(p.sortDirection));
|
|
499
498
|
return sortFields.length > 0
|
|
500
499
|
? sortFields.map(p => ({
|
|
@@ -511,7 +510,7 @@ class EntitySchemaHelper {
|
|
|
511
510
|
* @returns The finalised sort keys.
|
|
512
511
|
*/
|
|
513
512
|
static buildSortProperties(entitySchema, overrideSortKeys) {
|
|
514
|
-
Guards.object(EntitySchemaHelper.
|
|
513
|
+
Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
515
514
|
let finalSortKeys;
|
|
516
515
|
if (Is.arrayValue(overrideSortKeys)) {
|
|
517
516
|
finalSortKeys = [];
|
|
@@ -538,11 +537,11 @@ class EntitySchemaHelper {
|
|
|
538
537
|
* @throws If the entity is invalid.
|
|
539
538
|
*/
|
|
540
539
|
static validateEntity(entity, entitySchema) {
|
|
541
|
-
Guards.object(EntitySchemaHelper.
|
|
542
|
-
Guards.object(EntitySchemaHelper.
|
|
540
|
+
Guards.object(EntitySchemaHelper.CLASS_NAME, "entity", entity);
|
|
541
|
+
Guards.object(EntitySchemaHelper.CLASS_NAME, "entitySchema", entitySchema);
|
|
543
542
|
const properties = entitySchema.properties ?? [];
|
|
544
543
|
if (properties.length === 0 && Is.objectValue(entity)) {
|
|
545
|
-
throw new GeneralError(EntitySchemaHelper.
|
|
544
|
+
throw new GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidEntityProperties");
|
|
546
545
|
}
|
|
547
546
|
const allKeys = Object.keys(entity);
|
|
548
547
|
for (const prop of properties) {
|
|
@@ -554,7 +553,7 @@ class EntitySchemaHelper {
|
|
|
554
553
|
if (Is.empty(value)) {
|
|
555
554
|
// If the value is empty but the property is not optional, then it's invalid
|
|
556
555
|
if (!prop.optional) {
|
|
557
|
-
throw new GeneralError(EntitySchemaHelper.
|
|
556
|
+
throw new GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidOptional", {
|
|
558
557
|
property: prop.property,
|
|
559
558
|
type: prop.type
|
|
560
559
|
});
|
|
@@ -571,7 +570,7 @@ class EntitySchemaHelper {
|
|
|
571
570
|
else if (prop.type === "array" && Is.array(value)) ;
|
|
572
571
|
else if (prop.type !== typeof value) {
|
|
573
572
|
// The schema type does not match the value type
|
|
574
|
-
throw new GeneralError(EntitySchemaHelper.
|
|
573
|
+
throw new GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidEntityProperty", {
|
|
575
574
|
value,
|
|
576
575
|
property: prop.property,
|
|
577
576
|
type: prop.type
|
|
@@ -580,7 +579,7 @@ class EntitySchemaHelper {
|
|
|
580
579
|
}
|
|
581
580
|
if (allKeys.length > 0) {
|
|
582
581
|
// There are keys in the entity that are not in the schema
|
|
583
|
-
throw new GeneralError(EntitySchemaHelper.
|
|
582
|
+
throw new GeneralError(EntitySchemaHelper.CLASS_NAME, "invalidEntityKeys", {
|
|
584
583
|
keys: allKeys.join(", ")
|
|
585
584
|
});
|
|
586
585
|
}
|
|
@@ -6,6 +6,10 @@ import type { SortDirection } from "../models/sortDirection";
|
|
|
6
6
|
* Class to help with entity schema operations.
|
|
7
7
|
*/
|
|
8
8
|
export declare class EntitySchemaHelper {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static readonly CLASS_NAME: string;
|
|
9
13
|
/**
|
|
10
14
|
* Get the schema for the specified object.
|
|
11
15
|
* @param target The object to get the schema data for.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @twin.org/entity - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.22](https://github.com/twinfoundation/framework/compare/entity-v0.0.2-next.21...entity-v0.0.2-next.22) (2025-10-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **entity:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/nameof bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
16
|
+
* @twin.org/core bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
20
|
+
* @twin.org/validate-locales bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
21
|
+
|
|
22
|
+
## [0.0.2-next.21](https://github.com/twinfoundation/framework/compare/entity-v0.0.2-next.20...entity-v0.0.2-next.21) (2025-10-09)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
* The following workspace dependencies were updated
|
|
33
|
+
* dependencies
|
|
34
|
+
* @twin.org/nameof bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
35
|
+
* @twin.org/core bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
36
|
+
* devDependencies
|
|
37
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
38
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
39
|
+
* @twin.org/validate-locales bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
40
|
+
|
|
3
41
|
## [0.0.2-next.20](https://github.com/twinfoundation/framework/compare/entity-v0.0.2-next.19...entity-v0.0.2-next.20) (2025-10-02)
|
|
4
42
|
|
|
5
43
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.22",
|
|
4
4
|
"description": "Helpers for defining and working with entities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "0.0.2-next.
|
|
18
|
-
"@twin.org/nameof": "0.0.2-next.
|
|
17
|
+
"@twin.org/core": "0.0.2-next.22",
|
|
18
|
+
"@twin.org/nameof": "0.0.2-next.22",
|
|
19
19
|
"reflect-metadata": "0.2.2"
|
|
20
20
|
},
|
|
21
21
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -42,5 +42,9 @@
|
|
|
42
42
|
"iota",
|
|
43
43
|
"framework",
|
|
44
44
|
"blockchain"
|
|
45
|
-
]
|
|
45
|
+
],
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "git+https://github.com/twinfoundation/framework/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://twindev.org"
|
|
46
50
|
}
|