@twin.org/entity 0.0.2-next.9 → 0.0.3-next.2
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/es/decorators/entityDecorator.js +19 -0
- package/dist/es/decorators/entityDecorator.js.map +1 -0
- package/dist/es/decorators/propertyDecorator.js +31 -0
- package/dist/es/decorators/propertyDecorator.js.map +1 -0
- package/dist/es/factories/entitySchemaFactory.js +9 -0
- package/dist/es/factories/entitySchemaFactory.js.map +1 -0
- package/dist/es/index.js +22 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IComparator.js +2 -0
- package/dist/es/models/IComparator.js.map +1 -0
- package/dist/es/models/IComparatorGroup.js +2 -0
- package/dist/es/models/IComparatorGroup.js.map +1 -0
- package/dist/es/models/IEntitySchema.js +2 -0
- package/dist/es/models/IEntitySchema.js.map +1 -0
- package/dist/es/models/IEntitySchemaOptions.js +4 -0
- package/dist/es/models/IEntitySchemaOptions.js.map +1 -0
- package/dist/es/models/IEntitySchemaProperty.js +2 -0
- package/dist/es/models/IEntitySchemaProperty.js.map +1 -0
- package/dist/es/models/IEntitySort.js +2 -0
- package/dist/es/models/IEntitySort.js.map +1 -0
- package/dist/es/models/comparisonOperator.js +52 -0
- package/dist/es/models/comparisonOperator.js.map +1 -0
- package/dist/es/models/entityCondition.js +2 -0
- package/dist/es/models/entityCondition.js.map +1 -0
- package/dist/es/models/entitySchemaPropertyFormat.js +77 -0
- package/dist/es/models/entitySchemaPropertyFormat.js.map +1 -0
- package/dist/es/models/entitySchemaPropertyType.js +33 -0
- package/dist/es/models/entitySchemaPropertyType.js.map +1 -0
- package/dist/es/models/logicalOperator.js +17 -0
- package/dist/es/models/logicalOperator.js.map +1 -0
- package/dist/es/models/sortDirection.js +17 -0
- package/dist/es/models/sortDirection.js.map +1 -0
- package/dist/es/utils/decoratorHelper.js +29 -0
- package/dist/es/utils/decoratorHelper.js.map +1 -0
- package/dist/es/utils/entityConditions.js +175 -0
- package/dist/es/utils/entityConditions.js.map +1 -0
- package/dist/es/utils/entitySchemaHelper.js +143 -0
- package/dist/es/utils/entitySchemaHelper.js.map +1 -0
- package/dist/es/utils/entitySorter.js +72 -0
- package/dist/es/utils/entitySorter.js.map +1 -0
- package/dist/types/decorators/entityDecorator.d.ts +1 -1
- package/dist/types/decorators/propertyDecorator.d.ts +1 -1
- package/dist/types/factories/entitySchemaFactory.d.ts +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/models/IComparator.d.ts +1 -1
- package/dist/types/models/IComparatorGroup.d.ts +2 -2
- package/dist/types/models/IEntitySchema.d.ts +2 -2
- package/dist/types/models/IEntitySchemaProperty.d.ts +3 -3
- package/dist/types/models/IEntitySort.d.ts +2 -2
- package/dist/types/models/entityCondition.d.ts +2 -2
- package/dist/types/utils/decoratorHelper.d.ts +1 -1
- package/dist/types/utils/entityConditions.d.ts +2 -2
- package/dist/types/utils/entitySchemaHelper.d.ts +8 -4
- package/dist/types/utils/entitySorter.d.ts +3 -3
- package/docs/changelog.md +281 -0
- package/docs/reference/classes/EntitySchemaHelper.md +12 -4
- package/docs/reference/interfaces/IEntitySchema.md +1 -1
- package/package.json +19 -10
- package/dist/cjs/index.cjs +0 -673
- package/dist/esm/index.mjs +0 -660
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
import "reflect-metadata";
|
|
5
|
+
import { DecoratorHelper } from "../utils/decoratorHelper.js";
|
|
6
|
+
/**
|
|
7
|
+
* Decorator to produce schema data for entity.
|
|
8
|
+
* @param options The options for the entity.
|
|
9
|
+
* @returns The class decorator.
|
|
10
|
+
*/
|
|
11
|
+
export function entity(options) {
|
|
12
|
+
return (target) => {
|
|
13
|
+
const entitySchema = DecoratorHelper.getSchema(target);
|
|
14
|
+
entitySchema.type = target.name;
|
|
15
|
+
entitySchema.options = options;
|
|
16
|
+
DecoratorHelper.setSchema(target, entitySchema);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=entityDecorator.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
import "reflect-metadata";
|
|
5
|
+
import { DecoratorHelper } from "../utils/decoratorHelper.js";
|
|
6
|
+
/**
|
|
7
|
+
* Decorator to produce schema property data for entities.
|
|
8
|
+
* @param options The options for the property.
|
|
9
|
+
* @returns The property decorator.
|
|
10
|
+
*/
|
|
11
|
+
export function property(options) {
|
|
12
|
+
return (target, propertyKey) => {
|
|
13
|
+
const entitySchema = DecoratorHelper.getSchema(target);
|
|
14
|
+
entitySchema.properties ??= [];
|
|
15
|
+
const idx = entitySchema.properties.findIndex(p => p.property === propertyKey);
|
|
16
|
+
if (idx !== -1) {
|
|
17
|
+
entitySchema.properties[idx] = {
|
|
18
|
+
...options,
|
|
19
|
+
property: propertyKey
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
entitySchema.properties.push({
|
|
24
|
+
...options,
|
|
25
|
+
property: propertyKey
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
DecoratorHelper.setSchema(target, entitySchema);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=propertyDecorator.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating entity schemas.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const EntitySchemaFactory = Factory.createFactory("entity-schema");
|
|
9
|
+
//# sourceMappingURL=entitySchemaFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitySchemaFactory.js","sourceRoot":"","sources":["../../../src/factories/entitySchemaFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAgB,eAAe,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@twin.org/core\";\nimport type { IEntitySchema } from \"../models/IEntitySchema.js\";\n\n/**\n * Factory for creating entity schemas.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const EntitySchemaFactory = Factory.createFactory<IEntitySchema>(\"entity-schema\");\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./decorators/entityDecorator.js";
|
|
4
|
+
export * from "./decorators/propertyDecorator.js";
|
|
5
|
+
export * from "./factories/entitySchemaFactory.js";
|
|
6
|
+
export * from "./models/comparisonOperator.js";
|
|
7
|
+
export * from "./models/entityCondition.js";
|
|
8
|
+
export * from "./models/entitySchemaPropertyFormat.js";
|
|
9
|
+
export * from "./models/entitySchemaPropertyType.js";
|
|
10
|
+
export * from "./models/IComparator.js";
|
|
11
|
+
export * from "./models/IComparatorGroup.js";
|
|
12
|
+
export * from "./models/IEntitySchema.js";
|
|
13
|
+
export * from "./models/IEntitySchemaOptions.js";
|
|
14
|
+
export * from "./models/IEntitySchemaProperty.js";
|
|
15
|
+
export * from "./models/IEntitySort.js";
|
|
16
|
+
export * from "./models/logicalOperator.js";
|
|
17
|
+
export * from "./models/sortDirection.js";
|
|
18
|
+
export * from "./utils/decoratorHelper.js";
|
|
19
|
+
export * from "./utils/entityConditions.js";
|
|
20
|
+
export * from "./utils/entitySchemaHelper.js";
|
|
21
|
+
export * from "./utils/entitySorter.js";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./decorators/entityDecorator.js\";\nexport * from \"./decorators/propertyDecorator.js\";\nexport * from \"./factories/entitySchemaFactory.js\";\nexport * from \"./models/comparisonOperator.js\";\nexport * from \"./models/entityCondition.js\";\nexport * from \"./models/entitySchemaPropertyFormat.js\";\nexport * from \"./models/entitySchemaPropertyType.js\";\nexport * from \"./models/IComparator.js\";\nexport * from \"./models/IComparatorGroup.js\";\nexport * from \"./models/IEntitySchema.js\";\nexport * from \"./models/IEntitySchemaOptions.js\";\nexport * from \"./models/IEntitySchemaProperty.js\";\nexport * from \"./models/IEntitySort.js\";\nexport * from \"./models/logicalOperator.js\";\nexport * from \"./models/sortDirection.js\";\nexport * from \"./utils/decoratorHelper.js\";\nexport * from \"./utils/entityConditions.js\";\nexport * from \"./utils/entitySchemaHelper.js\";\nexport * from \"./utils/entitySorter.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IComparator.js","sourceRoot":"","sources":["../../../src/models/IComparator.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ComparisonOperator } from \"./comparisonOperator.js\";\n\n/**\n * Interface defining comparator operator.\n */\nexport interface IComparator {\n\t/**\n\t * The name of the property in the object to check.\n\t */\n\tproperty: string;\n\n\t/**\n\t * The value of the property to check.\n\t */\n\tvalue: unknown;\n\n\t/**\n\t * The comparison to perform.\n\t */\n\tcomparison: ComparisonOperator;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IComparatorGroup.js","sourceRoot":"","sources":["../../../src/models/IComparatorGroup.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { EntityCondition } from \"./entityCondition.js\";\nimport type { LogicalOperator } from \"./logicalOperator.js\";\n\n/**\n * Interface defining condition group operator.\n */\nexport interface IComparatorGroup<T = unknown> {\n\t/**\n\t * The conditions to join in a group.\n\t */\n\tconditions: EntityCondition<T>[];\n\n\t/**\n\t * The logical operator to use.\n\t */\n\tlogicalOperator?: LogicalOperator;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEntitySchema.js","sourceRoot":"","sources":["../../../src/models/IEntitySchema.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEntitySchemaOptions } from \"./IEntitySchemaOptions.js\";\nimport type { IEntitySchemaProperty } from \"./IEntitySchemaProperty.js\";\n\n/**\n * Definition for an entity schema.\n */\nexport interface IEntitySchema<T = unknown> {\n\t/**\n\t * The type of the entity.\n\t */\n\ttype: string | undefined;\n\n\t/**\n\t * The options for the entity.\n\t */\n\toptions?: IEntitySchemaOptions;\n\n\t/**\n\t * The properties of the entity.\n\t */\n\tproperties?: IEntitySchemaProperty<T>[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEntitySchemaOptions.js","sourceRoot":"","sources":["../../../src/models/IEntitySchemaOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Definition for an entity schema options.\n */\nexport interface IEntitySchemaOptions {\n\t/**\n\t * Description of the object.\n\t */\n\tdescription?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEntitySchemaProperty.js","sourceRoot":"","sources":["../../../src/models/IEntitySchemaProperty.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { EntitySchemaPropertyFormat } from \"./entitySchemaPropertyFormat.js\";\nimport type { EntitySchemaPropertyType } from \"./entitySchemaPropertyType.js\";\nimport type { SortDirection } from \"./sortDirection.js\";\n\n/**\n * Definition for an entity schema property.\n */\nexport interface IEntitySchemaProperty<T = unknown> {\n\t/**\n\t * The property name from the entity.\n\t */\n\tproperty: keyof T;\n\n\t/**\n\t * The type of the property.\n\t */\n\ttype: EntitySchemaPropertyType;\n\n\t/**\n\t * The format of the property.\n\t */\n\tformat?: EntitySchemaPropertyFormat;\n\n\t/**\n\t * Is this the primary index property.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Is this a secondary index property.\n\t */\n\tisSecondary?: boolean;\n\n\t/**\n\t * Default sort direction for this field, leave empty if not sortable.\n\t */\n\tsortDirection?: SortDirection;\n\n\t/**\n\t * Is the property optional.\n\t */\n\toptional?: boolean;\n\n\t/**\n\t * The type of the item (only applies when type is `array`).\n\t */\n\titemType?: EntitySchemaPropertyType;\n\n\t/**\n\t * The type ref of the item (only applies when type is either `array` or `object`).\n\t */\n\titemTypeRef?: string;\n\n\t/**\n\t * Description of the object.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Examples of the property values.\n\t */\n\texamples?: unknown[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEntitySort.js","sourceRoot":"","sources":["../../../src/models/IEntitySort.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { EntitySchemaPropertyType } from \"./entitySchemaPropertyType.js\";\nimport type { SortDirection } from \"./sortDirection.js\";\n\n/**\n * Definition of an entity property sort details.\n */\nexport interface IEntitySort<T> {\n\t/**\n\t * The name of the property.\n\t */\n\tproperty: keyof T;\n\n\t/**\n\t * The type of the property.\n\t */\n\ttype: EntitySchemaPropertyType;\n\n\t/**\n\t * Default sort direction for this column, leave empty if not sortable.\n\t */\n\tsortDirection: SortDirection;\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The types of comparisons.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const ComparisonOperator = {
|
|
8
|
+
/**
|
|
9
|
+
* Equals.
|
|
10
|
+
*/
|
|
11
|
+
Equals: "equals",
|
|
12
|
+
/**
|
|
13
|
+
* Not Equals.
|
|
14
|
+
*/
|
|
15
|
+
NotEquals: "not-equals",
|
|
16
|
+
/**
|
|
17
|
+
* Greater Than.
|
|
18
|
+
*/
|
|
19
|
+
GreaterThan: "greater-than",
|
|
20
|
+
/**
|
|
21
|
+
* Greater Than Or Equal.
|
|
22
|
+
*/
|
|
23
|
+
GreaterThanOrEqual: "greater-than-or-equal",
|
|
24
|
+
/**
|
|
25
|
+
* Less Than.
|
|
26
|
+
*/
|
|
27
|
+
LessThan: "less-than",
|
|
28
|
+
/**
|
|
29
|
+
* Less Than Or Equal.
|
|
30
|
+
*/
|
|
31
|
+
LessThanOrEqual: "less-than-or-equal",
|
|
32
|
+
/**
|
|
33
|
+
* Includes.
|
|
34
|
+
* A string in a substring.
|
|
35
|
+
* A set contains an element.
|
|
36
|
+
* A list contains an element.
|
|
37
|
+
*/
|
|
38
|
+
Includes: "includes",
|
|
39
|
+
/**
|
|
40
|
+
* Not Includes.
|
|
41
|
+
* A string not in a substring.
|
|
42
|
+
* A set does not contain an element.
|
|
43
|
+
* A list does not contain an element.
|
|
44
|
+
*/
|
|
45
|
+
NotIncludes: "not-includes",
|
|
46
|
+
/**
|
|
47
|
+
* In.
|
|
48
|
+
* A element is in a set.
|
|
49
|
+
*/
|
|
50
|
+
In: "in"
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=comparisonOperator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparisonOperator.js","sourceRoot":"","sources":["../../../src/models/comparisonOperator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,SAAS,EAAE,YAAY;IAEvB;;OAEG;IACH,WAAW,EAAE,cAAc;IAE3B;;OAEG;IACH,kBAAkB,EAAE,uBAAuB;IAE3C;;OAEG;IACH,QAAQ,EAAE,WAAW;IAErB;;OAEG;IACH,eAAe,EAAE,oBAAoB;IAErC;;;;;OAKG;IACH,QAAQ,EAAE,UAAU;IAEpB;;;;;OAKG;IACH,WAAW,EAAE,cAAc;IAE3B;;;OAGG;IACH,EAAE,EAAE,IAAI;CACC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The types of comparisons.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ComparisonOperator = {\n\t/**\n\t * Equals.\n\t */\n\tEquals: \"equals\",\n\n\t/**\n\t * Not Equals.\n\t */\n\tNotEquals: \"not-equals\",\n\n\t/**\n\t * Greater Than.\n\t */\n\tGreaterThan: \"greater-than\",\n\n\t/**\n\t * Greater Than Or Equal.\n\t */\n\tGreaterThanOrEqual: \"greater-than-or-equal\",\n\n\t/**\n\t * Less Than.\n\t */\n\tLessThan: \"less-than\",\n\n\t/**\n\t * Less Than Or Equal.\n\t */\n\tLessThanOrEqual: \"less-than-or-equal\",\n\n\t/**\n\t * Includes.\n\t * A string in a substring.\n\t * A set contains an element.\n\t * A list contains an element.\n\t */\n\tIncludes: \"includes\",\n\n\t/**\n\t * Not Includes.\n\t * A string not in a substring.\n\t * A set does not contain an element.\n\t * A list does not contain an element.\n\t */\n\tNotIncludes: \"not-includes\",\n\n\t/**\n\t * In.\n\t * A element is in a set.\n\t */\n\tIn: \"in\"\n} as const;\n\n/**\n * The types of comparisons.\n */\nexport type ComparisonOperator = (typeof ComparisonOperator)[keyof typeof ComparisonOperator];\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityCondition.js","sourceRoot":"","sources":["../../../src/models/entityCondition.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComparator } from \"./IComparator.js\";\nimport type { IComparatorGroup } from \"./IComparatorGroup.js\";\n\n/**\n * Type defining condition for entities filtering.\n */\nexport type EntityCondition<T> = IComparator | IComparatorGroup<T>;\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* Definition of the entity property format.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const EntitySchemaPropertyFormat = {
|
|
8
|
+
/**
|
|
9
|
+
* UUID.
|
|
10
|
+
*/
|
|
11
|
+
Uuid: "uuid",
|
|
12
|
+
/**
|
|
13
|
+
* URI.
|
|
14
|
+
*/
|
|
15
|
+
Uri: "uri",
|
|
16
|
+
/**
|
|
17
|
+
* email.
|
|
18
|
+
*/
|
|
19
|
+
Email: "email",
|
|
20
|
+
/**
|
|
21
|
+
* int8.
|
|
22
|
+
*/
|
|
23
|
+
Int8: "int8",
|
|
24
|
+
/**
|
|
25
|
+
* uint8.
|
|
26
|
+
*/
|
|
27
|
+
Uint8: "uint8",
|
|
28
|
+
/**
|
|
29
|
+
* int16.
|
|
30
|
+
*/
|
|
31
|
+
Int16: "int16",
|
|
32
|
+
/**
|
|
33
|
+
* uint16.
|
|
34
|
+
*/
|
|
35
|
+
Uint16: "uint16",
|
|
36
|
+
/**
|
|
37
|
+
* int32.
|
|
38
|
+
*/
|
|
39
|
+
Int32: "int32",
|
|
40
|
+
/**
|
|
41
|
+
* uint32.
|
|
42
|
+
*/
|
|
43
|
+
Uint32: "uint32",
|
|
44
|
+
/**
|
|
45
|
+
* float.
|
|
46
|
+
*/
|
|
47
|
+
Float: "float",
|
|
48
|
+
/**
|
|
49
|
+
* double.
|
|
50
|
+
*/
|
|
51
|
+
Double: "double",
|
|
52
|
+
/**
|
|
53
|
+
* int64.
|
|
54
|
+
*/
|
|
55
|
+
Int64: "int64",
|
|
56
|
+
/**
|
|
57
|
+
* uint64.
|
|
58
|
+
*/
|
|
59
|
+
Uint64: "uint64",
|
|
60
|
+
/**
|
|
61
|
+
* date.
|
|
62
|
+
*/
|
|
63
|
+
Date: "date",
|
|
64
|
+
/**
|
|
65
|
+
* time.
|
|
66
|
+
*/
|
|
67
|
+
Time: "time",
|
|
68
|
+
/**
|
|
69
|
+
* date-time.
|
|
70
|
+
*/
|
|
71
|
+
DateTime: "date-time",
|
|
72
|
+
/**
|
|
73
|
+
* JSON.
|
|
74
|
+
*/
|
|
75
|
+
Json: "json"
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=entitySchemaPropertyFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitySchemaPropertyFormat.js","sourceRoot":"","sources":["../../../src/models/entitySchemaPropertyFormat.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACzC;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,GAAG,EAAE,KAAK;IAEV;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,QAAQ,EAAE,WAAW;IAErB;;OAEG;IACH,IAAI,EAAE,MAAM;CACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Definition of the entity property format.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const EntitySchemaPropertyFormat = {\n\t/**\n\t * UUID.\n\t */\n\tUuid: \"uuid\",\n\n\t/**\n\t * URI.\n\t */\n\tUri: \"uri\",\n\n\t/**\n\t * email.\n\t */\n\tEmail: \"email\",\n\n\t/**\n\t * int8.\n\t */\n\tInt8: \"int8\",\n\n\t/**\n\t * uint8.\n\t */\n\tUint8: \"uint8\",\n\n\t/**\n\t * int16.\n\t */\n\tInt16: \"int16\",\n\n\t/**\n\t * uint16.\n\t */\n\tUint16: \"uint16\",\n\n\t/**\n\t * int32.\n\t */\n\tInt32: \"int32\",\n\n\t/**\n\t * uint32.\n\t */\n\tUint32: \"uint32\",\n\n\t/**\n\t * float.\n\t */\n\tFloat: \"float\",\n\n\t/**\n\t * double.\n\t */\n\tDouble: \"double\",\n\n\t/**\n\t * int64.\n\t */\n\tInt64: \"int64\",\n\n\t/**\n\t * uint64.\n\t */\n\tUint64: \"uint64\",\n\n\t/**\n\t * date.\n\t */\n\tDate: \"date\",\n\n\t/**\n\t * time.\n\t */\n\tTime: \"time\",\n\n\t/**\n\t * date-time.\n\t */\n\tDateTime: \"date-time\",\n\n\t/**\n\t * JSON.\n\t */\n\tJson: \"json\"\n} as const;\n\n/**\n * Definition of the entity property type's format.\n */\nexport type EntitySchemaPropertyFormat =\n\t(typeof EntitySchemaPropertyFormat)[keyof typeof EntitySchemaPropertyFormat];\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* Definition of the entity property types.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const EntitySchemaPropertyType = {
|
|
8
|
+
/**
|
|
9
|
+
* String.
|
|
10
|
+
*/
|
|
11
|
+
String: "string",
|
|
12
|
+
/**
|
|
13
|
+
* Number.
|
|
14
|
+
*/
|
|
15
|
+
Number: "number",
|
|
16
|
+
/**
|
|
17
|
+
* Integer.
|
|
18
|
+
*/
|
|
19
|
+
Integer: "integer",
|
|
20
|
+
/**
|
|
21
|
+
* Boolean.
|
|
22
|
+
*/
|
|
23
|
+
Boolean: "boolean",
|
|
24
|
+
/**
|
|
25
|
+
* Array.
|
|
26
|
+
*/
|
|
27
|
+
Array: "array",
|
|
28
|
+
/**
|
|
29
|
+
* Object.
|
|
30
|
+
*/
|
|
31
|
+
Object: "object"
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=entitySchemaPropertyType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitySchemaPropertyType.js","sourceRoot":"","sources":["../../../src/models/entitySchemaPropertyType.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,MAAM,EAAE,QAAQ;IAEhB;;OAEG;IACH,OAAO,EAAE,SAAS;IAElB;;OAEG;IACH,OAAO,EAAE,SAAS;IAElB;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,MAAM,EAAE,QAAQ;CACP,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Definition of the entity property types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const EntitySchemaPropertyType = {\n\t/**\n\t * String.\n\t */\n\tString: \"string\",\n\n\t/**\n\t * Number.\n\t */\n\tNumber: \"number\",\n\n\t/**\n\t * Integer.\n\t */\n\tInteger: \"integer\",\n\n\t/**\n\t * Boolean.\n\t */\n\tBoolean: \"boolean\",\n\n\t/**\n\t * Array.\n\t */\n\tArray: \"array\",\n\n\t/**\n\t * Object.\n\t */\n\tObject: \"object\"\n} as const;\n\n/**\n * Definition of the entity property types.\n */\nexport type EntitySchemaPropertyType =\n\t(typeof EntitySchemaPropertyType)[keyof typeof EntitySchemaPropertyType];\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The logical operators for condition combining.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const LogicalOperator = {
|
|
8
|
+
/**
|
|
9
|
+
* Logical operator AND.
|
|
10
|
+
*/
|
|
11
|
+
And: "and",
|
|
12
|
+
/**
|
|
13
|
+
* Logical operator OR.
|
|
14
|
+
*/
|
|
15
|
+
Or: "or"
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=logicalOperator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logicalOperator.js","sourceRoot":"","sources":["../../../src/models/logicalOperator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B;;OAEG;IACH,GAAG,EAAE,KAAK;IAEV;;OAEG;IACH,EAAE,EAAE,IAAI;CACC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The logical operators for condition combining.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const LogicalOperator = {\n\t/**\n\t * Logical operator AND.\n\t */\n\tAnd: \"and\",\n\n\t/**\n\t * Logical operator OR.\n\t */\n\tOr: \"or\"\n} as const;\n\n/**\n * The logical operators for condition combining.\n */\nexport type LogicalOperator = (typeof LogicalOperator)[keyof typeof LogicalOperator];\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The sort directions.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const SortDirection = {
|
|
8
|
+
/**
|
|
9
|
+
* Ascending.
|
|
10
|
+
*/
|
|
11
|
+
Ascending: "asc",
|
|
12
|
+
/**
|
|
13
|
+
* Descending.
|
|
14
|
+
*/
|
|
15
|
+
Descending: "desc"
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=sortDirection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortDirection.js","sourceRoot":"","sources":["../../../src/models/sortDirection.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B;;OAEG;IACH,SAAS,EAAE,KAAK;IAEhB;;OAEG;IACH,UAAU,EAAE,MAAM;CACT,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The sort directions.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const SortDirection = {\n\t/**\n\t * Ascending.\n\t */\n\tAscending: \"asc\",\n\n\t/**\n\t * Descending.\n\t */\n\tDescending: \"desc\"\n} as const;\n\n/**\n * The sort directions.\n */\nexport type SortDirection = (typeof SortDirection)[keyof typeof SortDirection];\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import "reflect-metadata";
|
|
4
|
+
const META_DATA_KEY = "EntitySchemaMetadata";
|
|
5
|
+
/**
|
|
6
|
+
* Class to help with decorators.
|
|
7
|
+
*/
|
|
8
|
+
export class DecoratorHelper {
|
|
9
|
+
/**
|
|
10
|
+
* Get the schema from the reflection metadata.
|
|
11
|
+
* @param target The object to get the schema data from.
|
|
12
|
+
* @returns The schema from the metadata if it can be found.
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
static getSchema(target) {
|
|
16
|
+
return (Reflect.getMetadata(META_DATA_KEY, typeof target === "object" ? target : target.prototype) ??
|
|
17
|
+
{});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Set the schema from the reflection metadata.
|
|
21
|
+
* @param target The object to get the schema data from.
|
|
22
|
+
* @param entitySchema The schema to set.
|
|
23
|
+
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
static setSchema(target, entitySchema) {
|
|
26
|
+
Reflect.defineMetadata(META_DATA_KEY, entitySchema, typeof target === "object" ? target : target.prototype);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=decoratorHelper.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { ArrayHelper, Is, ObjectHelper } from "@twin.org/core";
|
|
4
|
+
import { ComparisonOperator } from "../models/comparisonOperator.js";
|
|
5
|
+
import { LogicalOperator } from "../models/logicalOperator.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class to perform condition checks.
|
|
8
|
+
*/
|
|
9
|
+
export class EntityConditions {
|
|
10
|
+
/**
|
|
11
|
+
* See if the entity matches the conditions.
|
|
12
|
+
* @param entity The entity to test.
|
|
13
|
+
* @param condition The conditions to test.
|
|
14
|
+
* @returns True if the entity matches.
|
|
15
|
+
*/
|
|
16
|
+
static check(entity, condition) {
|
|
17
|
+
// If no conditions are defined then it's a match
|
|
18
|
+
if (Is.undefined(condition)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if ("conditions" in condition) {
|
|
22
|
+
// It's a group of comparisons, so check the individual items and combine with the logical operator
|
|
23
|
+
const results = condition.conditions.map(c => EntityConditions.check(entity, c));
|
|
24
|
+
if ((condition.logicalOperator ?? LogicalOperator.And) === LogicalOperator.And) {
|
|
25
|
+
return results.every(Boolean);
|
|
26
|
+
}
|
|
27
|
+
return results.some(Boolean);
|
|
28
|
+
}
|
|
29
|
+
if (condition.property.includes(".")) {
|
|
30
|
+
// It's a child property comparison, so evaluate the child property
|
|
31
|
+
// and then compare it to the conditions
|
|
32
|
+
const path = condition.property.split(".");
|
|
33
|
+
const child = ObjectHelper.propertyGet(entity, path[0]);
|
|
34
|
+
// If the child is an array then check each item
|
|
35
|
+
if (Is.array(child)) {
|
|
36
|
+
for (const c of child) {
|
|
37
|
+
const check = EntityConditions.check(c, {
|
|
38
|
+
...condition,
|
|
39
|
+
property: path.slice(1).join(".")
|
|
40
|
+
});
|
|
41
|
+
if (check) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// It's a single value so just check the condition
|
|
49
|
+
return EntityConditions.compare(entity, condition);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* See if the entity matches the conditions.
|
|
53
|
+
* @param entity The entity to test.
|
|
54
|
+
* @param comparator The condition to test.
|
|
55
|
+
* @returns True if the entity matches.
|
|
56
|
+
*/
|
|
57
|
+
static compare(entity, comparator) {
|
|
58
|
+
const val = ObjectHelper.propertyGet(entity, comparator.property);
|
|
59
|
+
const conditionValue = comparator.value;
|
|
60
|
+
if (Is.undefined(conditionValue)) {
|
|
61
|
+
const valUndefined = Is.undefined(val);
|
|
62
|
+
if (valUndefined && comparator.comparison === ComparisonOperator.Equals) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
else if (!valUndefined && comparator.comparison === ComparisonOperator.NotEquals) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
else if (Is.string(val)) {
|
|
71
|
+
if (Is.string(conditionValue)) {
|
|
72
|
+
if (!((comparator.comparison === ComparisonOperator.Equals && val === conditionValue) ||
|
|
73
|
+
(comparator.comparison === ComparisonOperator.NotEquals && val !== conditionValue) ||
|
|
74
|
+
(comparator.comparison === ComparisonOperator.GreaterThan && val > conditionValue) ||
|
|
75
|
+
(comparator.comparison === ComparisonOperator.LessThan && val < conditionValue) ||
|
|
76
|
+
(comparator.comparison === ComparisonOperator.GreaterThanOrEqual &&
|
|
77
|
+
val >= conditionValue) ||
|
|
78
|
+
(comparator.comparison === ComparisonOperator.LessThanOrEqual &&
|
|
79
|
+
val <= conditionValue) ||
|
|
80
|
+
(comparator.comparison === ComparisonOperator.Includes &&
|
|
81
|
+
val.includes(conditionValue)) ||
|
|
82
|
+
(comparator.comparison === ComparisonOperator.NotIncludes &&
|
|
83
|
+
!val.includes(conditionValue)))) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
else if (Is.array(conditionValue)) {
|
|
89
|
+
if (!(comparator.comparison === ComparisonOperator.In && conditionValue.includes(val))) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
else if (Is.number(val)) {
|
|
97
|
+
if (Is.number(conditionValue)) {
|
|
98
|
+
if (!((comparator.comparison === ComparisonOperator.Equals && val === conditionValue) ||
|
|
99
|
+
(comparator.comparison === ComparisonOperator.NotEquals && val !== conditionValue) ||
|
|
100
|
+
(comparator.comparison === ComparisonOperator.GreaterThan && val > conditionValue) ||
|
|
101
|
+
(comparator.comparison === ComparisonOperator.LessThan && val < conditionValue) ||
|
|
102
|
+
(comparator.comparison === ComparisonOperator.GreaterThanOrEqual &&
|
|
103
|
+
val >= conditionValue) ||
|
|
104
|
+
(comparator.comparison === ComparisonOperator.LessThanOrEqual && val <= conditionValue))) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
else if (Is.array(conditionValue)) {
|
|
110
|
+
if (!(comparator.comparison === ComparisonOperator.In && conditionValue.includes(val))) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
else if (Is.boolean(val)) {
|
|
118
|
+
if (Is.boolean(conditionValue)) {
|
|
119
|
+
if (!((comparator.comparison === ComparisonOperator.Equals && val === conditionValue) ||
|
|
120
|
+
(comparator.comparison === ComparisonOperator.NotEquals && val !== conditionValue))) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
else if (Is.array(val)) {
|
|
128
|
+
if (Is.array(conditionValue)) {
|
|
129
|
+
if (comparator.comparison === ComparisonOperator.Equals ||
|
|
130
|
+
comparator.comparison === ComparisonOperator.NotEquals) {
|
|
131
|
+
const matches = ArrayHelper.matches(val, conditionValue);
|
|
132
|
+
if (!((comparator.comparison === ComparisonOperator.Equals && matches) ||
|
|
133
|
+
(comparator.comparison === ComparisonOperator.NotEquals && !matches))) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
else if (Is.number(conditionValue) || Is.string(conditionValue)) {
|
|
141
|
+
if (comparator.comparison === ComparisonOperator.Includes ||
|
|
142
|
+
comparator.comparison === ComparisonOperator.NotIncludes ||
|
|
143
|
+
comparator.comparison === ComparisonOperator.In) {
|
|
144
|
+
const includes = val.includes(conditionValue);
|
|
145
|
+
if (!((comparator.comparison === ComparisonOperator.Includes && includes) ||
|
|
146
|
+
(comparator.comparison === ComparisonOperator.NotIncludes && !includes) ||
|
|
147
|
+
(comparator.comparison === ComparisonOperator.In && includes))) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
else if (Is.object(conditionValue)) {
|
|
155
|
+
if (comparator.comparison === ComparisonOperator.Includes) {
|
|
156
|
+
for (const v of val) {
|
|
157
|
+
if (ObjectHelper.equal(v, conditionValue)) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (comparator.comparison === ComparisonOperator.NotIncludes) {
|
|
163
|
+
for (const v of val) {
|
|
164
|
+
if (!ObjectHelper.equal(v, conditionValue)) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=entityConditions.js.map
|