@twin.org/entity 0.0.3-next.22 → 0.0.3-next.24

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.
Files changed (28) hide show
  1. package/README.md +1 -5
  2. package/dist/es/decorators/entityDecorator.js +1 -0
  3. package/dist/es/decorators/entityDecorator.js.map +1 -1
  4. package/dist/es/decorators/propertyDecorator.js +1 -0
  5. package/dist/es/decorators/propertyDecorator.js.map +1 -1
  6. package/dist/es/utils/decoratorHelper.js +1 -0
  7. package/dist/es/utils/decoratorHelper.js.map +1 -1
  8. package/dist/types/decorators/entityDecorator.d.ts +1 -0
  9. package/dist/types/decorators/propertyDecorator.d.ts +1 -0
  10. package/dist/types/utils/decoratorHelper.d.ts +1 -0
  11. package/docs/changelog.md +39 -1
  12. package/docs/examples.md +70 -1
  13. package/docs/reference/classes/DecoratorHelper.md +2 -2
  14. package/docs/reference/classes/EntityConditions.md +2 -2
  15. package/docs/reference/classes/EntitySchemaHelper.md +6 -6
  16. package/docs/reference/classes/EntitySorter.md +4 -4
  17. package/docs/reference/interfaces/IComparator.md +3 -3
  18. package/docs/reference/interfaces/IComparatorGroup.md +3 -3
  19. package/docs/reference/interfaces/IEntitySchema.md +5 -5
  20. package/docs/reference/interfaces/IEntitySchemaOptions.md +2 -2
  21. package/docs/reference/interfaces/IEntitySchemaProperty.md +20 -20
  22. package/docs/reference/interfaces/IEntitySort.md +3 -3
  23. package/docs/reference/variables/ComparisonOperator.md +9 -9
  24. package/docs/reference/variables/EntitySchemaPropertyFormat.md +17 -17
  25. package/docs/reference/variables/EntitySchemaPropertyType.md +6 -6
  26. package/docs/reference/variables/LogicalOperator.md +2 -2
  27. package/docs/reference/variables/SortDirection.md +2 -2
  28. package/package.json +5 -4
package/README.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # TWIN Entity
2
2
 
3
- This package contains helper methods and classes for working with entities.
4
-
5
- - Defining
6
- - Sorting
7
- - Comparing
3
+ This package is part of the framework workspace and provides helpers for defining and working with entities to support consistent development workflows across the ecosystem.
8
4
 
9
5
  ## Installation
10
6
 
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
4
  import "reflect-metadata";
5
+ import "tslib";
5
6
  import { DecoratorHelper } from "../utils/decoratorHelper.js";
