@twin.org/entity 0.0.1-next.9 → 0.0.1

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.
@@ -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 >= 0) {
64
+ if (idx !== -1) {
65
65
  entitySchema.properties[idx] = {
66
66
  ...options,
67
67
  property: propertyKey
@@ -533,6 +533,60 @@ class EntitySchemaHelper {
533
533
  }
534
534
  return finalSortKeys;
535
535
  }
536
+ /**
537
+ * Validate the entity against the schema.
538
+ * @param entity The entity to validate.
539
+ * @param entitySchema The schema to validate against.
540
+ * @throws If the entity is invalid.
541
+ */
542
+ static validateEntity(entity, entitySchema) {
543
+ core.Guards.object(EntitySchemaHelper._CLASS_NAME, "entity", entity);
544
+ core.Guards.object(EntitySchemaHelper._CLASS_NAME, "entitySchema", entitySchema);
545
+ const properties = entitySchema.properties ?? [];
546
+ if (properties.length === 0 && core.Is.objectValue(entity)) {
547
+ throw new core.GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidEntityProperties");
548
+ }
549
+ const allKeys = Object.keys(entity);
550
+ for (const prop of properties) {
551
+ const idx = allKeys.indexOf(prop.property);
552
+ if (idx !== -1) {
553
+ allKeys.splice(idx, 1);
554
+ }
555
+ const value = entity[prop.property];
556
+ if (core.Is.empty(value)) {
557
+ // If the value is empty but the property is not optional, then it's invalid
558
+ if (!prop.optional) {
559
+ throw new core.GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidOptional", {
560
+ property: prop.property,
561
+ type: prop.type
562
+ });
563
+ }
564
+ }
565
+ else if (prop.type === "integer" && core.Is.integer(value)) ;
566
+ else if (prop.type === "object" &&
567
+ (core.Is.object(value) ||
568
+ core.Is.array(value) ||
569
+ core.Is.string(value) ||
570
+ core.Is.number(value) ||
571
+ core.Is.boolean(value) ||
572
+ core.Is.null(value))) ;
573
+ else if (prop.type === "array" && core.Is.array(value)) ;
574
+ else if (prop.type !== typeof value) {
575
+ // The schema type does not match the value type
576
+ throw new core.GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidEntityProperty", {
577
+ value,
578
+ property: prop.property,
579
+ type: prop.type
580
+ });
581
+ }
582
+ }
583
+ if (allKeys.length > 0) {
584
+ // There are keys in the entity that are not in the schema
585
+ throw new core.GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidEntityKeys", {
586
+ keys: allKeys.join(", ")
587
+ });
588
+ }
589
+ }
536
590
  }
537
591
 
538
592
  // Copyright 2024 IOTA Stiftung.
@@ -572,7 +626,9 @@ class EntitySorter {
572
626
  */
573
627
  static compare(entity1, entity2, prop, type, direction = SortDirection.Ascending) {
574
628
  let res = 0;
575
- if (!core.Is.empty(entity1[prop]) && !core.Is.empty(entity2[prop])) {
629
+ const hasProp1 = !core.Is.empty(entity1[prop]);
630
+ const hasProp2 = !core.Is.empty(entity2[prop]);
631
+ if (hasProp1 && hasProp2) {
576
632
  if (type === "number" || type === "integer") {
577
633
  res = entity1[prop] - entity2[prop];
578
634
  }
@@ -593,6 +649,12 @@ class EntitySorter {
593
649
  res = entity1[prop].localeCompare(entity2[prop]);
594
650
  }
595
651
  }
652
+ else if (hasProp1) {
653
+ res = -1;
654
+ }
655
+ else {
656
+ res = 1;
657
+ }
596
658
  return direction === SortDirection.Ascending ? res : res * -1;
597
659
  }
598
660
  }
@@ -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 >= 0) {
62
+ if (idx !== -1) {
63
63
  entitySchema.properties[idx] = {
64
64
  ...options,
65
65
  property: propertyKey
@@ -531,6 +531,60 @@ class EntitySchemaHelper {
531
531
  }
532
532
  return finalSortKeys;
533
533
  }
534
+ /**
535
+ * Validate the entity against the schema.
536
+ * @param entity The entity to validate.
537
+ * @param entitySchema The schema to validate against.
538
+ * @throws If the entity is invalid.
539
+ */
540
+ static validateEntity(entity, entitySchema) {
541
+ Guards.object(EntitySchemaHelper._CLASS_NAME, "entity", entity);
542
+ Guards.object(EntitySchemaHelper._CLASS_NAME, "entitySchema", entitySchema);
543
+ const properties = entitySchema.properties ?? [];
544
+ if (properties.length === 0 && Is.objectValue(entity)) {
545
+ throw new GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidEntityProperties");
546
+ }
547
+ const allKeys = Object.keys(entity);
548
+ for (const prop of properties) {
549
+ const idx = allKeys.indexOf(prop.property);
550
+ if (idx !== -1) {
551
+ allKeys.splice(idx, 1);
552
+ }
553
+ const value = entity[prop.property];
554
+ if (Is.empty(value)) {
555
+ // If the value is empty but the property is not optional, then it's invalid
556
+ if (!prop.optional) {
557
+ throw new GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidOptional", {
558
+ property: prop.property,
559
+ type: prop.type
560
+ });
561
+ }
562
+ }
563
+ else if (prop.type === "integer" && Is.integer(value)) ;
564
+ else if (prop.type === "object" &&
565
+ (Is.object(value) ||
566
+ Is.array(value) ||
567
+ Is.string(value) ||
568
+ Is.number(value) ||
569
+ Is.boolean(value) ||
570
+ Is.null(value))) ;
571
+ else if (prop.type === "array" && Is.array(value)) ;
572
+ else if (prop.type !== typeof value) {
573
+ // The schema type does not match the value type
574
+ throw new GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidEntityProperty", {
575
+ value,
576
+ property: prop.property,
577
+ type: prop.type
578
+ });
579
+ }
580
+ }
581
+ if (allKeys.length > 0) {
582
+ // There are keys in the entity that are not in the schema
583
+ throw new GeneralError(EntitySchemaHelper._CLASS_NAME, "invalidEntityKeys", {
584
+ keys: allKeys.join(", ")
585
+ });
586
+ }
587
+ }
534
588
  }
