@intellegens/cornerstone-client 0.0.0-experimental-upgrade-20260302-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.
- package/README.md +256 -0
- package/demo/index.ts +29 -0
- package/demo/public_html/favicon.ico +0 -0
- package/demo/public_html/index.html +106 -0
- package/demo/public_html/websettings.json +3 -0
- package/dist/adapters/CollectionViewAdapter/index.d.ts +198 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.d.ts +1 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.js +163 -0
- package/dist/adapters/CollectionViewAdapter/index.js +381 -0
- package/dist/adapters/SearchAdapter/index.d.ts +55 -0
- package/dist/adapters/SearchAdapter/index.js +233 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +2 -0
- package/dist/data/api/dto/PropertyPathDto.d.ts +4 -0
- package/dist/data/api/dto/PropertyPathDto.js +1 -0
- package/dist/data/api/dto/ReadOptionsDto.d.ts +8 -0
- package/dist/data/api/dto/ReadOptionsDto.js +1 -0
- package/dist/data/api/dto/ReadResultDto.d.ts +12 -0
- package/dist/data/api/dto/ReadResultDto.js +1 -0
- package/dist/data/api/dto/ReadResultMetadataDto.d.ts +8 -0
- package/dist/data/api/dto/ReadResultMetadataDto.js +1 -0
- package/dist/data/api/dto/crud/CrudMetadataDto.d.ts +4 -0
- package/dist/data/api/dto/crud/CrudMetadataDto.js +1 -0
- package/dist/data/api/dto/crud/index.d.ts +1 -0
- package/dist/data/api/dto/crud/index.js +1 -0
- package/dist/data/api/dto/index.d.ts +4 -0
- package/dist/data/api/dto/index.js +4 -0
- package/dist/data/api/dto/read/ReadMetadataDto.d.ts +8 -0
- package/dist/data/api/dto/read/ReadMetadataDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedDefinitionDto.d.ts +18 -0
- package/dist/data/api/dto/read/ReadSelectedDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +22 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +18 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +14 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.d.ts +13 -0
- package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.d.ts +167 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.js +267 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +33 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +114 -0
- package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/index.d.ts +10 -0
- package/dist/data/api/dto/read/index.js +10 -0
- package/dist/data/api/dto/response/ApiErrorDto.d.ts +17 -0
- package/dist/data/api/dto/response/ApiErrorDto.js +1 -0
- package/dist/data/api/dto/response/ApiErrorResponseDto.d.ts +11 -0
- package/dist/data/api/dto/response/ApiErrorResponseDto.js +1 -0
- package/dist/data/api/dto/response/ApiResponseDto.d.ts +3 -0
- package/dist/data/api/dto/response/ApiResponseDto.js +1 -0
- package/dist/data/api/dto/response/ApiSuccessResponseDto.d.ts +13 -0
- package/dist/data/api/dto/response/ApiSuccessResponseDto.js +1 -0
- package/dist/data/api/dto/response/EmptyMetadataDto.d.ts +4 -0
- package/dist/data/api/dto/response/EmptyMetadataDto.js +1 -0
- package/dist/data/api/dto/response/MetadataDto.d.ts +25 -0
- package/dist/data/api/dto/response/MetadataDto.js +1 -0
- package/dist/data/api/dto/response/index.d.ts +5 -0
- package/dist/data/api/dto/response/index.js +5 -0
- package/dist/data/api/enum/index.d.ts +2 -0
- package/dist/data/api/enum/index.js +2 -0
- package/dist/data/api/enum/read/ReadSelectedCollectionOperator.d.ts +16 -0
- package/dist/data/api/enum/read/ReadSelectedCollectionOperator.js +17 -0
- package/dist/data/api/enum/read/ReadSelectedComparisonOperator.d.ts +69 -0
- package/dist/data/api/enum/read/ReadSelectedComparisonOperator.js +76 -0
- package/dist/data/api/enum/read/ReadSelectedLogicalOperator.d.ts +15 -0
- package/dist/data/api/enum/read/ReadSelectedLogicalOperator.js +16 -0
- package/dist/data/api/enum/read/ReadSelectedOrderingDirection.d.ts +13 -0
- package/dist/data/api/enum/read/ReadSelectedOrderingDirection.js +14 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.d.ts +66 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.js +75 -0
- package/dist/data/api/enum/read/index.d.ts +5 -0
- package/dist/data/api/enum/read/index.js +5 -0
- package/dist/data/api/enum/response/ApiErrorCodes.d.ts +7 -0
- package/dist/data/api/enum/response/ApiErrorCodes.js +8 -0
- package/dist/data/api/enum/response/ErrorCode.d.ts +13 -0
- package/dist/data/api/enum/response/ErrorCode.js +14 -0
- package/dist/data/api/enum/response/index.d.ts +1 -0
- package/dist/data/api/enum/response/index.js +1 -0
- package/dist/data/api/index.d.ts +3 -0
- package/dist/data/api/index.js +3 -0
- package/dist/data/api/interface/ICommonIdentifiable.d.ts +7 -0
- package/dist/data/api/interface/ICommonIdentifiable.js +1 -0
- package/dist/data/api/interface/IConcurrencySafe.d.ts +9 -0
- package/dist/data/api/interface/IConcurrencySafe.js +2 -0
- package/dist/data/api/interface/IIdentifiable.d.ts +11 -0
- package/dist/data/api/interface/IIdentifiable.js +1 -0
- package/dist/data/api/interface/IIdentifiableSecondary.d.ts +9 -0
- package/dist/data/api/interface/IIdentifiableSecondary.js +1 -0
- package/dist/data/api/interface/index.d.ts +3 -0
- package/dist/data/api/interface/index.js +3 -0
- package/dist/data/auth/dto/ClaimDto.d.ts +4 -0
- package/dist/data/auth/dto/ClaimDto.js +1 -0
- package/dist/data/auth/dto/RegisterRequestDto.d.ts +4 -0
- package/dist/data/auth/dto/RegisterRequestDto.js +1 -0
- package/dist/data/auth/dto/RoleDto.d.ts +5 -0
- package/dist/data/auth/dto/RoleDto.js +1 -0
- package/dist/data/auth/dto/SignInRequestDto.d.ts +4 -0
- package/dist/data/auth/dto/SignInRequestDto.js +1 -0
- package/dist/data/auth/dto/TokensDto.d.ts +4 -0
- package/dist/data/auth/dto/TokensDto.js +1 -0
- package/dist/data/auth/dto/UserDto.d.ts +17 -0
- package/dist/data/auth/dto/UserDto.js +1 -0
- package/dist/data/auth/dto/UserInfoDto.d.ts +14 -0
- package/dist/data/auth/dto/UserInfoDto.js +1 -0
- package/dist/data/auth/dto/index.d.ts +5 -0
- package/dist/data/auth/dto/index.js +5 -0
- package/dist/data/auth/index.d.ts +2 -0
- package/dist/data/auth/index.js +2 -0
- package/dist/data/auth/policy.d.ts +52 -0
- package/dist/data/auth/policy.js +44 -0
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/services/api/ApiCrudControllerClient/index.d.ts +41 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.js +34 -0
- package/dist/services/api/ApiCrudControllerClient/index.js +116 -0
- package/dist/services/api/ApiInitializationService/index.d.ts +106 -0
- package/dist/services/api/ApiInitializationService/index.js +208 -0
- package/dist/services/api/ApiReadControllerClient/index.d.ts +40 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.js +59 -0
- package/dist/services/api/ApiReadControllerClient/index.js +111 -0
- package/dist/services/api/HttpService/FetchHttpService.d.ts +7 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.d.ts +1 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.js +52 -0
- package/dist/services/api/HttpService/FetchHttpService.js +29 -0
- package/dist/services/api/HttpService/HttpRequestConfig.d.ts +10 -0
- package/dist/services/api/HttpService/HttpRequestConfig.js +1 -0
- package/dist/services/api/HttpService/HttpResponse.d.ts +11 -0
- package/dist/services/api/HttpService/HttpResponse.js +3 -0
- package/dist/services/api/HttpService/IHttpService.d.ts +13 -0
- package/dist/services/api/HttpService/IHttpService.js +3 -0
- package/dist/services/api/HttpService/index.d.ts +9 -0
- package/dist/services/api/HttpService/index.js +10 -0
- package/dist/services/api/UserManagementControllerClient/index.d.ts +41 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.js +60 -0
- package/dist/services/api/UserManagementControllerClient/index.js +117 -0
- package/dist/services/api/index.d.ts +5 -0
- package/dist/services/api/index.js +5 -0
- package/dist/services/auth/client/AuthService/index.d.ts +75 -0
- package/dist/services/auth/client/AuthService/index.js +200 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +48 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.js +89 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.js +148 -0
- package/dist/services/auth/client/index.d.ts +2 -0
- package/dist/services/auth/client/index.js +2 -0
- package/dist/services/auth/index.d.ts +1 -0
- package/dist/services/auth/index.js +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/utils/authorization/index.d.ts +17 -0
- package/dist/utils/authorization/index.js +45 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/result/index.d.ts +21 -0
- package/dist/utils/result/index.js +16 -0
- package/dist/utils/search/index.d.ts +34 -0
- package/dist/utils/search/index.js +106 -0
- package/package.json +45 -0
- package/src/adapters/CollectionViewAdapter/index.integration.test.ts +197 -0
- package/src/adapters/CollectionViewAdapter/index.ts +477 -0
- package/src/adapters/SearchAdapter/index.ts +302 -0
- package/src/adapters/index.ts +2 -0
- package/src/data/api/dto/PropertyPathDto.ts +4 -0
- package/src/data/api/dto/ReadOptionsDto.ts +8 -0
- package/src/data/api/dto/ReadResultDto.ts +13 -0
- package/src/data/api/dto/ReadResultMetadataDto.ts +8 -0
- package/src/data/api/dto/crud/CrudMetadataDto.ts +4 -0
- package/src/data/api/dto/crud/index.ts +1 -0
- package/src/data/api/dto/index.ts +4 -0
- package/src/data/api/dto/read/ReadMetadataDto.ts +8 -0
- package/src/data/api/dto/read/ReadSelectedDefinitionDto.ts +21 -0
- package/src/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.ts +25 -0
- package/src/data/api/dto/read/ReadSelectedNestedCriteriaDto.ts +20 -0
- package/src/data/api/dto/read/ReadSelectedOrderingDefinitionDto.ts +8 -0
- package/src/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.ts +16 -0
- package/src/data/api/dto/read/ReadSelectedPaginationDefinitionDto.ts +13 -0
- package/src/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.ts +348 -0
- package/src/data/api/dto/read/ReadSelectedSearchDefinitionDto.ts +43 -0
- package/src/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.ts +186 -0
- package/src/data/api/dto/read/index.ts +10 -0
- package/src/data/api/dto/response/ApiErrorDto.ts +21 -0
- package/src/data/api/dto/response/ApiErrorResponseDto.ts +13 -0
- package/src/data/api/dto/response/ApiResponseDto.ts +7 -0
- package/src/data/api/dto/response/ApiSuccessResponseDto.ts +13 -0
- package/src/data/api/dto/response/MetadataDto.ts +24 -0
- package/src/data/api/dto/response/index.ts +5 -0
- package/src/data/api/enum/index.ts +2 -0
- package/src/data/api/enum/read/ReadSelectedCollectionOperator.ts +17 -0
- package/src/data/api/enum/read/ReadSelectedComparisonOperator.ts +96 -0
- package/src/data/api/enum/read/ReadSelectedLogicalOperator.ts +16 -0
- package/src/data/api/enum/read/ReadSelectedOrderingDirection.ts +13 -0
- package/src/data/api/enum/read/ReadSelectedPropertyType.ts +96 -0
- package/src/data/api/enum/read/index.ts +5 -0
- package/src/data/api/enum/response/ErrorCode.ts +13 -0
- package/src/data/api/enum/response/index.ts +1 -0
- package/src/data/api/index.ts +3 -0
- package/src/data/api/interface/ICommonIdentifiable.ts +9 -0
- package/src/data/api/interface/IConcurrencySafe.ts +9 -0
- package/src/data/api/interface/IIdentifiable.ts +12 -0
- package/src/data/api/interface/IIdentifiableSecondary.ts +9 -0
- package/src/data/api/interface/index.ts +3 -0
- package/src/data/auth/dto/ClaimDto.ts +4 -0
- package/src/data/auth/dto/RegisterRequestDto.ts +4 -0
- package/src/data/auth/dto/RoleDto.ts +6 -0
- package/src/data/auth/dto/SignInRequestDto.ts +4 -0
- package/src/data/auth/dto/TokensDto.ts +4 -0
- package/src/data/auth/dto/UserDto.ts +18 -0
- package/src/data/auth/dto/UserInfoDto.ts +15 -0
- package/src/data/auth/dto/index.ts +5 -0
- package/src/data/auth/index.ts +2 -0
- package/src/data/auth/policy.ts +63 -0
- package/src/data/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/services/api/ApiCrudControllerClient/index.integration.test.ts +46 -0
- package/src/services/api/ApiCrudControllerClient/index.ts +135 -0
- package/src/services/api/ApiInitializationService/index.ts +254 -0
- package/src/services/api/ApiReadControllerClient/index.integration.test.ts +71 -0
- package/src/services/api/ApiReadControllerClient/index.ts +137 -0
- package/src/services/api/HttpService/FetchHttpService.integration.test.ts +65 -0
- package/src/services/api/HttpService/FetchHttpService.ts +34 -0
- package/src/services/api/HttpService/HttpRequestConfig.ts +10 -0
- package/src/services/api/HttpService/HttpResponse.ts +14 -0
- package/src/services/api/HttpService/IHttpService.ts +17 -0
- package/src/services/api/HttpService/README.md +106 -0
- package/src/services/api/HttpService/index.ts +12 -0
- package/src/services/api/UserManagementControllerClient/index.integration.test.ts +69 -0
- package/src/services/api/UserManagementControllerClient/index.ts +134 -0
- package/src/services/api/index.ts +5 -0
- package/src/services/auth/client/AuthService/index.ts +233 -0
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.ts +110 -0
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.ts +165 -0
- package/src/services/auth/client/index.ts +2 -0
- package/src/services/auth/index.ts +1 -0
- package/src/services/index.ts +2 -0
- package/src/utils/authorization/index.ts +47 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/result/index.ts +25 -0
- package/src/utils/search/index.ts +150 -0
- package/tsconfig.json +19 -0
- package/vitest-setup.ts +43 -0
- package/vitest.config.ts +59 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ReadSelectedComparisonOperator, ReadSelectedLogicalOperator, ReadSelectedPropertyType, } from '../../data';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a ReadSelectedSearchDefinitionDto ready to be used with the CollectionViewAdapter
|
|
4
|
+
*
|
|
5
|
+
* @param logicalOperator - specify `ReadSelectedLogicalOperator` that will apply to all ReadSelectedSearchPropertyDefinitionDto property definitions included in this search definition
|
|
6
|
+
* @param conditions - Variable number of condition objects containing:
|
|
7
|
+
* - propertyName: The property name from the DTO to search on
|
|
8
|
+
* - operator: The `ReadSelectedComparisonOperator` enum
|
|
9
|
+
* - value: The value to compare against
|
|
10
|
+
* - valueType: The `ReadSelectedPropertyType` being compared
|
|
11
|
+
*/
|
|
12
|
+
export function condition(logicalOperator, ...conditions) {
|
|
13
|
+
return {
|
|
14
|
+
logicalOperator: logicalOperator,
|
|
15
|
+
propertyCriteria: conditions.map(condition => ({
|
|
16
|
+
propertyName: toPascalCase(condition.propertyName),
|
|
17
|
+
comparisonOperator: condition.operator,
|
|
18
|
+
valueType: condition.valueType,
|
|
19
|
+
value: condition.value,
|
|
20
|
+
})),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Combines multiple ReadSelectedSearchDefinitionDto with AND logic
|
|
25
|
+
*/
|
|
26
|
+
export function and(...definitions) {
|
|
27
|
+
return {
|
|
28
|
+
logicalOperator: ReadSelectedLogicalOperator.And,
|
|
29
|
+
searches: definitions,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Combines multiple ReadSelectedSearchDefinitionDto with OR logic
|
|
34
|
+
*/
|
|
35
|
+
export function or(...definitions) {
|
|
36
|
+
return {
|
|
37
|
+
logicalOperator: ReadSelectedLogicalOperator.Or,
|
|
38
|
+
searches: definitions,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Preset implementation for filtering by searchTerm. String types will search by provided `textSearchableProperties` with `ReadSelectedComparisonOperator.Contains`. Numeric types will search by provided `numericSearchableProperties`, `parseInt` the search term and use `ReadSelectedComparisonOperator.Equal`.
|
|
43
|
+
*/
|
|
44
|
+
export function searchTerm(searchTerm, textSearchableProperties, numericSearchableProperties) {
|
|
45
|
+
let comparisonOperator;
|
|
46
|
+
let valueType;
|
|
47
|
+
let searchableProperties;
|
|
48
|
+
let searchValue;
|
|
49
|
+
try {
|
|
50
|
+
const numericValue = parseInt(searchTerm);
|
|
51
|
+
if (!Number.isNaN(numericValue) && String(numericValue) === searchTerm.trim()) {
|
|
52
|
+
comparisonOperator = ReadSelectedComparisonOperator.Equal;
|
|
53
|
+
valueType = ReadSelectedPropertyType.Int;
|
|
54
|
+
searchableProperties = numericSearchableProperties;
|
|
55
|
+
searchValue = numericValue;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
comparisonOperator = ReadSelectedComparisonOperator.Contains;
|
|
59
|
+
valueType = ReadSelectedPropertyType.String;
|
|
60
|
+
searchableProperties = textSearchableProperties;
|
|
61
|
+
searchValue = searchTerm;
|
|
62
|
+
}
|
|
63
|
+
const searchConditions = searchableProperties.map(propertyName => ({
|
|
64
|
+
propertyName: toPascalCase(propertyName),
|
|
65
|
+
operator: comparisonOperator,
|
|
66
|
+
value: searchValue,
|
|
67
|
+
valueType: valueType,
|
|
68
|
+
}));
|
|
69
|
+
return condition(ReadSelectedLogicalOperator.Or, ...searchConditions);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Preset implementation for filtering a date range. User may select desired `ReadSelectedComparisonOperator` and `ReadSelectedPropertyType` for the from and to dates. Valid object property must be provided for `searchableProperty`.
|
|
77
|
+
*/
|
|
78
|
+
export function dateInterval(fromDate, toDate, fromDateComparisonOperator, toDateComparisonOperator, valueType, searchableProperty) {
|
|
79
|
+
try {
|
|
80
|
+
if (!(valueType === ReadSelectedPropertyType.DateOnly ||
|
|
81
|
+
valueType === ReadSelectedPropertyType.DateTime ||
|
|
82
|
+
valueType === ReadSelectedPropertyType.DateTimeOffset)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
return condition(ReadSelectedLogicalOperator.And, {
|
|
86
|
+
propertyName: toPascalCase(searchableProperty),
|
|
87
|
+
operator: fromDateComparisonOperator,
|
|
88
|
+
value: fromDate,
|
|
89
|
+
valueType: valueType,
|
|
90
|
+
}, {
|
|
91
|
+
propertyName: toPascalCase(searchableProperty),
|
|
92
|
+
operator: toDateComparisonOperator,
|
|
93
|
+
value: toDate,
|
|
94
|
+
valueType: valueType,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function toPascalCase(str) {
|
|
102
|
+
if (typeof str !== 'string') {
|
|
103
|
+
return str;
|
|
104
|
+
}
|
|
105
|
+
return (str.charAt(0).toUpperCase() + str.slice(1));
|
|
106
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@intellegens/cornerstone-client",
|
|
3
|
+
"version": "0.0.0-experimental-upgrade-20260302-1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishable": true,
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"author": "Intellegens",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"description": "",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"intellegens",
|
|
14
|
+
"cornerstone"
|
|
15
|
+
],
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@eslint/js": "^10.0.1",
|
|
18
|
+
"@types/express": "^5.0.6",
|
|
19
|
+
"@types/node": "^25.3.1",
|
|
20
|
+
"eslint": "^10.0.2",
|
|
21
|
+
"eslint-config-prettier": "^10.1.8",
|
|
22
|
+
"express": "^5.2.1",
|
|
23
|
+
"globals": "^17.3.0",
|
|
24
|
+
"prettier": "^3.8.1",
|
|
25
|
+
"rxjs": "~7.8.2",
|
|
26
|
+
"tsc-alias": "^1.8.16",
|
|
27
|
+
"typescript-eslint": "^8.56.1",
|
|
28
|
+
"vite": "7.3.1",
|
|
29
|
+
"vitest": "^4.0.18",
|
|
30
|
+
"zod": "^3.25.76"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"http-proxy-middleware": "^3.0.5",
|
|
34
|
+
"typescript": "~5.9.3"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"clean": "pnpx rimraf '{dist}'",
|
|
38
|
+
"test": "vitest run --passWithNoTests",
|
|
39
|
+
"test:unit": "vitest run --project unit --passWithNoTests",
|
|
40
|
+
"test:integration": "vitest run --project integration --passWithNoTests",
|
|
41
|
+
"coverage": "vitest run --coverage",
|
|
42
|
+
"build": "pnpm run clean && tsc && tsc-alias",
|
|
43
|
+
"start": "pnpm run build && pnpx vite build && pnpx tsx ./demo"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { CollectionViewAdapter, CollectionViewAdapterOptions } from '.';
|
|
3
|
+
import { ReadSelectedComparisonOperator, ReadSelectedOrderingDirection, ReadSelectedPropertyType } from '@/data';
|
|
4
|
+
import { dateInterval, searchTerm } from '@/utils';
|
|
5
|
+
|
|
6
|
+
type TestDto = { id: number; name: string; dateOfBirth: string; rowVersion: string };
|
|
7
|
+
|
|
8
|
+
describe('CollectionViewAdapter', () => {
|
|
9
|
+
let data: TestDto[] | undefined;
|
|
10
|
+
let error: string | undefined;
|
|
11
|
+
let isLoading: boolean | undefined;
|
|
12
|
+
|
|
13
|
+
const callback = vi.fn((_isLoading: boolean, _data: TestDto[] | undefined, _error: string | undefined) => {
|
|
14
|
+
isLoading = _isLoading;
|
|
15
|
+
data = _data;
|
|
16
|
+
error = _error;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const options: CollectionViewAdapterOptions<TestDto> = {
|
|
20
|
+
pagination: { useTotalItemCount: true, pageSize: 5, pageNumber: 1 },
|
|
21
|
+
ordering: { maxActiveOrderingColumns: 1, orderByPaths: [] },
|
|
22
|
+
search: { textSearchableProperties: ['name'], numericSearchableProperties: ['id'] },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let adapter: CollectionViewAdapter<number, TestDto, TestDto>;
|
|
26
|
+
|
|
27
|
+
const waitForData = async (timeout = 2000) => {
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
while (isLoading !== false && Date.now() - start < timeout) {
|
|
30
|
+
await new Promise(res => setTimeout(res, 50));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const resetAdapterState = () => {
|
|
35
|
+
data = undefined;
|
|
36
|
+
error = undefined;
|
|
37
|
+
isLoading = undefined;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
data = undefined;
|
|
42
|
+
error = undefined;
|
|
43
|
+
isLoading = undefined;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('callback returns correct loading status and collection data', async () => {
|
|
47
|
+
options.pagination.useTotalItemCount = true;
|
|
48
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
49
|
+
await waitForData();
|
|
50
|
+
|
|
51
|
+
expect(callback).toHaveBeenNthCalledWith(1, true, undefined, undefined);
|
|
52
|
+
expect(callback).toHaveBeenLastCalledWith(false, data, undefined);
|
|
53
|
+
expect(data).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('adapter options set correct ordering', async () => {
|
|
57
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
58
|
+
await waitForData();
|
|
59
|
+
resetAdapterState();
|
|
60
|
+
adapter.setOrdering(['name'], ReadSelectedOrderingDirection.Descending);
|
|
61
|
+
await waitForData();
|
|
62
|
+
|
|
63
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
64
|
+
{
|
|
65
|
+
orderByPath: ['name'],
|
|
66
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('text search is applied to adapter', async () => {
|
|
72
|
+
const searchDefinition = searchTerm('Flu', ['name'], ['id']);
|
|
73
|
+
if (!searchDefinition) throw new Error('searchDefinition is undefined');
|
|
74
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
75
|
+
await waitForData();
|
|
76
|
+
resetAdapterState();
|
|
77
|
+
adapter.setSearchDefinition(searchDefinition);
|
|
78
|
+
await waitForData();
|
|
79
|
+
|
|
80
|
+
expect(data).toBeDefined();
|
|
81
|
+
expect(data!.length).toBeGreaterThan(0);
|
|
82
|
+
for (const item of data!) {
|
|
83
|
+
expect(item.name).toMatch(/flu/i);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('numeric search is applied to adapter', async () => {
|
|
88
|
+
const searchDefinition = searchTerm('10000001', ['id'], ['id']);
|
|
89
|
+
if (!searchDefinition) throw new Error('searchDefinition is undefined');
|
|
90
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
91
|
+
await waitForData();
|
|
92
|
+
resetAdapterState();
|
|
93
|
+
adapter.setSearchDefinition(searchDefinition);
|
|
94
|
+
await waitForData();
|
|
95
|
+
|
|
96
|
+
expect(data).toBeDefined();
|
|
97
|
+
expect(data!.length).toBe(1);
|
|
98
|
+
for (const item of data!) {
|
|
99
|
+
expect(item.id).toBe(10000001);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('applies date range filter from-to on the same date type property', async () => {
|
|
104
|
+
adapter = new CollectionViewAdapter('PetsSlim', callback, options);
|
|
105
|
+
const from = new Date('2017-01-01T00:00:00.000Z');
|
|
106
|
+
const to = new Date('2017-12-31T00:00:00.000Z');
|
|
107
|
+
|
|
108
|
+
const searchDefinition = dateInterval<TestDto>(
|
|
109
|
+
from,
|
|
110
|
+
to,
|
|
111
|
+
ReadSelectedComparisonOperator.GreaterOrEqual,
|
|
112
|
+
ReadSelectedComparisonOperator.LessOrEqual,
|
|
113
|
+
ReadSelectedPropertyType.DateOnly,
|
|
114
|
+
'dateOfBirth',
|
|
115
|
+
);
|
|
116
|
+
if (!searchDefinition) throw new Error('searchDefinition is undefined');
|
|
117
|
+
await waitForData();
|
|
118
|
+
resetAdapterState();
|
|
119
|
+
adapter.setSearchDefinition(searchDefinition);
|
|
120
|
+
await waitForData();
|
|
121
|
+
|
|
122
|
+
expect(data).toBeDefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('applies pagination: page size and jump to page set skip/limit', async () => {
|
|
126
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
127
|
+
await waitForData();
|
|
128
|
+
const firstPageData = data;
|
|
129
|
+
resetAdapterState();
|
|
130
|
+
adapter.jumpToPage(3);
|
|
131
|
+
await waitForData();
|
|
132
|
+
|
|
133
|
+
expect(data).toBeDefined();
|
|
134
|
+
expect(data!.length).toBe(5);
|
|
135
|
+
// Check that data is different from first page
|
|
136
|
+
expect(data).not.toEqual(firstPageData);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('calculates total when useTotalItemCount=false and last page is partial', async () => {
|
|
140
|
+
options.pagination.useTotalItemCount = false;
|
|
141
|
+
options.pagination.pageSize = 10;
|
|
142
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
143
|
+
await waitForData();
|
|
144
|
+
const firstPageData = data;
|
|
145
|
+
resetAdapterState();
|
|
146
|
+
adapter.jumpToPage(2);
|
|
147
|
+
await waitForData();
|
|
148
|
+
|
|
149
|
+
expect(adapter.totalItemCount).toBe(firstPageData!.length + data!.length);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('setOrdering correctly handles PropertyPathDto array comparison and limits columns', async () => {
|
|
153
|
+
options.ordering.maxActiveOrderingColumns = 2;
|
|
154
|
+
// Add first ordering
|
|
155
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
156
|
+
adapter.setOrdering(['name'], ReadSelectedOrderingDirection.Descending);
|
|
157
|
+
await waitForData();
|
|
158
|
+
|
|
159
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
160
|
+
{
|
|
161
|
+
orderByPath: ['name'],
|
|
162
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
163
|
+
},
|
|
164
|
+
]);
|
|
165
|
+
|
|
166
|
+
// Add second ordering
|
|
167
|
+
adapter.setOrdering(['id'], ReadSelectedOrderingDirection.Ascending);
|
|
168
|
+
await waitForData();
|
|
169
|
+
|
|
170
|
+
// Should have both orderings, with 'id' first (most recent)
|
|
171
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
172
|
+
{
|
|
173
|
+
orderByPath: ['id'],
|
|
174
|
+
orderDirection: ReadSelectedOrderingDirection.Ascending,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
orderByPath: ['name'],
|
|
178
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
179
|
+
},
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
// // Add third ordering - should remove the oldest one (name)
|
|
183
|
+
adapter.setOrdering(['description'], ReadSelectedOrderingDirection.Descending);
|
|
184
|
+
await waitForData();
|
|
185
|
+
|
|
186
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
187
|
+
{
|
|
188
|
+
orderByPath: ['description'],
|
|
189
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
orderByPath: ['id'],
|
|
193
|
+
orderDirection: ReadSelectedOrderingDirection.Ascending,
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
});
|
|
197
|
+
});
|