@twin.org/entity 0.0.1-next.2 → 0.0.1-next.21
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 +10 -2
- package/dist/esm/index.mjs +10 -2
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/DecoratorHelper.md +9 -3
- package/docs/reference/classes/EntityConditions.md +12 -4
- package/docs/reference/classes/EntitySchemaHelper.md +15 -5
- package/docs/reference/classes/EntitySorter.md +21 -7
- package/docs/reference/functions/entity.md +3 -1
- package/docs/reference/functions/property.md +3 -1
- package/docs/reference/variables/EntitySchemaFactory.md +1 -1
- package/package.json +3 -29
package/dist/cjs/index.cjs
CHANGED
|
@@ -61,7 +61,7 @@ function property(options) {
|
|
|
61
61
|
const entitySchema = DecoratorHelper.getSchema(target);
|
|
62
62
|
entitySchema.properties ??= [];
|
|
63
63
|
const idx = entitySchema.properties.findIndex(p => p.property === propertyKey);
|
|
64
|
-
if (idx
|
|
64
|
+
if (idx !== -1) {
|
|
65
65
|
entitySchema.properties[idx] = {
|
|
66
66
|
...options,
|
|
67
67
|
property: propertyKey
|
|
@@ -572,7 +572,9 @@ class EntitySorter {
|
|
|
572
572
|
*/
|
|
573
573
|
static compare(entity1, entity2, prop, type, direction = SortDirection.Ascending) {
|
|
574
574
|
let res = 0;
|
|
575
|
-
|
|
575
|
+
const hasProp1 = !core.Is.empty(entity1[prop]);
|
|
576
|
+
const hasProp2 = !core.Is.empty(entity2[prop]);
|
|
577
|
+
if (hasProp1 && hasProp2) {
|
|
576
578
|
if (type === "number" || type === "integer") {
|
|
577
579
|
res = entity1[prop] - entity2[prop];
|
|
578
580
|
}
|
|
@@ -593,6 +595,12 @@ class EntitySorter {
|
|
|
593
595
|
res = entity1[prop].localeCompare(entity2[prop]);
|
|
594
596
|
}
|
|
595
597
|
}
|
|
598
|
+
else if (hasProp1) {
|
|
599
|
+
res = -1;
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
res = 1;
|
|
603
|
+
}
|
|
596
604
|
return direction === SortDirection.Ascending ? res : res * -1;
|
|
597
605
|
}
|
|
598
606
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -59,7 +59,7 @@ function property(options) {
|
|
|
59
59
|
const entitySchema = DecoratorHelper.getSchema(target);
|
|
60
60
|
entitySchema.properties ??= [];
|
|
61
61
|
const idx = entitySchema.properties.findIndex(p => p.property === propertyKey);
|
|
62
|
-
if (idx
|
|
62
|
+
if (idx !== -1) {
|
|
63
63
|
entitySchema.properties[idx] = {
|
|
64
64
|
...options,
|
|
65
65
|
property: propertyKey
|
|
@@ -570,7 +570,9 @@ class EntitySorter {
|
|
|
570
570
|
*/
|
|
571
571
|
static compare(entity1, entity2, prop, type, direction = SortDirection.Ascending) {
|
|
572
572
|
let res = 0;
|
|
573
|
-
|
|
573
|
+
const hasProp1 = !Is.empty(entity1[prop]);
|
|
574
|
+
const hasProp2 = !Is.empty(entity2[prop]);
|
|
575
|
+
if (hasProp1 && hasProp2) {
|
|
574
576
|
if (type === "number" || type === "integer") {
|
|
575
577
|
res = entity1[prop] - entity2[prop];
|
|
576
578
|
}
|
|
@@ -591,6 +593,12 @@ class EntitySorter {
|
|
|
591
593
|
res = entity1[prop].localeCompare(entity2[prop]);
|
|
592
594
|
}
|
|
593
595
|
}
|
|
596
|
+
else if (hasProp1) {
|
|
597
|
+
res = -1;
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
res = 1;
|
|
601
|
+
}
|
|
594
602
|
return direction === SortDirection.Ascending ? res : res * -1;
|
|
595
603
|
}
|
|
596
604
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -26,7 +26,9 @@ Get the schema from the reflection metadata.
|
|
|
26
26
|
|
|
27
27
|
#### Parameters
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
##### target
|
|
30
|
+
|
|
31
|
+
`any`
|
|
30
32
|
|
|
31
33
|
The object to get the schema data from.
|
|
32
34
|
|
|
@@ -50,11 +52,15 @@ Set the schema from the reflection metadata.
|
|
|
50
52
|
|
|
51
53
|
#### Parameters
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
##### target
|
|
56
|
+
|
|
57
|
+
`any`
|
|
54
58
|
|
|
55
59
|
The object to get the schema data from.
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
##### entitySchema
|
|
62
|
+
|
|
63
|
+
[`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
|
|
58
64
|
|
|
59
65
|
The schema to set.
|
|
60
66
|
|
|
@@ -26,11 +26,15 @@ See if the entity matches the conditions.
|
|
|
26
26
|
|
|
27
27
|
#### Parameters
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
##### entity
|
|
30
|
+
|
|
31
|
+
`T`
|
|
30
32
|
|
|
31
33
|
The entity to test.
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
##### condition?
|
|
36
|
+
|
|
37
|
+
[`EntityCondition`](../type-aliases/EntityCondition.md)\<`T`\>
|
|
34
38
|
|
|
35
39
|
The conditions to test.
|
|
36
40
|
|
|
@@ -54,11 +58,15 @@ See if the entity matches the conditions.
|
|
|
54
58
|
|
|
55
59
|
#### Parameters
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
##### entity
|
|
62
|
+
|
|
63
|
+
`T`
|
|
58
64
|
|
|
59
65
|
The entity to test.
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
##### comparator
|
|
68
|
+
|
|
69
|
+
[`IComparator`](../interfaces/IComparator.md)
|
|
62
70
|
|
|
63
71
|
The condition to test.
|
|
64
72
|
|
|
@@ -26,7 +26,9 @@ Get the schema for the specified object.
|
|
|
26
26
|
|
|
27
27
|
#### Parameters
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
##### target
|
|
30
|
+
|
|
31
|
+
`any`
|
|
30
32
|
|
|
31
33
|
The object to get the schema data for.
|
|
32
34
|
|
|
@@ -50,7 +52,9 @@ Get the primary key from the entity schema.
|
|
|
50
52
|
|
|
51
53
|
#### Parameters
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
##### entitySchema
|
|
56
|
+
|
|
57
|
+
[`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
|
|
54
58
|
|
|
55
59
|
The entity schema to find the primary key from.
|
|
56
60
|
|
|
@@ -78,7 +82,9 @@ Get the sort properties from the schema.
|
|
|
78
82
|
|
|
79
83
|
#### Parameters
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
##### entitySchema
|
|
86
|
+
|
|
87
|
+
[`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
|
|
82
88
|
|
|
83
89
|
The entity schema to find the primary key from.
|
|
84
90
|
|
|
@@ -102,11 +108,15 @@ Build sort properties from the schema and override if necessary.
|
|
|
102
108
|
|
|
103
109
|
#### Parameters
|
|
104
110
|
|
|
105
|
-
|
|
111
|
+
##### entitySchema
|
|
112
|
+
|
|
113
|
+
[`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
|
|
106
114
|
|
|
107
115
|
The entity schema to retrieve the default sort keys.
|
|
108
116
|
|
|
109
|
-
|
|
117
|
+
##### overrideSortKeys?
|
|
118
|
+
|
|
119
|
+
`object`[]
|
|
110
120
|
|
|
111
121
|
The override sort keys.
|
|
112
122
|
|
|
@@ -26,11 +26,15 @@ Sort a list of entities using multiple keys and direction.
|
|
|
26
26
|
|
|
27
27
|
#### Parameters
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
##### entities
|
|
30
|
+
|
|
31
|
+
`T`[]
|
|
30
32
|
|
|
31
33
|
The list of entities.
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
##### entitySorters?
|
|
36
|
+
|
|
37
|
+
[`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[]
|
|
34
38
|
|
|
35
39
|
The sort keys to use.
|
|
36
40
|
|
|
@@ -54,23 +58,33 @@ Compare two properties.
|
|
|
54
58
|
|
|
55
59
|
#### Parameters
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
##### entity1
|
|
62
|
+
|
|
63
|
+
`T`
|
|
58
64
|
|
|
59
65
|
The first entity.
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
##### entity2
|
|
68
|
+
|
|
69
|
+
`T`
|
|
62
70
|
|
|
63
71
|
The second entity.
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
##### prop
|
|
74
|
+
|
|
75
|
+
keyof `T`
|
|
66
76
|
|
|
67
77
|
The property to compare.
|
|
68
78
|
|
|
69
|
-
|
|
79
|
+
##### type
|
|
80
|
+
|
|
81
|
+
[`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
|
|
70
82
|
|
|
71
83
|
The type of the property.
|
|
72
84
|
|
|
73
|
-
|
|
85
|
+
##### direction
|
|
86
|
+
|
|
87
|
+
[`SortDirection`](../type-aliases/SortDirection.md) = `SortDirection.Ascending`
|
|
74
88
|
|
|
75
89
|
The direction of the sort.
|
|
76
90
|
|
|
@@ -6,7 +6,9 @@ Decorator to produce schema data for entity.
|
|
|
6
6
|
|
|
7
7
|
## Parameters
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### options?
|
|
10
|
+
|
|
11
|
+
[`IEntitySchemaOptions`](../interfaces/IEntitySchemaOptions.md)
|
|
10
12
|
|
|
11
13
|
The options for the entity.
|
|
12
14
|
|
|
@@ -6,7 +6,9 @@ Decorator to produce schema property data for entities.
|
|
|
6
6
|
|
|
7
7
|
## Parameters
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### options
|
|
10
|
+
|
|
11
|
+
`Omit`\<[`IEntitySchemaProperty`](../interfaces/IEntitySchemaProperty.md), `"property"`\>
|
|
10
12
|
|
|
11
13
|
The options for the property.
|
|
12
14
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Variable: EntitySchemaFactory
|
|
2
2
|
|
|
3
|
-
> `const` **EntitySchemaFactory**: `Factory`\<[`IEntitySchema`](../interfaces/IEntitySchema.md)
|
|
3
|
+
> `const` **EntitySchemaFactory**: `Factory`\<[`IEntitySchema`](../interfaces/IEntitySchema.md)\>
|
|
4
4
|
|
|
5
5
|
Factory for creating entity schemas.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.21",
|
|
4
4
|
"description": "Helpers for defining and working with entities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,37 +13,11 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"clean": "rimraf dist coverage",
|
|
18
|
-
"build": "tspc",
|
|
19
|
-
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
-
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
-
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
-
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
-
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
-
"docs:clean": "rimraf docs/reference",
|
|
25
|
-
"docs:generate": "typedoc",
|
|
26
|
-
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
-
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
-
},
|
|
29
16
|
"dependencies": {
|
|
17
|
+
"@twin.org/core": "0.0.1-next.21",
|
|
30
18
|
"@twin.org/nameof": "next",
|
|
31
|
-
"@twin.org/core": "0.0.1-next.2",
|
|
32
19
|
"reflect-metadata": "0.2.2"
|
|
33
20
|
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@twin.org/nameof-transformer": "next",
|
|
36
|
-
"@vitest/coverage-v8": "2.1.1",
|
|
37
|
-
"copyfiles": "2.4.1",
|
|
38
|
-
"rimraf": "6.0.1",
|
|
39
|
-
"rollup": "4.21.3",
|
|
40
|
-
"rollup-plugin-typescript2": "0.36.0",
|
|
41
|
-
"ts-patch": "3.2.1",
|
|
42
|
-
"typedoc": "0.26.7",
|
|
43
|
-
"typedoc-plugin-markdown": "4.2.7",
|
|
44
|
-
"typescript": "5.6.2",
|
|
45
|
-
"vitest": "2.1.1"
|
|
46
|
-
},
|
|
47
21
|
"main": "./dist/cjs/index.cjs",
|
|
48
22
|
"module": "./dist/esm/index.mjs",
|
|
49
23
|
"types": "./dist/types/index.d.ts",
|
|
@@ -53,7 +27,7 @@
|
|
|
53
27
|
"import": "./dist/esm/index.mjs",
|
|
54
28
|
"types": "./dist/types/index.d.ts"
|
|
55
29
|
},
|
|
56
|
-
"./locales": "./locales"
|
|
30
|
+
"./locales/*.json": "./locales/*.json"
|
|
57
31
|
},
|
|
58
32
|
"files": [
|
|
59
33
|
"dist/cjs",
|