535
589
 
536
590
  // Copyright 2024 IOTA Stiftung.
@@ -570,7 +624,9 @@ class EntitySorter {
570
624
  */
571
625
  static compare(entity1, entity2, prop, type, direction = SortDirection.Ascending) {
572
626
  let res = 0;
573
- if (!Is.empty(entity1[prop]) && !Is.empty(entity2[prop])) {
627
+ const hasProp1 = !Is.empty(entity1[prop]);
628
+ const hasProp2 = !Is.empty(entity2[prop]);
629
+ if (hasProp1 && hasProp2) {
574
630
  if (type === "number" || type === "integer") {
575
631
  res = entity1[prop] - entity2[prop];
576
632
  }
@@ -591,6 +647,12 @@ class EntitySorter {
591
647
  res = entity1[prop].localeCompare(entity2[prop]);
592
648
  }
593
649
  }
650
+ else if (hasProp1) {
651
+ res = -1;
652
+ }
653
+ else {
654
+ res = 1;
655
+ }
594
656
  return direction === SortDirection.Ascending ? res : res * -1;
595
657
  }
596
658
  }
@@ -35,4 +35,11 @@ export declare class EntitySchemaHelper {
35
35
  property: keyof T;
36
36
  sortDirection: SortDirection;
37
37
  }[]): IEntitySort<T>[] | undefined;
38
+ /**
39
+ * Validate the entity against the schema.
40
+ * @param entity The entity to validate.
41
+ * @param entitySchema The schema to validate against.
42
+ * @throws If the entity is invalid.
43
+ */
44
+ static validateEntity<T>(entity: T, entitySchema: IEntitySchema<T>): void;
38
45
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,335 @@
1
1
  # @twin.org/entity - Changelog
2
2
 