6
7
  /**
7
8
  * Decorator to produce schema data for entity.
@@ -1 +1 @@
1
- {"version":3,"file":"entityDecorator.js","sourceRoot":"","sources":["../../../src/decorators/entityDecorator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,uDAAuD;AACvD,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,OAA8B;IACpD,OAAO,CAAC,MAAW,EAAE,EAAE;QACtB,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACvD,YAAY,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAChC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;QAC/B,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport \"reflect-metadata\";\nimport type { IEntitySchemaOptions } from \"../models/IEntitySchemaOptions.js\";\nimport { DecoratorHelper } from \"../utils/decoratorHelper.js\";\n\n/**\n * Decorator to produce schema data for entity.\n * @param options The options for the entity.\n * @returns The class decorator.\n */\nexport function entity(options?: IEntitySchemaOptions): any {\n\treturn (target: any) => {\n\t\tconst entitySchema = DecoratorHelper.getSchema(target);\n\t\tentitySchema.type = target.name;\n\t\tentitySchema.options = options;\n\t\tDecoratorHelper.setSchema(target, entitySchema);\n\t};\n}\n"]}
1
+ {"version":3,"file":"entityDecorator.js","sourceRoot":"","sources":["../../../src/decorators/entityDecorator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,uDAAuD;AACvD,OAAO,kBAAkB,CAAC;AAC1B,OAAO,OAAO,CAAC;AAEf,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,OAA8B;IACpD,OAAO,CAAC,MAAW,EAAE,EAAE;QACtB,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACvD,YAAY,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAChC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;QAC/B,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport \"reflect-metadata\";\nimport \"tslib\";\nimport type { IEntitySchemaOptions } from \"../models/IEntitySchemaOptions.js\";\nimport { DecoratorHelper } from \"../utils/decoratorHelper.js\";\n\n/**\n * Decorator to produce schema data for entity.\n * @param options The options for the entity.\n * @returns The class decorator.\n */\nexport function entity(options?: IEntitySchemaOptions): any {\n\treturn (target: any) => {\n\t\tconst entitySchema = DecoratorHelper.getSchema(target);\n\t\tentitySchema.type = target.name;\n\t\tentitySchema.options = options;\n\t\tDecoratorHelper.setSchema(target, entitySchema);\n\t};\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
4
  import "reflect-metadata";
5
+ import "tslib";
5
6
  import { DecoratorHelper } from "../utils/decoratorHelper.js";
6
7
  /**
7
8
  * Decorator to produce schema property data for entities.
@@ -1 +1 @@
1
- {"version":3,"file":"propertyDecorator.js","sourceRoot":"","sources":["../../../src/decorators/propertyDecorator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,uDAAuD;AACvD,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAgD;IACxE,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAM,MAAM,CAAC,CAAC;QAC5D,YAAY,CAAC,UAAU,KAAK,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC;QAC/E,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YAChB,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG;gBAC9B,GAAG,OAAO;gBACV,QAAQ,EAAE,WAAW;aACrB,CAAC;QACH,CAAC;aAAM,CAAC;YACP,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC5B,GAAG,OAAO;gBACV,QAAQ,EAAE,WAAW;aACrB,CAAC,CAAC;QACJ,CAAC;QACD,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport \"reflect-metadata\";\nimport type { IEntitySchemaProperty } from \"../models/IEntitySchemaProperty.js\";\nimport { DecoratorHelper } from \"../utils/decoratorHelper.js\";\n\n/**\n * Decorator to produce schema property data for entities.\n * @param options The options for the property.\n * @returns The property decorator.\n */\nexport function property(options: Omit<IEntitySchemaProperty, \"property\">): any {\n\treturn (target: any, propertyKey: string) => {\n\t\tconst entitySchema = DecoratorHelper.getSchema<any>(target);\n\t\tentitySchema.properties ??= [];\n\t\tconst idx = entitySchema.properties.findIndex(p => p.property === propertyKey);\n\t\tif (idx !== -1) {\n\t\t\tentitySchema.properties[idx] = {\n\t\t\t\t...options,\n\t\t\t\tproperty: propertyKey\n\t\t\t};\n\t\t} else {\n\t\t\tentitySchema.properties.push({\n\t\t\t\t...options,\n\t\t\t\tproperty: propertyKey\n\t\t\t});\n\t\t}\n\t\tDecoratorHelper.setSchema(target, entitySchema);\n\t};\n}\n"]}
1
+ {"version":3,"file":"propertyDecorator.js","sourceRoot":"","sources":["../../../src/decorators/propertyDecorator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,uDAAuD;AACvD,OAAO,kBAAkB,CAAC;AAC1B,OAAO,OAAO,CAAC;AAEf,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAgD;IACxE,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC3C,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAM,MAAM,CAAC,CAAC;QAC5D,YAAY,CAAC,UAAU,KAAK,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC;QAC/E,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YAChB,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG;gBAC9B,GAAG,OAAO;gBACV,QAAQ,EAAE,WAAW;aACrB,CAAC;QACH,CAAC;aAAM,CAAC;YACP,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC5B,GAAG,OAAO;gBACV,QAAQ,EAAE,WAAW;aACrB,CAAC,CAAC;QACJ,CAAC;QACD,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport \"reflect-metadata\";\nimport \"tslib\";\nimport type { IEntitySchemaProperty } from \"../models/IEntitySchemaProperty.js\";\nimport { DecoratorHelper } from \"../utils/decoratorHelper.js\";\n\n/**\n * Decorator to produce schema property data for entities.\n * @param options The options for the property.\n * @returns The property decorator.\n */\nexport function property(options: Omit<IEntitySchemaProperty, \"property\">): any {\n\treturn (target: any, propertyKey: string) => {\n\t\tconst entitySchema = DecoratorHelper.getSchema<any>(target);\n\t\tentitySchema.properties ??= [];\n\t\tconst idx = entitySchema.properties.findIndex(p => p.property === propertyKey);\n\t\tif (idx !== -1) {\n\t\t\tentitySchema.properties[idx] = {\n\t\t\t\t...options,\n\t\t\t\tproperty: propertyKey\n\t\t\t};\n\t\t} else {\n\t\t\tentitySchema.properties.push({\n\t\t\t\t...options,\n\t\t\t\tproperty: propertyKey\n\t\t\t});\n\t\t}\n\t\tDecoratorHelper.setSchema(target, entitySchema);\n\t};\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import "reflect-metadata";
4
+ import "tslib";
4
5
  const META_DATA_KEY = "EntitySchemaMetadata";
5
6
  /**
6
7
  * Class to help with decorators.
@@ -1 +1 @@
1
- {"version":3,"file":"decoratorHelper.js","sourceRoot":"","sources":["../../../src/utils/decoratorHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,kBAAkB,CAAC;AAG1B,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;;;OAIG;IACH,8DAA8D;IACvD,MAAM,CAAC,SAAS,CAAc,MAAW;QAC/C,OAAO,CACN,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;YAC1F,EAAE,CACF,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,8DAA8D;IACvD,MAAM,CAAC,SAAS,CAAc,MAAW,EAAE,YAA8B;QAC/E,OAAO,CAAC,cAAc,CACrB,aAAa,EACb,YAAY,EACZ,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CACtD,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport \"reflect-metadata\";\nimport type { IEntitySchema } from \"../models/IEntitySchema.js\";\n\nconst META_DATA_KEY = \"EntitySchemaMetadata\";\n\n/**\n * Class to help with decorators.\n */\nexport class DecoratorHelper {\n\t/**\n\t * Get the schema from the reflection metadata.\n\t * @param target The object to get the schema data from.\n\t * @returns The schema from the metadata if it can be found.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static getSchema<T = unknown>(target: any): IEntitySchema<T> {\n\t\treturn (\n\t\t\tReflect.getMetadata(META_DATA_KEY, typeof target === \"object\" ? target : target.prototype) ??\n\t\t\t{}\n\t\t);\n\t}\n\n\t/**\n\t * Set the schema from the reflection metadata.\n\t * @param target The object to get the schema data from.\n\t * @param entitySchema The schema to set.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static setSchema<T = unknown>(target: any, entitySchema: IEntitySchema<T>): void {\n\t\tReflect.defineMetadata(\n\t\t\tMETA_DATA_KEY,\n\t\t\tentitySchema,\n\t\t\ttypeof target === \"object\" ? target : target.prototype\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"decoratorHelper.js","sourceRoot":"","sources":["../../../src/utils/decoratorHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,kBAAkB,CAAC;AAC1B,OAAO,OAAO,CAAC;AAGf,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;;;OAIG;IACH,8DAA8D;IACvD,MAAM,CAAC,SAAS,CAAc,MAAW;QAC/C,OAAO,CACN,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;YAC1F,EAAE,CACF,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,8DAA8D;IACvD,MAAM,CAAC,SAAS,CAAc,MAAW,EAAE,YAA8B;QAC/E,OAAO,CAAC,cAAc,CACrB,aAAa,EACb,YAAY,EACZ,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CACtD,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport \"reflect-metadata\";\nimport \"tslib\";\nimport type { IEntitySchema } from \"../models/IEntitySchema.js\";\n\nconst META_DATA_KEY = \"EntitySchemaMetadata\";\n\n/**\n * Class to help with decorators.\n */\nexport class DecoratorHelper {\n\t/**\n\t * Get the schema from the reflection metadata.\n\t * @param target The object to get the schema data from.\n\t * @returns The schema from the metadata if it can be found.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static getSchema<T = unknown>(target: any): IEntitySchema<T> {\n\t\treturn (\n\t\t\tReflect.getMetadata(META_DATA_KEY, typeof target === \"object\" ? target : target.prototype) ??\n\t\t\t{}\n\t\t);\n\t}\n\n\t/**\n\t * Set the schema from the reflection metadata.\n\t * @param target The object to get the schema data from.\n\t * @param entitySchema The schema to set.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static setSchema<T = unknown>(target: any, entitySchema: IEntitySchema<T>): void {\n\t\tReflect.defineMetadata(\n\t\t\tMETA_DATA_KEY,\n\t\t\tentitySchema,\n\t\t\ttypeof target === \"object\" ? target : target.prototype\n\t\t);\n\t}\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import "tslib";
2
3
  import type { IEntitySchemaOptions } from "../models/IEntitySchemaOptions.js";
3
4
  /**
4
5
  * Decorator to produce schema data for entity.
@@ -1,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import "tslib";
2
3
  import type { IEntitySchemaProperty } from "../models/IEntitySchemaProperty.js";
3
4
  /**
4
5
  * Decorator to produce schema property data for entities.
@@ -1,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import "tslib";
2
3
  import type { IEntitySchema } from "../models/IEntitySchema.js";
3
4
  /**
4
5
  * Class to help with decorators.
package/docs/changelog.md CHANGED
@@ -1,4 +1,42 @@
1
- # @twin.org/entity - Changelog
1
+ # Changelog
2
+
3
+ ## [0.0.3-next.24](https://github.com/twinfoundation/framework/compare/entity-v0.0.3-next.23...entity-v0.0.3-next.24) (2026-03-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * ensure __decorate is defined for decorators ([103a563](https://github.com/twinfoundation/framework/commit/103a563ce01ebdef6240d2e590e7b026e8692684))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.0.3-next.23 to 0.0.3-next.24
16
+ * @twin.org/core bumped from 0.0.3-next.23 to 0.0.3-next.24
17
+ * devDependencies
18
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.23 to 0.0.3-next.24
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.23 to 0.0.3-next.24
20
+ * @twin.org/validate-locales bumped from 0.0.3-next.23 to 0.0.3-next.24
21
+
22
+ ## [0.0.3-next.23](https://github.com/twinfoundation/framework/compare/entity-v0.0.3-next.22...entity-v0.0.3-next.23) (2026-03-17)
23
+
24
+
25
+ ### Miscellaneous Chores
26
+
27
+ * **entity:** Synchronize repo versions
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/nameof bumped from 0.0.3-next.22 to 0.0.3-next.23
35
+ * @twin.org/core bumped from 0.0.3-next.22 to 0.0.3-next.23
36
+ * devDependencies
37
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.22 to 0.0.3-next.23
38
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.22 to 0.0.3-next.23
39
+ * @twin.org/validate-locales bumped from 0.0.3-next.22 to 0.0.3-next.23
2
40
 
3
41
  ## [0.0.3-next.22](https://github.com/twinfoundation/framework/compare/entity-v0.0.3-next.21...entity-v0.0.3-next.22) (2026-02-26)
4
42
 
package/docs/examples.md CHANGED
@@ -1 +1,70 @@
1
- # @twin.org/entity - Examples
1
+ # Entity Examples
2
+
3
+ Use these snippets to build schemas, compose conditions and order data for query-style workflows.
4
+
5
+ ## EntitySchemaHelper
6
+
7
+ ```typescript
8
+ import { EntitySchemaHelper } from '@twin.org/entity';
9
+
10
+ class Product {
11
+ public id!: string;
12
+ public sku!: string;
13
+ public price!: number;
14
+ }
15
+
16
+ const schema = EntitySchemaHelper.getSchema(Product);
17
+ EntitySchemaHelper.getPrimaryKey(schema); // 'id'
18
+ EntitySchemaHelper.getSortProperties(schema); // ['sku', 'price']
19
+ ```
20
+
21
+ ## EntityConditions
22
+
23
+ ```typescript
24
+ import { EntityConditions } from '@twin.org/entity';
25
+
26
+ const product = {
27
+ sku: 'A-100',
28
+ price: 49.99,
29
+ active: true
30
+ };
31
+
32
+ EntityConditions.compare('eq', product.sku, 'A-100'); // true
33
+ EntityConditions.check(product, [{ property: 'price', comparison: 'gt', value: 10 }]); // true
34
+ ```
35
+
36
+ ## EntitySorter
37
+
38
+ ```typescript
39
+ import { EntitySorter } from '@twin.org/entity';
40
+
41
+ const records = [
42
+ { sku: 'A-300', price: 15 },
43
+ { sku: 'A-100', price: 20 },
44
+ { sku: 'A-200', price: 10 }
45
+ ];
46
+
47
+ EntitySorter.sort(records, [{ property: 'sku', sortDirection: 'ascending' }]);
48
+ ```
49
+
50
+ ## DecoratorHelper
51
+
52
+ ```typescript
53
+ import { DecoratorHelper } from '@twin.org/entity';
54
+
55
+ class Customer {
56
+ public id!: string;
57
+ }
58
+
59
+ DecoratorHelper.setSchema(Customer, {
60
+ primaryKey: 'id',
61
+ type: 'customer',
62
+ properties: {
63
+ id: {
64
+ type: 'string'
65
+ }
66
+ }
67
+ });
68
+
69
+ DecoratorHelper.getSchema(Customer)?.primaryKey; // 'id'
70
+ ```
@@ -14,7 +14,7 @@ Class to help with decorators.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### getSchema()
17
+ ### getSchema() {#getschema}
18
18
 
19
19
  > `static` **getSchema**\<`T`\>(`target`): [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
20
20
 
@@ -42,7 +42,7 @@ The schema from the metadata if it can be found.
42
42
 
43
43
  ***
44
44
 
45
- ### setSchema()
45
+ ### setSchema() {#setschema}
46
46
 
47
47
  > `static` **setSchema**\<`T`\>(`target`, `entitySchema`): `void`
48
48
 
@@ -14,7 +14,7 @@ Class to perform condition checks.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### check()
17
+ ### check() {#check}
18
18
 
19
19
  > `static` **check**\<`T`\>(`entity`, `condition?`): `boolean`
20
20
 
@@ -48,7 +48,7 @@ True if the entity matches.
48
48
 
49
49
  ***
50
50
 
51
- ### compare()
51
+ ### compare() {#compare}
52
52
 
53
53
  > `static` **compare**\<`T`\>(`entity`, `comparator`): `boolean`
54
54
 
@@ -14,7 +14,7 @@ Class to help with entity schema operations.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### CLASS\_NAME
17
+ ### CLASS\_NAME {#class_name}
18
18
 
19
19
  > `readonly` `static` **CLASS\_NAME**: `string`
20
20
 
@@ -22,7 +22,7 @@ Runtime name for the class.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### getSchema()
25
+ ### getSchema() {#getschema}
26
26
 
27
27
  > `static` **getSchema**\<`T`\>(`target`): [`IEntitySchema`](../interfaces/IEntitySchema.md)\<`T`\>
28
28
 
@@ -50,7 +50,7 @@ The schema for the object if it can be found.
50
50
 
51
51
  ***
52
52
 
53
- ### getPrimaryKey()
53
+ ### getPrimaryKey() {#getprimarykey}
54
54
 
55
55
  > `static` **getPrimaryKey**\<`T`\>(`entitySchema`): [`IEntitySchemaProperty`](../interfaces/IEntitySchemaProperty.md)\<`T`\>
56
56
 
@@ -82,7 +82,7 @@ If no primary key was found, or more than one.
82
82
 
83
83
  ***
84
84
 
85
- ### getSortProperties()
85
+ ### getSortProperties() {#getsortproperties}
86
86
 
87
87
  > `static` **getSortProperties**\<`T`\>(`entitySchema`): [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[] \| `undefined`
88
88
 
@@ -110,7 +110,7 @@ The sort keys from the schema or undefined if there are none.
110
110
 
111
111
  ***
112
112
 
113
- ### buildSortProperties()
113
+ ### buildSortProperties() {#buildsortproperties}
114
114
 
115
115
  > `static` **buildSortProperties**\<`T`\>(`entitySchema`, `overrideSortKeys?`): [`IEntitySort`](../interfaces/IEntitySort.md)\<`T`\>[] \| `undefined`
116
116
 
@@ -144,7 +144,7 @@ The finalised sort keys.
144
144
 
145
145
  ***
146
146
 
147
- ### validateEntity()
147
+ ### validateEntity() {#validateentity}
148
148
 
149
149
  > `static` **validateEntity**\<`T`\>(`entity`, `entitySchema`): `void`
150
150
 
@@ -14,7 +14,7 @@ Class to perform sort operations on entities.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### sort()
17
+ ### sort() {#sort}
18
18
 
19
19
  > `static` **sort**\<`T`\>(`entities`, `entitySorters?`): `T`[]
20
20
 
@@ -48,9 +48,9 @@ The sorted list.
48
48
 
49
49
  ***
50
50
 
51
- ### compare()
51
+ ### compare() {#compare}
52
52
 
53
- > `static` **compare**\<`T`\>(`entity1`, `entity2`, `prop`, `type`, `direction`): `number`
53
+ > `static` **compare**\<`T`\>(`entity1`, `entity2`, `prop`, `type`, `direction?`): `number`
54
54
 
55
55
  Compare two properties.
56
56
 
@@ -86,7 +86,7 @@ The property to compare.
86
86
 
87
87
  The type of the property.
88
88
 
89
- ##### direction
89
+ ##### direction?
90
90
 
91
91
  [`SortDirection`](../type-aliases/SortDirection.md) = `SortDirection.Ascending`
92
92
 
@@ -4,7 +4,7 @@ Interface defining comparator operator.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### property
7
+ ### property {#property}
8
8
 
9
9
  > **property**: `string`
10
10
 
@@ -12,7 +12,7 @@ The name of the property in the object to check.
12
12
 
13
13
  ***
14
14
 
15
- ### value
15
+ ### value {#value}
16
16
 
17
17
  > **value**: `unknown`
18
18
 
@@ -20,7 +20,7 @@ The value of the property to check.
20
20
 
21
21
  ***
22
22
 
23
- ### comparison
23
+ ### comparison {#comparison}
24
24
 
25
25
  > **comparison**: [`ComparisonOperator`](../type-aliases/ComparisonOperator.md)
26
26
 
@@ -10,7 +10,7 @@ Interface defining condition group operator.
10
10
 
11
11
  ## Properties
12
12
 
13
- ### conditions
13
+ ### conditions {#conditions}
14
14
 
15
15
  > **conditions**: [`EntityCondition`](../type-aliases/EntityCondition.md)\<`T`\>[]
16
16
 
@@ -18,8 +18,8 @@ The conditions to join in a group.
18
18
 
19
19
  ***
20
20
 
21
- ### logicalOperator?
21
+ ### logicalOperator? {#logicaloperator}
22
22
 
23
- > `optional` **logicalOperator**: [`LogicalOperator`](../type-aliases/LogicalOperator.md)
23
+ > `optional` **logicalOperator?**: [`LogicalOperator`](../type-aliases/LogicalOperator.md)
24
24
 
25
25
  The logical operator to use.
@@ -10,7 +10,7 @@ Definition for an entity schema.
10
10
 
11
11
  ## Properties
12
12
 
13
- ### type
13
+ ### type {#type}
14
14
 
15
15
  > **type**: `string` \| `undefined`
16
16
 
@@ -18,16 +18,16 @@ The type of the entity.
18
18
 
19
19
  ***
20
20
 
21
- ### options?
21
+ ### options? {#options}
22
22
 
23
- > `optional` **options**: [`IEntitySchemaOptions`](IEntitySchemaOptions.md)
23
+ > `optional` **options?**: [`IEntitySchemaOptions`](IEntitySchemaOptions.md)
24
24
 
25
25
  The options for the entity.
26
26
 
27
27
  ***
28
28
 
29
- ### properties?
29
+ ### properties? {#properties}
30
30
 
31
- > `optional` **properties**: [`IEntitySchemaProperty`](IEntitySchemaProperty.md)\<`T`\>[]
31
+ > `optional` **properties?**: [`IEntitySchemaProperty`](IEntitySchemaProperty.md)\<`T`\>[]
32
32
 
33
33
  The properties of the entity.
@@ -4,8 +4,8 @@ Definition for an entity schema options.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### description?
7
+ ### description? {#description}
8
8
 
9
- > `optional` **description**: `string`
9
+ > `optional` **description?**: `string`
10
10
 
11
11
  Description of the object.
@@ -10,7 +10,7 @@ Definition for an entity schema property.
10
10
 
11
11
  ## Properties
12
12
 
13
- ### property
13
+ ### property {#property}
14
14
 
15
15
  > **property**: keyof `T`
16
16
 
@@ -18,7 +18,7 @@ The property name from the entity.
18
18
 
19
19
  ***
20
20
 
21
- ### type
21
+ ### type {#type}
22
22
 
23
23
  > **type**: [`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
24
24
 
@@ -26,72 +26,72 @@ The type of the property.
26
26
 
27
27
  ***
28
28
 
29
- ### format?
29
+ ### format? {#format}
30
30
 
31
- > `optional` **format**: [`EntitySchemaPropertyFormat`](../type-aliases/EntitySchemaPropertyFormat.md)
31
+ > `optional` **format?**: [`EntitySchemaPropertyFormat`](../type-aliases/EntitySchemaPropertyFormat.md)
32
32
 
33
33
  The format of the property.
34
34
 
35
35
  ***
36
36
 
37
- ### isPrimary?
37
+ ### isPrimary? {#isprimary}
38
38
 
39
- > `optional` **isPrimary**: `boolean`
39
+ > `optional` **isPrimary?**: `boolean`
40
40
 
41
41
  Is this the primary index property.
42
42
 
43
43
  ***
44
44
 
45
- ### isSecondary?
45
+ ### isSecondary? {#issecondary}
46
46
 
47
- > `optional` **isSecondary**: `boolean`
47
+ > `optional` **isSecondary?**: `boolean`
48
48
 
49
49
  Is this a secondary index property.
50
50
 
51
51
  ***
52
52
 
53
- ### sortDirection?
53
+ ### sortDirection? {#sortdirection}
54
54
 
55
- > `optional` **sortDirection**: [`SortDirection`](../type-aliases/SortDirection.md)
55
+ > `optional` **sortDirection?**: [`SortDirection`](../type-aliases/SortDirection.md)
56
56
 
57
57
  Default sort direction for this field, leave empty if not sortable.
58
58
 
59
59
  ***
60
60
 
61
- ### optional?
61
+ ### optional? {#optional}
62
62
 
63
- > `optional` **optional**: `boolean`
63
+ > `optional` **optional?**: `boolean`
64
64
 
65
65
  Is the property optional.
66
66
 
67
67
  ***
68
68
 
69
- ### itemType?
69
+ ### itemType? {#itemtype}
70
70
 
71
- > `optional` **itemType**: [`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
71
+ > `optional` **itemType?**: [`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
72
72
 
73
73
  The type of the item (only applies when type is `array`).
74
74
 
75
75
  ***
76
76
 
77
- ### itemTypeRef?
77
+ ### itemTypeRef? {#itemtyperef}
78
78
 
79
- > `optional` **itemTypeRef**: `string`
79
+ > `optional` **itemTypeRef?**: `string`
80
80
 
81
81
  The type ref of the item (only applies when type is either `array` or `object`).
82
82
 
83
83
  ***
84
84
 
85
- ### description?
85
+ ### description? {#description}
86
86
 
87
- > `optional` **description**: `string`
87
+ > `optional` **description?**: `string`
88
88
 
89
89
  Description of the object.
90
90
 
91
91
  ***
92
92
 
93
- ### examples?
93
+ ### examples? {#examples}
94
94
 
95
- > `optional` **examples**: `unknown`[]
95
+ > `optional` **examples?**: `unknown`[]
96
96
 
97
97
  Examples of the property values.
@@ -10,7 +10,7 @@ Definition of an entity property sort details.
10
10
 
11
11
  ## Properties
12
12
 
13
- ### property
13
+ ### property {#property}
14
14
 
15
15
  > **property**: keyof `T`
16
16
 
@@ -18,7 +18,7 @@ The name of the property.
18
18
 
19
19
  ***
20
20
 
21
- ### type
21
+ ### type {#type}
22
22
 
23
23
  > **type**: [`EntitySchemaPropertyType`](../type-aliases/EntitySchemaPropertyType.md)
24
24
 
@@ -26,7 +26,7 @@ The type of the property.
26
26
 
27
27
  ***
28
28
 
29
- ### sortDirection
29
+ ### sortDirection {#sortdirection}
30
30
 
31
31
  > **sortDirection**: [`SortDirection`](../type-aliases/SortDirection.md)
32
32
 
@@ -6,43 +6,43 @@ The types of comparisons.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### Equals
9
+ ### Equals {#equals}
10
10
 
11
11
  > `readonly` **Equals**: `"equals"` = `"equals"`
12
12
 
13
13
  Equals.
14
14
 
15
- ### NotEquals
15
+ ### NotEquals {#notequals}
16
16
 
17
17
  > `readonly` **NotEquals**: `"not-equals"` = `"not-equals"`
18
18
 
19
19
  Not Equals.
20
20
 
21
- ### GreaterThan
21
+ ### GreaterThan {#greaterthan}
22
22
 
23
23
  > `readonly` **GreaterThan**: `"greater-than"` = `"greater-than"`
24
24
 
25
25
  Greater Than.
26
26
 
27
- ### GreaterThanOrEqual
27
+ ### GreaterThanOrEqual {#greaterthanorequal}
28
28
 
29
29
  > `readonly` **GreaterThanOrEqual**: `"greater-than-or-equal"` = `"greater-than-or-equal"`
30
30
 
31
31
  Greater Than Or Equal.
32
32
 
33
- ### LessThan
33
+ ### LessThan {#lessthan}
34
34
 
35
35
  > `readonly` **LessThan**: `"less-than"` = `"less-than"`
36
36
 
37
37
  Less Than.
38
38
 
39
- ### LessThanOrEqual
39
+ ### LessThanOrEqual {#lessthanorequal}
40
40
 
41
41
  > `readonly` **LessThanOrEqual**: `"less-than-or-equal"` = `"less-than-or-equal"`
42
42
 
43
43
  Less Than Or Equal.
44
44
 
45
- ### Includes
45
+ ### Includes {#includes}
46
46
 
47
47
  > `readonly` **Includes**: `"includes"` = `"includes"`
48
48
 
@@ -51,7 +51,7 @@ A string in a substring.
51
51
  A set contains an element.
52
52
  A list contains an element.
53
53
 
54
- ### NotIncludes
54
+ ### NotIncludes {#notincludes}
55
55
 
56
56
  > `readonly` **NotIncludes**: `"not-includes"` = `"not-includes"`
57
57
 
@@ -60,7 +60,7 @@ A string not in a substring.
60
60
  A set does not contain an element.
61
61
  A list does not contain an element.
62
62
 
63
- ### In
63
+ ### In {#in}
64
64
 
65
65
  > `readonly` **In**: `"in"` = `"in"`
66
66
 
@@ -6,103 +6,103 @@ Definition of the entity property format.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### Uuid
9
+ ### Uuid {#uuid}
10
10
 
11
11
  > `readonly` **Uuid**: `"uuid"` = `"uuid"`
12
12
 
13
13
  UUID.
14
14
 
15
- ### Uri
15
+ ### Uri {#uri}
16
16
 
17
17
  > `readonly` **Uri**: `"uri"` = `"uri"`
18
18
 
19
19
  URI.
20
20
 
21
- ### Email
21
+ ### Email {#email}
22
22
 
23
23
  > `readonly` **Email**: `"email"` = `"email"`
24
24
 
25
25
  email.
26
26
 
27
- ### Int8
27
+ ### Int8 {#int8}
28
28
 
29
29
  > `readonly` **Int8**: `"int8"` = `"int8"`
30
30
 
31
31
  int8.
32
32
 
33
- ### Uint8
33
+ ### Uint8 {#uint8}
34
34
 
35
35
  > `readonly` **Uint8**: `"uint8"` = `"uint8"`
36
36
 
37
37
  uint8.
38
38
 
39
- ### Int16
39
+ ### Int16 {#int16}
40
40
 
41
41
  > `readonly` **Int16**: `"int16"` = `"int16"`
42
42
 
43
43
  int16.
44
44
 
45
- ### Uint16
45
+ ### Uint16 {#uint16}
46
46
 
47
47
  > `readonly` **Uint16**: `"uint16"` = `"uint16"`
48
48
 
49
49
  uint16.
50
50
 
51
- ### Int32
51
+ ### Int32 {#int32}
52
52
 
53
53
  > `readonly` **Int32**: `"int32"` = `"int32"`
54
54
 
55
55
  int32.
56
56
 
57
- ### Uint32
57
+ ### Uint32 {#uint32}
58
58
 
59
59
  > `readonly` **Uint32**: `"uint32"` = `"uint32"`
60
60
 
61
61
  uint32.
62
62
 
63
- ### Float
63
+ ### Float {#float}
64
64
 
65
65
  > `readonly` **Float**: `"float"` = `"float"`
66
66
 
67
67
  float.
68
68
 
69
- ### Double
69
+ ### Double {#double}
70
70
 
71
71
  > `readonly` **Double**: `"double"` = `"double"`
72
72
 
73
73
  double.
74
74
 
75
- ### Int64
75
+ ### Int64 {#int64}
76
76
 
77
77
  > `readonly` **Int64**: `"int64"` = `"int64"`
78
78
 
79
79
  int64.
80
80
 
81
- ### Uint64
81
+ ### Uint64 {#uint64}
82
82
 
83
83
  > `readonly` **Uint64**: `"uint64"` = `"uint64"`
84
84
 
85
85
  uint64.
86
86
 
87
- ### Date
87
+ ### Date {#date}
88
88
 
89
89
  > `readonly` **Date**: `"date"` = `"date"`
90
90
 
91
91
  date.
92
92
 
93
- ### Time
93
+ ### Time {#time}
94
94
 
95
95
  > `readonly` **Time**: `"time"` = `"time"`
96
96
 
97
97
  time.
98
98
 
99
- ### DateTime
99
+ ### DateTime {#datetime}
100
100
 
101
101
  > `readonly` **DateTime**: `"date-time"` = `"date-time"`
102
102
 
103
103
  date-time.
104
104
 
105
- ### Json
105
+ ### Json {#json}
106
106
 
107
107
  > `readonly` **Json**: `"json"` = `"json"`
108
108
 
@@ -6,37 +6,37 @@ Definition of the entity property types.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### String
9
+ ### String {#string}
10
10
 
11
11
  > `readonly` **String**: `"string"` = `"string"`
12
12
 
13
13
  String.
14
14
 
15
- ### Number
15
+ ### Number {#number}
16
16
 
17
17
  > `readonly` **Number**: `"number"` = `"number"`
18
18
 
19
19
  Number.
20
20
 
21
- ### Integer
21
+ ### Integer {#integer}
22
22
 
23
23
  > `readonly` **Integer**: `"integer"` = `"integer"`
24
24
 
25
25
  Integer.
26
26
 
27
- ### Boolean
27
+ ### Boolean {#boolean}
28
28
 
29
29
  > `readonly` **Boolean**: `"boolean"` = `"boolean"`
30
30
 
31
31
  Boolean.
32
32
 
33
- ### Array
33
+ ### Array {#array}
34
34
 
35
35
  > `readonly` **Array**: `"array"` = `"array"`
36
36
 
37
37
  Array.
38
38
 
39
- ### Object
39
+ ### Object {#object}
40
40
 
41
41
  > `readonly` **Object**: `"object"` = `"object"`
42
42
 
@@ -6,13 +6,13 @@ The logical operators for condition combining.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### And
9
+ ### And {#and}
10
10
 
11
11
  > `readonly` **And**: `"and"` = `"and"`
12
12
 
13
13
  Logical operator AND.
14
14
 
15
- ### Or
15
+ ### Or {#or}
16
16
 
17
17
  > `readonly` **Or**: `"or"` = `"or"`
18
18
 
@@ -6,13 +6,13 @@ The sort directions.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### Ascending
9
+ ### Ascending {#ascending}
10
10
 
11
11
  > `readonly` **Ascending**: `"asc"` = `"asc"`
12
12
 
13
13
  Ascending.
14
14
 
15
- ### Descending
15
+ ### Descending {#descending}
16
16
 
17
17
  > `readonly` **Descending**: `"desc"` = `"desc"`
18
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity",
3
- "version": "0.0.3-next.22",
3
+ "version": "0.0.3-next.24",
4
4
  "description": "Helpers for defining and working with entities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,9 +14,10 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "0.0.3-next.22",
18
- "@twin.org/nameof": "0.0.3-next.22",
19
- "reflect-metadata": "0.2.2"
17
+ "@twin.org/core": "0.0.3-next.24",
18
+ "@twin.org/nameof": "0.0.3-next.24",
19
+ "reflect-metadata": "0.2.2",
20
+ "tslib": "2.8.1"
20
21
  },
21
22
  "main": "./dist/es/index.js",
22
23
  "types": "./dist/types/index.d.ts",