3
- ## 0.0.1-next.9
3
+ ## 0.0.1 (2025-07-03)
4
+
5
+
6
+ ### Features
7
+
8
+ * release to production ([829d53d](https://github.com/twinfoundation/framework/commit/829d53d3953b1e1b40b0243c04cfdfd3842aac7b))
9
+ * release to production ([5cf3a76](https://github.com/twinfoundation/framework/commit/5cf3a76a09eff2e6414d0cba846c7c37400a11d6))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @twin.org/nameof bumped from ^0.0.0 to ^0.0.1
17
+ * @twin.org/core bumped from ^0.0.0 to ^0.0.1
18
+ * devDependencies
19
+ * @twin.org/nameof-transformer bumped from ^0.0.0 to ^0.0.1
20
+ * @twin.org/nameof-vitest-plugin bumped from ^0.0.0 to ^0.0.1
21
+
22
+ ## [0.0.1-next.70](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.69...entity-v0.0.1-next.70) (2025-07-02)
23
+
24
+
25
+ ### Features
26
+
27
+ * add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
28
+ * relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
29
+ * use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
30
+
31
+
32
+ ### Dependencies
33
+
34
+ * The following workspace dependencies were updated
35
+ * dependencies
36
+ * @twin.org/nameof bumped from 0.0.1-next.69 to 0.0.1-next.70
37
+ * @twin.org/core bumped from 0.0.1-next.69 to 0.0.1-next.70
38
+ * devDependencies
39
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.69 to 0.0.1-next.70
40
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.69 to 0.0.1-next.70
41
+
42
+ ## [0.0.1-next.69](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.68...entity-v0.0.1-next.69) (2025-07-02)
43
+
44
+
45
+ ### Features
46
+
47
+ * add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
48
+ * relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
49
+ * use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
50
+
51
+
52
+ ### Dependencies
53
+
54
+ * The following workspace dependencies were updated
55
+ * dependencies
56
+ * @twin.org/nameof bumped from 0.0.1-next.68 to 0.0.1-next.69
57
+ * @twin.org/core bumped from 0.0.1-next.68 to 0.0.1-next.69
58
+ * devDependencies
59
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.68 to 0.0.1-next.69
60
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.68 to 0.0.1-next.69
61
+
62
+ ## [0.0.1-next.68](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.67...entity-v0.0.1-next.68) (2025-07-02)
63
+
64
+
65
+ ### Features
66
+
67
+ * relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
68
+
69
+
70
+ ### Dependencies
71
+
72
+ * The following workspace dependencies were updated
73
+ * dependencies
74
+ * @twin.org/nameof bumped from 0.0.1-next.67 to 0.0.1-next.68
75
+ * @twin.org/core bumped from 0.0.1-next.67 to 0.0.1-next.68
76
+ * devDependencies
77
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.67 to 0.0.1-next.68
78
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.67 to 0.0.1-next.68
79
+
80
+ ## [0.0.1-next.67](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.66...entity-v0.0.1-next.67) (2025-06-26)
81
+
82
+
83
+ ### Miscellaneous Chores
84
+
85
+ * **entity:** Synchronize repo versions
86
+
87
+
88
+ ### Dependencies
89
+
90
+ * The following workspace dependencies were updated
91
+ * dependencies
92
+ * @twin.org/core bumped from 0.0.1-next.66 to 0.0.1-next.67
93
+
94
+ ## [0.0.1-next.66](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.65...entity-v0.0.1-next.66) (2025-06-26)
95
+
96
+
97
+ ### Miscellaneous Chores
98
+
99
+ * **entity:** Synchronize repo versions
100
+
101
+
102
+ ### Dependencies
103
+
104
+ * The following workspace dependencies were updated
105
+ * dependencies
106
+ * @twin.org/core bumped from 0.0.1-next.65 to 0.0.1-next.66
107
+
108
+ ## [0.0.1-next.65](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.64...entity-v0.0.1-next.65) (2025-06-19)
109
+
110
+
111
+ ### Miscellaneous Chores
112
+
113
+ * **entity:** Synchronize repo versions
114
+
115
+
116
+ ### Dependencies
117
+
118
+ * The following workspace dependencies were updated
119
+ * dependencies
120
+ * @twin.org/core bumped from 0.0.1-next.64 to 0.0.1-next.65
121
+
122
+ ## [0.0.1-next.64](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.63...entity-v0.0.1-next.64) (2025-06-19)
123
+
124
+
125
+ ### Miscellaneous Chores
126
+
127
+ * **entity:** Synchronize repo versions
128
+
129
+
130
+ ### Dependencies
131
+
132
+ * The following workspace dependencies were updated
133
+ * dependencies
134
+ * @twin.org/core bumped from 0.0.1-next.63 to 0.0.1-next.64
135
+
136
+ ## [0.0.1-next.63](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.62...entity-v0.0.1-next.63) (2025-06-18)
137
+
138
+
139
+ ### Miscellaneous Chores
140
+
141
+ * **entity:** Synchronize repo versions
142
+
143
+
144
+ ### Dependencies
145
+
146
+ * The following workspace dependencies were updated
147
+ * dependencies
148
+ * @twin.org/core bumped from 0.0.1-next.62 to 0.0.1-next.63
149
+
150
+ ## [0.0.1-next.62](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.61...entity-v0.0.1-next.62) (2025-06-17)
151
+
152
+
153
+ ### Features
154
+
155
+ * add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
156
+ * use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
157
+
158
+
159
+ ### Dependencies
160
+
161
+ * The following workspace dependencies were updated
162
+ * dependencies
163
+ * @twin.org/core bumped from 0.0.1-next.61 to 0.0.1-next.62
164
+
165
+ ## [0.0.1-next.61](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.60...entity-v0.0.1-next.61) (2025-06-17)
166
+
167
+
168
+ ### Miscellaneous Chores
169
+
170
+ * **entity:** Synchronize repo versions
171
+
172
+
173
+ ### Dependencies
174
+
175
+ * The following workspace dependencies were updated
176
+ * dependencies
177
+ * @twin.org/core bumped from 0.0.1-next.60 to 0.0.1-next.61
178
+
179
+ ## [0.0.1-next.60](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.59...entity-v0.0.1-next.60) (2025-06-17)
180
+
181
+
182
+ ### Miscellaneous Chores
183
+
184
+ * **entity:** Synchronize repo versions
185
+
186
+
187
+ ### Dependencies
188
+
189
+ * The following workspace dependencies were updated
190
+ * dependencies
191
+ * @twin.org/core bumped from 0.0.1-next.59 to 0.0.1-next.60
192
+
193
+ ## [0.0.1-next.59](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.58...entity-v0.0.1-next.59) (2025-06-17)
194
+
195
+
196
+ ### Miscellaneous Chores
197
+
198
+ * **entity:** Synchronize repo versions
199
+
200
+
201
+ ### Dependencies
202
+
203
+ * The following workspace dependencies were updated
204
+ * dependencies
205
+ * @twin.org/core bumped from 0.0.1-next.58 to 0.0.1-next.59
206
+
207
+ ## [0.0.1-next.58](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.57...entity-v0.0.1-next.58) (2025-06-13)
208
+
209
+
210
+ ### Miscellaneous Chores
211
+
212
+ * **entity:** Synchronize repo versions
213
+
214
+
215
+ ### Dependencies
216
+
217
+ * The following workspace dependencies were updated
218
+ * dependencies
219
+ * @twin.org/core bumped from 0.0.1-next.57 to 0.0.1-next.58
220
+
221
+ ## [0.0.1-next.57](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.56...entity-v0.0.1-next.57) (2025-06-10)
222
+
223
+
224
+ ### Features
225
+
226
+ * add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
227
+
228
+
229
+ ### Dependencies
230
+
231
+ * The following workspace dependencies were updated
232
+ * dependencies
233
+ * @twin.org/core bumped from 0.0.1-next.56 to 0.0.1-next.57
234
+
235
+ ## [0.0.1-next.56](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.55...entity-v0.0.1-next.56) (2025-05-08)
236
+
237
+
238
+ ### Miscellaneous Chores
239
+
240
+ * **entity:** Synchronize repo versions
241
+
242
+
243
+ ### Dependencies
244
+
245
+ * The following workspace dependencies were updated
246
+ * dependencies
247
+ * @twin.org/core bumped from 0.0.1-next.55 to 0.0.1-next.56
248
+
249
+ ## [0.0.1-next.55](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.54...entity-v0.0.1-next.55) (2025-05-07)
250
+
251
+
252
+ ### Miscellaneous Chores
253
+
254
+ * **entity:** Synchronize repo versions
255
+
256
+
257
+ ### Dependencies
258
+
259
+ * The following workspace dependencies were updated
260
+ * dependencies
261
+ * @twin.org/core bumped from 0.0.1-next.54 to 0.0.1-next.55
262
+
263
+ ## [0.0.1-next.54](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.53...entity-v0.0.1-next.54) (2025-05-06)
264
+
265
+
266
+ ### Miscellaneous Chores
267
+
268
+ * **entity:** Synchronize repo versions
269
+
270
+
271
+ ### Dependencies
272
+
273
+ * The following workspace dependencies were updated
274
+ * dependencies
275
+ * @twin.org/core bumped from 0.0.1-next.53 to 0.0.1-next.54
276
+
277
+ ## [0.0.1-next.53](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.52...entity-v0.0.1-next.53) (2025-05-01)
278
+
279
+
280
+ ### Miscellaneous Chores
281
+
282
+ * **entity:** Synchronize repo versions
283
+
284
+
285
+ ### Dependencies
286
+
287
+ * The following workspace dependencies were updated
288
+ * dependencies
289
+ * @twin.org/core bumped from 0.0.1-next.52 to 0.0.1-next.53
290
+
291
+ ## [0.0.1-next.52](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.51...entity-v0.0.1-next.52) (2025-04-17)
292
+
293
+
294
+ ### Features
295
+
296
+ * use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
297
+
298
+
299
+ ### Dependencies
300
+
301
+ * The following workspace dependencies were updated
302
+ * dependencies
303
+ * @twin.org/core bumped from 0.0.1-next.51 to 0.0.1-next.52
304
+
305
+ ## [0.0.1-next.51](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.50...entity-v0.0.1-next.51) (2025-03-27)
306
+
307
+
308
+ ### Miscellaneous Chores
309
+
310
+ * **entity:** Synchronize repo versions
311
+
312
+
313
+ ### Dependencies
314
+
315
+ * The following workspace dependencies were updated
316
+ * dependencies
317
+ * @twin.org/core bumped from 0.0.1-next.50 to 0.0.1-next.51
318
+
319
+ ## [0.0.1-next.50](https://github.com/twinfoundation/framework/compare/entity-v0.0.1-next.49...entity-v0.0.1-next.50) (2025-03-26)
320
+
321
+
322
+ ### Miscellaneous Chores
323
+
324
+ * **entity:** Synchronize repo versions
325
+
326
+
327
+ ### Dependencies
328
+
329
+ * The following workspace dependencies were updated
330
+ * dependencies
331
+ * @twin.org/core bumped from 0.0.1-next.49 to 0.0.1-next.50
332
+
333
+ ## 0.0.1-next.49
4
334
 
5
335
  - Initial Release
@@ -4,13 +4,13 @@ Class to help with decorators.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new DecoratorHelper()
7
+ ### Constructor
8
8
 
9
- > **new DecoratorHelper**(): [`DecoratorHelper`](DecoratorHelper.md)
9
+ > **new DecoratorHelper**(): `DecoratorHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`DecoratorHelper`](DecoratorHelper.md)
13
+ `DecoratorHelper`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,11 +22,15 @@ Get the schema from the reflection metadata.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T** = `unknown`
25
+ ##### T
26
+
27
+ `T` = `unknown`
26
28
 
27
29
  #### Parameters
28
30
 
29
- **target**: `any`
31
+ ##### target
32
+
33
+ `any`
30
34
 
31
35
  The object to get the schema data from.
32
36
 
@@ -46,15 +50,21 @@ Set the schema from the reflection metadata.
46
50
 
47
51
  #### Type Parameters
48
52
 
49
- **T** = `unknown`
53
+ ##### T
54
+
55
+ `T` = `unknown`
50
56
 
51
57
  #### Parameters
52
58
 
53
- **target**: `any`
59
+ ##### target
60
+
61
+ `any`
54
62
 
55
63
  The object to get the schema data from.
56
64
 
57
- **entitySchema**: [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
65
+ ##### entitySchema
66
+
67
+ [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
58
68
 
59
69
  The schema to set.
60
70
 
@@ -4,33 +4,39 @@ Class to perform condition checks.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new EntityConditions()
7
+ ### Constructor
8
8
 
9
- > **new EntityConditions**(): [`EntityConditions`](EntityConditions.md)
9
+ > **new EntityConditions**(): `EntityConditions`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`EntityConditions`](EntityConditions.md)
13
+ `EntityConditions`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### check()
18
18
 
19
- > `static` **check**\<`T`\>(`entity`, `condition`?): `boolean`
19
+ > `static` **check**\<`T`\>(`entity`, `condition?`): `boolean`
20
20
 
21
21
  See if the entity matches the conditions.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T**
25
+ ##### T
26
+
27
+ `T`
26
28
 
27
29
  #### Parameters
28
30
 
29
- **entity**: `T`
31
+ ##### entity
32
+
33
+ `T`
30
34
 
31
35
  The entity to test.
32
36
 
33
- **condition?**: [`EntityCondition`](../type-aliases/EntityCondition.md)\<`T`\>
37
+ ##### condition?
38
+
39
+ [`EntityCondition`](../type-aliases/EntityCondition.md)\<`T`\>
34
40
 
35
41
  The conditions to test.
36
42
 
@@ -50,15 +56,21 @@ See if the entity matches the conditions.
50
56
 
51
57
  #### Type Parameters
52
58
 
53
- **T**
59
+ ##### T
60
+
61
+ `T`
54
62
 
55
63
  #### Parameters
56
64
 
57
- **entity**: `T`
65
+ ##### entity
66
+
67
+ `T`
58
68
 
59
69
  The entity to test.
60
70
 
61
- **comparator**: [`IComparator`](../interfaces/IComparator.md)
71
+ ##### comparator
72
+
73
+ [`IComparator`](../interfaces/IComparator.md)
62
74
 
63
75
  The condition to test.
64
76
 
@@ -4,13 +4,13 @@ Class to help with entity schema operations.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new EntitySchemaHelper()
7
+ ### Constructor
8
8
 
9
- > **new EntitySchemaHelper**(): [`EntitySchemaHelper`](EntitySchemaHelper.md)
9
+ > **new EntitySchemaHelper**(): `EntitySchemaHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`EntitySchemaHelper`](EntitySchemaHelper.md)
13
+ `EntitySchemaHelper`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,11 +22,15 @@ Get the schema for the specified object.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T** = `unknown`
25
+ ##### T
26
+
27
+ `T` = `unknown`
26
28
 
27
29
  #### Parameters
28
30
 
29
- **target**: `any`
31
+ ##### target
32
+
33
+ `any`
30
34
 
31
35
  The object to get the schema data for.
32
36
 
@@ -46,11 +50,15 @@ Get the primary key from the entity schema.
46
50
 
47
51
  #### Type Parameters
48
52
 
49
- **T**
53
+ ##### T
54
+
55
+ `T`
50
56
 
51
57
  #### Parameters
52
58
 
53
- **entitySchema**: [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
59
+ ##### entitySchema
60
+
61
+ [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
54
62
 
55
63
  The entity schema to find the primary key from.
56
64
 
@@ -74,11 +82,15 @@ Get the sort properties from the schema.
74
82
 
75
83
  #### Type Parameters
76
84
 
77
- **T**
85
+ ##### T
86
+
87
+ `T`
78
88
 
79
89
  #### Parameters
80
90
 
81
- **entitySchema**: [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
91
+ ##### entitySchema
92
+
93
+ [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
82
94
 
83
95
  The entity schema to find the primary key from.
84
96
 
@@ -92,21 +104,27 @@ The sort keys from the schema or undefined if there are none.
92
104
 
93
105
  ### buildSortProperties()
94
106
 
95
- > `static` **buildSortProperties**\<`T`\>(`entitySchema`, `overrideSortKeys`?): `undefined` \| [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[]
107
+ > `static` **buildSortProperties**\<`T`\>(`entitySchema`, `overrideSortKeys?`): `undefined` \| [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[]
96
108
 
97
109
  Build sort properties from the schema and override if necessary.
98
110
 
99
111
  #### Type Parameters
100
112
 
101
- **T**
113
+ ##### T
114
+
115
+ `T`
102
116
 
103
117
  #### Parameters
104
118
 
105
- **entitySchema**: [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
119
+ ##### entitySchema
120
+
121
+ [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
106
122
 
107
123
  The entity schema to retrieve the default sort keys.
108
124
 
109
- **overrideSortKeys?**: `object`[]
125
+ ##### overrideSortKeys?
126
+
127
+ `object`[]
110
128
 
111
129
  The override sort keys.
112
130
 
@@ -115,3 +133,39 @@ The override sort keys.
115
133
  `undefined` \| [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[]
116
134
 
117
135
  The finalised sort keys.
136
+
137
+ ***
138
+
139
+ ### validateEntity()
140
+
141
+ > `static` **validateEntity**\<`T`\>(`entity`, `entitySchema`): `void`
142
+
143
+ Validate the entity against the schema.
144
+
145
+ #### Type Parameters
146
+
147
+ ##### T
148
+
149
+ `T`
150
+
151
+ #### Parameters
152
+
153
+ ##### entity
154
+
155
+ `T`
156
+
157
+ The entity to validate.
158
+
159
+ ##### entitySchema
160
+
161
+ [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
162
+
163
+ The schema to validate against.
164
+
165
+ #### Returns
166
+
167
+ `void`
168
+
169
+ #### Throws
170
+
171
+ If the entity is invalid.
@@ -4,33 +4,39 @@ Class to perform sort operations on entities.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new EntitySorter()
7
+ ### Constructor
8
8
 
9
- > **new EntitySorter**(): [`EntitySorter`](EntitySorter.md)
9
+ > **new EntitySorter**(): `EntitySorter`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`EntitySorter`](EntitySorter.md)
13
+ `EntitySorter`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### sort()
18
18
 
19
- > `static` **sort**\<`T`\>(`entities`, `entitySorters`?): `T`[]
19
+ > `static` **sort**\<`T`\>(`entities`, `entitySorters?`): `T`[]
20
20
 
21
21
  Sort a list of entities using multiple keys and direction.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T**
25
+ ##### T
26
+
27
+ `T`
26
28
 
27
29
  #### Parameters
28
30
 
29
- **entities**: `T`[]
31
+ ##### entities
32
+
33
+ `T`[]
30
34
 
31
35
  The list of entities.
32
36
 
33
- **entitySorters?**: [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[]
37
+ ##### entitySorters?
38
+
39
+ [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[]
34
40
 
35
41
  The sort keys to use.
36
42
 
@@ -50,27 +56,39 @@ Compare two properties.
50
56
 
51
57
  #### Type Parameters
52
58
 
53
- **T**
59
+ ##### T
60
+
61
+ `T`
54
62
 
55
63
  #### Parameters
56
64
 
57
- **entity1**: `T`
65
+ ##### entity1
66
+
67
+ `T`
58
68
 
59
69
  The first entity.
60
70
 
61
- **entity2**: `T`
71
+ ##### entity2
72
+
73
+ `T`
62
74
 
63
75
  The second entity.
64
76
 
65
- **prop**: keyof `T`
77
+ ##### prop
78
+
79
+ keyof `T`
66
80
 
67
81
  The property to compare.
68
82
 
69
- **type**: [`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
83
+ ##### type
84
+
85
+ [`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
70
86
 
71
87
  The type of the property.
72
88
 
73
- **direction**: [`SortDirection`](../type-aliases/SortDirection.md) = `SortDirection.Ascending`
89
+ ##### direction
90
+
91
+ [`SortDirection`](../type-aliases/SortDirection.md) = `SortDirection.Ascending`
74
92
 
75
93
  The direction of the sort.
76
94
 
@@ -1,12 +1,14 @@
1
1
  # Function: entity()
2
2
 
3
- > **entity**(`options`?): `any`
3
+ > **entity**(`options?`): `any`
4
4
 
5
5
  Decorator to produce schema data for entity.
6
6
 
7
7
  ## Parameters
8
8
 
9
- **options?**: [`IEntitySchemaOptions`](../interfaces/IEntitySchemaOptions.md)
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
- **options**: `Omit`\<[`IEntitySchemaProperty`](../interfaces/IEntitySchemaProperty.md)\<`unknown`\>, `"property"`\>
9
+ ### options
10
+
11
+ `Omit`\<[`IEntitySchemaProperty`](../interfaces/IEntitySchemaProperty.md), `"property"`\>
10
12
 
11
13
  The options for the property.
12
14
 
@@ -4,7 +4,9 @@ Interface defining condition group operator.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T** = `unknown`
7
+ ### T
8
+
9
+ `T` = `unknown`
8
10
 
9
11
  ## Properties
10
12
 
@@ -4,7 +4,9 @@ Definition for an entity schema.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T** = `unknown`
7
+ ### T
8
+
9
+ `T` = `unknown`
8
10
 
9
11
  ## Properties
10
12
 
@@ -4,7 +4,9 @@ Definition for an entity schema property.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T** = `unknown`
7
+ ### T
8
+
9
+ `T` = `unknown`
8
10
 
9
11
  ## Properties
10
12
 
@@ -4,7 +4,9 @@ Definition of an entity property sort details.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T**
7
+ ### T
8
+
9
+ `T`
8
10
 
9
11
  ## Properties
10
12
 
@@ -1,5 +1,5 @@
1
1
  # Type Alias: ComparisonOperator
2
2
 
3
- > **ComparisonOperator**: *typeof* [`ComparisonOperator`](../variables/ComparisonOperator.md)\[keyof *typeof* [`ComparisonOperator`](../variables/ComparisonOperator.md)\]
3
+ > **ComparisonOperator** = *typeof* [`ComparisonOperator`](../variables/ComparisonOperator.md)\[keyof *typeof* [`ComparisonOperator`](../variables/ComparisonOperator.md)\]
4
4
 
5
5
  The types of comparisons.
@@ -1,9 +1,11 @@
1
1
  # Type Alias: EntityCondition\<T\>
2
2
 
3
- > **EntityCondition**\<`T`\>: [`IComparator`](../interfaces/IComparator.md) \| [`IComparatorGroup`](../interfaces/IComparatorGroup.md)\<`T`\>
3
+ > **EntityCondition**\<`T`\> = [`IComparator`](../interfaces/IComparator.md) \| [`IComparatorGroup`](../interfaces/IComparatorGroup.md)\<`T`\>
4
4
 
5
5
  Type defining condition for entities filtering.
6
6
 
7
7
  ## Type Parameters
8
8
 
9
- **T**
9
+ ### T
10
+
11
+ `T`
@@ -1,5 +1,5 @@
1
1
  # Type Alias: EntitySchemaPropertyFormat
2
2
 
3
- > **EntitySchemaPropertyFormat**: *typeof* [`EntitySchemaPropertyFormat`](../variables/EntitySchemaPropertyFormat.md)\[keyof *typeof* [`EntitySchemaPropertyFormat`](../variables/EntitySchemaPropertyFormat.md)\]
3
+ > **EntitySchemaPropertyFormat** = *typeof* [`EntitySchemaPropertyFormat`](../variables/EntitySchemaPropertyFormat.md)\[keyof *typeof* [`EntitySchemaPropertyFormat`](../variables/EntitySchemaPropertyFormat.md)\]
4
4
 
5
5
  Definition of the entity property type's format.
@@ -1,5 +1,5 @@
1
1
  # Type Alias: EntitySchemaPropertyType
2
2
 
3
- > **EntitySchemaPropertyType**: *typeof* [`EntitySchemaPropertyType`](../variables/EntitySchemaPropertyType.md)\[keyof *typeof* [`EntitySchemaPropertyType`](../variables/EntitySchemaPropertyType.md)\]
3
+ > **EntitySchemaPropertyType** = *typeof* [`EntitySchemaPropertyType`](../variables/EntitySchemaPropertyType.md)\[keyof *typeof* [`EntitySchemaPropertyType`](../variables/EntitySchemaPropertyType.md)\]
4
4
 
5
5
  Definition of the entity property types.
@@ -1,5 +1,5 @@
1
1
  # Type Alias: LogicalOperator
2
2
 
3
- > **LogicalOperator**: *typeof* [`LogicalOperator`](../variables/LogicalOperator.md)\[keyof *typeof* [`LogicalOperator`](../variables/LogicalOperator.md)\]
3
+ > **LogicalOperator** = *typeof* [`LogicalOperator`](../variables/LogicalOperator.md)\[keyof *typeof* [`LogicalOperator`](../variables/LogicalOperator.md)\]
4
4
 
5
5
  The logical operators for condition combining.
@@ -1,5 +1,5 @@
1
1
  # Type Alias: SortDirection
2
2
 
3
- > **SortDirection**: *typeof* [`SortDirection`](../variables/SortDirection.md)\[keyof *typeof* [`SortDirection`](../variables/SortDirection.md)\]
3
+ > **SortDirection** = *typeof* [`SortDirection`](../variables/SortDirection.md)\[keyof *typeof* [`SortDirection`](../variables/SortDirection.md)\]
4
4
 
5
5
  The sort directions.
package/locales/en.json CHANGED
@@ -2,7 +2,11 @@
2
2
  "error": {
3
3
  "entitySchemaHelper": {
4
4
  "noIsPrimary": "Property \"entitySchema.properties\" must contain a value with isPrimary set",
5
- "multipleIsPrimary": "Property \"entitySchema.properties\" contains more than one property with isPrimary set"
5
+ "multipleIsPrimary": "Property \"entitySchema.properties\" contains more than one property with isPrimary set",
6
+ "invalidEntityProperties": "The schema has no properties defined, but the entity has properties",
7
+ "invalidEntityProperty": "The entity value of \"{value}\" does not match the type \"{type}\" for property \"{property}\"",
8
+ "invalidOptional": "The entity property \"{property}\" of type \"{type}\" is not optional, but no value has been provided",
9
+ "invalidEntityKeys": "The entity had additional properties that are not in the schema, \"{keys}\""
6
10
  }
7
11
  }
8
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity",
3
- "version": "0.0.1-next.9",
3
+ "version": "0.0.1",
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.1-next.9",
18
- "@twin.org/nameof": "next",
17
+ "@twin.org/core": "^0.0.1",
18
+ "@twin.org/nameof": "^0.0.1",
19
19
  "reflect-metadata": "0.2.2"
20
20
  },
21
21
  "main": "./dist/cjs/index.cjs",
@@ -23,11 +23,11 @@
23
23
  "types": "./dist/types/index.d.ts",
24
24
  "exports": {
25
25
  ".": {
26
+ "types": "./dist/types/index.d.ts",
26
27
  "require": "./dist/cjs/index.cjs",
27
- "import": "./dist/esm/index.mjs",
28
- "types": "./dist/types/index.d.ts"
28
+ "import": "./dist/esm/index.mjs"
29
29
  },
30
- "./locales": "./locales"
30
+ "./locales/*.json": "./locales/*.json"
31
31
  },
32
32
  "files": [
33
33
  "dist/cjs",