@intellegens/cornerstone-client 0.0.9999-alpha-8 → 0.0.9999-alpha-10

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 (227) hide show
  1. package/demo/index.ts +29 -0
  2. package/demo/public_html/favicon.ico +0 -0
  3. package/demo/public_html/index.html +106 -0
  4. package/demo/public_html/websettings.json +3 -0
  5. package/{adapters → dist/adapters}/CollectionViewAdapter/index.d.ts +0 -0
  6. package/{adapters → dist/adapters}/CollectionViewAdapter/index.js +0 -0
  7. package/{adapters → dist/adapters}/index.d.ts +0 -0
  8. package/{adapters → dist/adapters}/index.js +0 -0
  9. package/{data → dist/data}/api/dto/PropertyPathDto.d.ts +0 -0
  10. package/{data → dist/data}/api/dto/PropertyPathDto.js +0 -0
  11. package/{data → dist/data}/api/dto/ReadOptionsDto.d.ts +0 -0
  12. package/{data → dist/data}/api/dto/ReadOptionsDto.js +0 -0
  13. package/{data → dist/data}/api/dto/ReadResultDto.d.ts +0 -0
  14. package/{data → dist/data}/api/dto/ReadResultDto.js +0 -0
  15. package/{data → dist/data}/api/dto/ReadResultMetadataDto.d.ts +0 -0
  16. package/{data → dist/data}/api/dto/ReadResultMetadataDto.js +0 -0
  17. package/{data → dist/data}/api/dto/crud/CrudMetadataDto.d.ts +0 -0
  18. package/{data → dist/data}/api/dto/crud/CrudMetadataDto.js +0 -0
  19. package/{data → dist/data}/api/dto/crud/index.d.ts +0 -0
  20. package/{data → dist/data}/api/dto/crud/index.js +0 -0
  21. package/{data → dist/data}/api/dto/index.d.ts +0 -0
  22. package/{data → dist/data}/api/dto/index.js +0 -0
  23. package/{data → dist/data}/api/dto/read/ReadMetadataDto.d.ts +0 -0
  24. package/{data → dist/data}/api/dto/read/ReadMetadataDto.js +0 -0
  25. package/{data → dist/data}/api/dto/read/ReadSelectedDefinitionDto.d.ts +0 -0
  26. package/{data → dist/data}/api/dto/read/ReadSelectedDefinitionDto.js +0 -0
  27. package/{data → dist/data}/api/dto/read/ReadSelectedOrderingDefinitionDto.d.ts +0 -0
  28. package/{data → dist/data}/api/dto/read/ReadSelectedOrderingDefinitionDto.js +0 -0
  29. package/{data → dist/data}/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +0 -0
  30. package/{data → dist/data}/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.js +0 -0
  31. package/{data → dist/data}/api/dto/read/ReadSelectedPaginationDefinitionDto.d.ts +0 -0
  32. package/{data → dist/data}/api/dto/read/ReadSelectedPaginationDefinitionDto.js +0 -0
  33. package/{data → dist/data}/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +0 -0
  34. package/{data → dist/data}/api/dto/read/ReadSelectedSearchDefinitionDto.js +0 -0
  35. package/{data → dist/data}/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +0 -0
  36. package/{data → dist/data}/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.js +0 -0
  37. package/{data → dist/data}/api/dto/read/index.d.ts +0 -0
  38. package/{data → dist/data}/api/dto/read/index.js +0 -0
  39. package/{data → dist/data}/api/dto/response/ApiErrorDto.d.ts +0 -0
  40. package/{data → dist/data}/api/dto/response/ApiErrorDto.js +0 -0
  41. package/{data → dist/data}/api/dto/response/ApiResponseDto.d.ts +0 -0
  42. package/{data → dist/data}/api/dto/response/ApiResponseDto.js +0 -0
  43. package/{data → dist/data}/api/dto/response/ApiSuccessResponseDto.d.ts +0 -0
  44. package/{data → dist/data}/api/dto/response/ApiSuccessResponseDto.js +0 -0
  45. package/{data → dist/data}/api/dto/response/EmptyMetadataDto.d.ts +0 -0
  46. package/{data → dist/data}/api/dto/response/EmptyMetadataDto.js +0 -0
  47. package/{data → dist/data}/api/dto/response/index.d.ts +0 -0
  48. package/{data → dist/data}/api/dto/response/index.js +0 -0
  49. package/{data → dist/data}/api/enum/index.d.ts +0 -0
  50. package/{data → dist/data}/api/enum/index.js +0 -0
  51. package/{data → dist/data}/api/enum/read/ReadSelectedComparisonOperator.d.ts +0 -0
  52. package/{data → dist/data}/api/enum/read/ReadSelectedComparisonOperator.js +0 -0
  53. package/{data → dist/data}/api/enum/read/ReadSelectedLogicalOperator.d.ts +0 -0
  54. package/{data → dist/data}/api/enum/read/ReadSelectedLogicalOperator.js +0 -0
  55. package/{data → dist/data}/api/enum/read/ReadSelectedOrderingDirection.d.ts +0 -0
  56. package/{data → dist/data}/api/enum/read/ReadSelectedOrderingDirection.js +0 -0
  57. package/{data → dist/data}/api/enum/read/ReadSelectedPropertyType.d.ts +0 -0
  58. package/{data → dist/data}/api/enum/read/ReadSelectedPropertyType.js +0 -0
  59. package/{data → dist/data}/api/enum/read/index.d.ts +0 -0
  60. package/{data → dist/data}/api/enum/read/index.js +0 -0
  61. package/{data → dist/data}/api/enum/response/ApiErrorCodes.d.ts +0 -0
  62. package/{data → dist/data}/api/enum/response/ApiErrorCodes.js +0 -0
  63. package/{data → dist/data}/api/enum/response/index.d.ts +0 -0
  64. package/{data → dist/data}/api/enum/response/index.js +0 -0
  65. package/{data → dist/data}/api/index.d.ts +0 -0
  66. package/{data → dist/data}/api/index.js +0 -0
  67. package/{data → dist/data}/api/interface/IConcurrencySafe.d.ts +0 -0
  68. package/{data → dist/data}/api/interface/IConcurrencySafe.js +0 -0
  69. package/{data → dist/data}/api/interface/IIdentifiable.d.ts +0 -0
  70. package/{data → dist/data}/api/interface/IIdentifiable.js +0 -0
  71. package/{data → dist/data}/api/interface/IIdentifiableSecondary.d.ts +0 -0
  72. package/{data → dist/data}/api/interface/IIdentifiableSecondary.js +0 -0
  73. package/{data → dist/data}/api/interface/index.d.ts +0 -0
  74. package/{data → dist/data}/api/interface/index.js +0 -0
  75. package/{data → dist/data}/auth/dto/ClaimDto.d.ts +0 -0
  76. package/{data → dist/data}/auth/dto/ClaimDto.js +0 -0
  77. package/{data → dist/data}/auth/dto/RegisterRequestDto.d.ts +0 -0
  78. package/{data → dist/data}/auth/dto/RegisterRequestDto.js +0 -0
  79. package/{data → dist/data}/auth/dto/RoleDto.d.ts +0 -0
  80. package/{data → dist/data}/auth/dto/RoleDto.js +0 -0
  81. package/{data → dist/data}/auth/dto/SignInRequestDto.d.ts +0 -0
  82. package/{data → dist/data}/auth/dto/SignInRequestDto.js +0 -0
  83. package/{data → dist/data}/auth/dto/TokensDto.d.ts +0 -0
  84. package/{data → dist/data}/auth/dto/TokensDto.js +0 -0
  85. package/{data → dist/data}/auth/dto/UserDto.d.ts +0 -0
  86. package/{data → dist/data}/auth/dto/UserDto.js +0 -0
  87. package/{data → dist/data}/auth/dto/UserInfoDto.d.ts +0 -0
  88. package/{data → dist/data}/auth/dto/UserInfoDto.js +0 -0
  89. package/{data → dist/data}/auth/dto/index.d.ts +0 -0
  90. package/{data → dist/data}/auth/dto/index.js +0 -0
  91. package/{data → dist/data}/auth/index.d.ts +0 -0
  92. package/{data → dist/data}/auth/index.js +0 -0
  93. package/{data → dist/data}/index.d.ts +0 -0
  94. package/{data → dist/data}/index.js +0 -0
  95. package/{index.d.ts → dist/index.d.ts} +0 -0
  96. package/{index.js → dist/index.js} +0 -0
  97. package/{services → dist/services}/api/ApiCrudControllerClient/index.d.ts +0 -0
  98. package/{services → dist/services}/api/ApiCrudControllerClient/index.js +0 -0
  99. package/{services → dist/services}/api/ApiInitializationService/index.d.ts +0 -0
  100. package/{services → dist/services}/api/ApiInitializationService/index.js +0 -0
  101. package/{services → dist/services}/api/ApiReadControllerClient/index.d.ts +0 -0
  102. package/{services → dist/services}/api/ApiReadControllerClient/index.js +0 -0
  103. package/{services → dist/services}/api/HttpService/FetchHttpService.d.ts +0 -0
  104. package/{services → dist/services}/api/HttpService/FetchHttpService.js +0 -0
  105. package/{services → dist/services}/api/HttpService/HttpRequestConfig.d.ts +0 -0
  106. package/{services → dist/services}/api/HttpService/HttpRequestConfig.js +0 -0
  107. package/{services → dist/services}/api/HttpService/HttpResponse.d.ts +0 -0
  108. package/{services → dist/services}/api/HttpService/HttpResponse.js +0 -0
  109. package/{services → dist/services}/api/HttpService/IHttpService.d.ts +0 -0
  110. package/{services → dist/services}/api/HttpService/IHttpService.js +0 -0
  111. package/{services → dist/services}/api/HttpService/index.d.ts +0 -0
  112. package/{services → dist/services}/api/HttpService/index.js +0 -0
  113. package/{services → dist/services}/api/UserManagementControllerClient/index.d.ts +0 -0
  114. package/{services → dist/services}/api/UserManagementControllerClient/index.js +0 -0
  115. package/{services → dist/services}/api/index.d.ts +0 -0
  116. package/{services → dist/services}/api/index.js +0 -0
  117. package/{services → dist/services}/auth/client/AuthService/index.d.ts +0 -0
  118. package/{services → dist/services}/auth/client/AuthService/index.js +0 -0
  119. package/{services → dist/services}/auth/client/AuthorizationManagementControllerClient/index.d.ts +0 -0
  120. package/{services → dist/services}/auth/client/AuthorizationManagementControllerClient/index.js +0 -0
  121. package/{services → dist/services}/auth/client/index.d.ts +0 -0
  122. package/{services → dist/services}/auth/client/index.js +0 -0
  123. package/{services → dist/services}/auth/index.d.ts +0 -0
  124. package/{services → dist/services}/auth/index.js +0 -0
  125. package/{services → dist/services}/index.d.ts +0 -0
  126. package/{services → dist/services}/index.js +0 -0
  127. package/{utils → dist/utils}/index.d.ts +0 -0
  128. package/{utils → dist/utils}/index.js +0 -0
  129. package/jest.config.js +29 -0
  130. package/package.json +24 -24
  131. package/src/adapters/CollectionViewAdapter/index.ts +390 -0
  132. package/src/adapters/index.ts +1 -0
  133. package/src/data/api/dto/PropertyPathDto.ts +4 -0
  134. package/src/data/api/dto/ReadOptionsDto.ts +8 -0
  135. package/src/data/api/dto/ReadResultDto.ts +13 -0
  136. package/src/data/api/dto/ReadResultMetadataDto.ts +8 -0
  137. package/src/data/api/dto/crud/CrudMetadataDto.ts +4 -0
  138. package/src/data/api/dto/crud/index.ts +1 -0
  139. package/src/data/api/dto/index.ts +4 -0
  140. package/src/data/api/dto/read/ReadMetadataDto.ts +8 -0
  141. package/src/data/api/dto/read/ReadSelectedDefinitionDto.ts +21 -0
  142. package/src/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.ts +25 -0
  143. package/src/data/api/dto/read/ReadSelectedNestedCriteriaDto.ts +20 -0
  144. package/src/data/api/dto/read/ReadSelectedOrderingDefinitionDto.ts +8 -0
  145. package/src/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.ts +16 -0
  146. package/src/data/api/dto/read/ReadSelectedPaginationDefinitionDto.ts +13 -0
  147. package/src/data/api/dto/read/ReadSelectedSearchDefinitionDto.ts +43 -0
  148. package/src/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.ts +186 -0
  149. package/src/data/api/dto/read/index.ts +9 -0
  150. package/src/data/api/dto/response/ApiErrorDto.ts +21 -0
  151. package/src/data/api/dto/response/ApiErrorResponseDto.ts +13 -0
  152. package/src/data/api/dto/response/ApiResponseDto.ts +7 -0
  153. package/src/data/api/dto/response/ApiSuccessResponseDto.ts +13 -0
  154. package/src/data/api/dto/response/MetadataDto.ts +24 -0
  155. package/src/data/api/dto/response/index.ts +5 -0
  156. package/src/data/api/enum/index.ts +2 -0
  157. package/src/data/api/enum/read/ReadSelectedCollectionOperator.ts +17 -0
  158. package/src/data/api/enum/read/ReadSelectedComparisonOperator.ts +96 -0
  159. package/src/data/api/enum/read/ReadSelectedLogicalOperator.ts +16 -0
  160. package/src/data/api/enum/read/ReadSelectedOrderingDirection.ts +13 -0
  161. package/src/data/api/enum/read/ReadSelectedPropertyType.ts +86 -0
  162. package/src/data/api/enum/read/index.ts +5 -0
  163. package/src/data/api/enum/response/ErrorCode.ts +13 -0
  164. package/src/data/api/enum/response/index.ts +1 -0
  165. package/src/data/api/index.ts +3 -0
  166. package/src/data/api/interface/IConcurrencySafe.ts +9 -0
  167. package/src/data/api/interface/IIdentifiable.ts +12 -0
  168. package/src/data/api/interface/IIdentifiableSecondary.ts +9 -0
  169. package/src/data/api/interface/index.ts +3 -0
  170. package/src/data/auth/dto/ClaimDto.ts +4 -0
  171. package/src/data/auth/dto/RegisterRequestDto.ts +4 -0
  172. package/src/data/auth/dto/RoleDto.ts +6 -0
  173. package/src/data/auth/dto/SignInRequestDto.ts +4 -0
  174. package/src/data/auth/dto/TokensDto.ts +4 -0
  175. package/src/data/auth/dto/UserDto.ts +18 -0
  176. package/src/data/auth/dto/UserInfoDto.ts +15 -0
  177. package/src/data/auth/dto/index.ts +4 -0
  178. package/src/data/auth/index.ts +2 -0
  179. package/src/data/auth/policy.ts +63 -0
  180. package/src/data/index.ts +2 -0
  181. package/src/index.ts +4 -0
  182. package/src/services/api/ApiCrudControllerClient/index.ts +129 -0
  183. package/src/services/api/ApiInitializationService/index.ts +254 -0
  184. package/src/services/api/ApiReadControllerClient/index.ts +137 -0
  185. package/src/services/api/HttpService/FetchHttpService.ts +34 -0
  186. package/src/services/api/HttpService/HttpRequestConfig.ts +10 -0
  187. package/src/services/api/HttpService/HttpResponse.ts +14 -0
  188. package/src/services/api/HttpService/IHttpService.ts +17 -0
  189. package/src/services/api/HttpService/README.md +106 -0
  190. package/src/services/api/HttpService/index.ts +12 -0
  191. package/src/services/api/UserManagementControllerClient/index.ts +160 -0
  192. package/src/services/api/index.ts +5 -0
  193. package/src/services/auth/client/AuthService/index.ts +187 -0
  194. package/src/services/auth/client/AuthorizationManagementControllerClient/index.ts +165 -0
  195. package/src/services/auth/client/index.ts +2 -0
  196. package/src/services/auth/index.ts +1 -0
  197. package/src/services/index.ts +2 -0
  198. package/src/utils/authorization/index.ts +47 -0
  199. package/src/utils/index.ts +2 -0
  200. package/src/utils/result/index.ts +25 -0
  201. package/src/utils/search/index.ts +150 -0
  202. package/tests/ApiClients.test.ts +284 -0
  203. package/tests/CollectionViewAdapter.test.ts +392 -0
  204. package/tests/HttpService.test.ts +303 -0
  205. package/tests/setup.ts +76 -0
  206. package/tsconfig.json +19 -0
  207. package/LICENSE.md +0 -7
  208. /package/{data → dist/data}/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +0 -0
  209. /package/{data → dist/data}/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +0 -0
  210. /package/{data → dist/data}/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +0 -0
  211. /package/{data → dist/data}/api/dto/read/ReadSelectedNestedCriteriaDto.js +0 -0
  212. /package/{data → dist/data}/api/dto/response/ApiErrorResponseDto.d.ts +0 -0
  213. /package/{data → dist/data}/api/dto/response/ApiErrorResponseDto.js +0 -0
  214. /package/{data → dist/data}/api/dto/response/MetadataDto.d.ts +0 -0
  215. /package/{data → dist/data}/api/dto/response/MetadataDto.js +0 -0
  216. /package/{data → dist/data}/api/enum/read/ReadSelectedCollectionOperator.d.ts +0 -0
  217. /package/{data → dist/data}/api/enum/read/ReadSelectedCollectionOperator.js +0 -0
  218. /package/{data → dist/data}/api/enum/response/ErrorCode.d.ts +0 -0
  219. /package/{data → dist/data}/api/enum/response/ErrorCode.js +0 -0
  220. /package/{data → dist/data}/auth/policy.d.ts +0 -0
  221. /package/{data → dist/data}/auth/policy.js +0 -0
  222. /package/{utils → dist/utils}/authorization/index.d.ts +0 -0
  223. /package/{utils → dist/utils}/authorization/index.js +0 -0
  224. /package/{utils → dist/utils}/result/index.d.ts +0 -0
  225. /package/{utils → dist/utils}/result/index.js +0 -0
  226. /package/{utils → dist/utils}/search/index.d.ts +0 -0
  227. /package/{utils → dist/utils}/search/index.js +0 -0
@@ -0,0 +1,390 @@
1
+ import { IIdentifiable, PropertyPathDto, ReadSelectedDefinitionDto, ReadSelectedOrderingDirection, ReadSelectedSearchDefinitionDto } from '@data';
2
+ import { toPascalCase } from '@utils';
3
+ import { ApiReadControllerClient } from '@services';
4
+
5
+ /**
6
+ * Used with CollectionViewAdapter, a simplified configuration object for handling reading/writing from/to ReadSelectedDefinitionDto.
7
+ *
8
+ * @template TDto The type of the collection being sorted/filtered/paginated.
9
+ *
10
+ * @property {object} pagination - Pagination configuration
11
+ * @property {boolean} pagination.useTotalItemCount - Used for last page related logic of the paginator.
12
+ * Set to true if the total count for the collection is available; false assumes the last page is not known
13
+ * and adapts the pagination display accordingly.
14
+ * @property {number} [pagination.pageSize] - Number of items/rows to be fetched for the current page.
15
+ * @property {number} [pagination.pageNumber] - Current page index (skips fetching `(n-1) * pageSize` items/rows).
16
+ *
17
+ * @property {object} ordering - Ordering configuration
18
+ * @property {string[]} [ordering.orderByPath] - Array of column/property names that are sortable.
19
+ * @property {ReadSelectedOrderingDirection} [ordering.orderDirection] - Enum for ascending/descending sort order.
20
+ *
21
+ * @property {object} search - Search configuration
22
+ * @property {(keyof TDto)[]} [search.textSearchableProperties] - Array of column/property names that are searchable where the value type is string.
23
+ * @property {(keyof TDto)[]} [search.numericSearchableProperties] - Array of column/property names that are searchable where the value type is number.
24
+ * @property {ReadSelectedSearchDefinitionDto<TDto>} [search.searchDefinition] - The search definition by which the collection will be filtered.
25
+ */
26
+ export type CollectionViewAdapterOptions<TDto> = {
27
+ pagination: {
28
+ useTotalItemCount: boolean;
29
+ pageSize?: number;
30
+ pageNumber?: number;
31
+ };
32
+ ordering: {
33
+ maxActiveOrderingColumns: number;
34
+ orderByPaths: {
35
+ orderByPath: PropertyPathDto;
36
+ orderDirection: ReadSelectedOrderingDirection;
37
+ }[];
38
+ };
39
+ search: {
40
+ textSearchableProperties?: (keyof TDto)[];
41
+ numericSearchableProperties?: (keyof TDto)[];
42
+ searchDefinition?: ReadSelectedSearchDefinitionDto<TDto>;
43
+ };
44
+ };
45
+
46
+ /**
47
+ * TS class for handling ordering, filtering and paginating collections
48
+ *
49
+ * @param controllerName - specify the target endpoint controller name.
50
+ * @param dataChangedCallback - Function invoked whenever the data changes.
51
+ * Receives a loading state flag and the updated data collection.
52
+ * @param options - Optional settings of type CollectionViewAdapter to customize the behavior of the adapter.
53
+ */
54
+ export class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>> {
55
+ private _readClient: ApiReadControllerClient<TKey, TDto>;
56
+
57
+ private _isLoading = false;
58
+ private _pageData: TDto[] = [];
59
+
60
+ private _defaultOptions: CollectionViewAdapterOptions<TDto> = {
61
+ pagination: {
62
+ useTotalItemCount: false,
63
+ pageSize: 10,
64
+ pageNumber: 1,
65
+ },
66
+ ordering: {
67
+ maxActiveOrderingColumns: 1,
68
+ orderByPaths: [],
69
+ },
70
+ search: {
71
+ textSearchableProperties: [],
72
+ numericSearchableProperties: [],
73
+ },
74
+ };
75
+
76
+ private _initialOptions: CollectionViewAdapterOptions<TDto>;
77
+ private _currentOptions: CollectionViewAdapterOptions<TDto>;
78
+
79
+ constructor(
80
+ controllerName: string,
81
+ dataChangedCallback: (isLoading: boolean, data: TDto[] | undefined, error: string | undefined) => void,
82
+ options?: CollectionViewAdapterOptions<TDto>,
83
+ ) {
84
+ this._readClient = new ApiReadControllerClient<TKey, TDto>(controllerName);
85
+
86
+ this._initialOptions = {
87
+ pagination: {
88
+ ...this._defaultOptions.pagination,
89
+ ...options?.pagination,
90
+ },
91
+ ordering: {
92
+ ...this._defaultOptions.ordering,
93
+ ...options?.ordering,
94
+ },
95
+ search: {
96
+ ...this._defaultOptions.search,
97
+ ...options?.search,
98
+ },
99
+ };
100
+
101
+ this._currentOptions = {
102
+ pagination: { ...this._initialOptions.pagination },
103
+ ordering: { ...this._initialOptions.ordering },
104
+ search: { ...this._initialOptions.search },
105
+ };
106
+
107
+ this._dataChangedCallback = dataChangedCallback;
108
+ this._fetchCurrentPageData();
109
+ }
110
+
111
+ //#region SEARCH
112
+
113
+ /**
114
+ * Allows for adding any filtering criteria. Label is required to distinguish custom search categories (e.g. searchTerm, dateRange, anyCustom ...)
115
+ */
116
+ public setSearchDefinition(searchDefinition: ReadSelectedSearchDefinitionDto<TDto>) {
117
+ this._currentOptions.search.searchDefinition = searchDefinition;
118
+ this._currentOptions.pagination.pageNumber = 1; // Reset to first page
119
+ return this._fetchCurrentPageData();
120
+ }
121
+
122
+ //#endregion
123
+
124
+ //#region ORDERING
125
+
126
+ /**
127
+ * Compares two PropertyPathDto arrays for equality
128
+ */
129
+ private _arePropertyPathsEqual(path1: PropertyPathDto, path2: PropertyPathDto): boolean {
130
+ if (path1.length !== path2.length) return false;
131
+ return path1.every((segment, index) => segment === path2[index]);
132
+ }
133
+
134
+ /**
135
+ * Public method for ordering the collection by property path / column name.
136
+ *
137
+ * @param propertyPath - must match camel-cased property/column name being sorted
138
+ * @param orderDirection - use `ReadSelectedOrderingDirection` enum choices
139
+ */
140
+ public setOrdering(propertyPath: PropertyPathDto, orderDirection: ReadSelectedOrderingDirection) {
141
+ // Remove any existing ordering for this property path
142
+ this._currentOptions.ordering.orderByPaths = this._currentOptions.ordering.orderByPaths.filter(
143
+ p => !this._arePropertyPathsEqual(p.orderByPath, propertyPath),
144
+ );
145
+
146
+ // Add the new ordering at the beginning
147
+ this._currentOptions.ordering.orderByPaths.unshift({
148
+ orderByPath: propertyPath,
149
+ orderDirection: orderDirection,
150
+ });
151
+
152
+ // Limit to maxActiveOrderingColumns
153
+ if (this._currentOptions.ordering.orderByPaths.length > this._currentOptions.ordering.maxActiveOrderingColumns) {
154
+ this._currentOptions.ordering.orderByPaths = this._currentOptions.ordering.orderByPaths.slice(0, this._currentOptions.ordering.maxActiveOrderingColumns);
155
+ }
156
+
157
+ this._currentOptions.pagination.pageNumber = 1; // Reset to first page
158
+ return this._fetchCurrentPageData();
159
+ }
160
+
161
+ /**
162
+ * Returns the property name of the current columns/properties on which ordering is applied, along with the `ReadSelectedOrderingDirection` direction
163
+ */
164
+ public getCurrentOrdering() {
165
+ return this._currentOptions.ordering.orderByPaths;
166
+ }
167
+ //#endregion
168
+
169
+ //#region PAGINATION
170
+
171
+ /**
172
+ * Returns the current page's page number
173
+ */
174
+ public get currentPage() {
175
+ return this._currentOptions.pagination.pageNumber;
176
+ }
177
+
178
+ /**
179
+ * Sets the current page to `pageNumber` and triggers data re-fetch
180
+ *
181
+ * @param pageNumber
182
+ */
183
+ public jumpToPage(pageNumber: number) {
184
+ this._currentOptions.pagination.pageNumber = pageNumber;
185
+ return this._fetchCurrentPageData();
186
+ }
187
+
188
+ /**
189
+ * Returns the currently set page size value
190
+ */
191
+ public get pageSize() {
192
+ return this._currentOptions.pagination.pageSize;
193
+ }
194
+
195
+ /**
196
+ * Page size dictates the number of items or rows being fetched in a single API call
197
+ *
198
+ * @param pageSize
199
+ */
200
+ public setPageSize(pageSize: number) {
201
+ this._currentOptions.pagination.pageSize = pageSize;
202
+ this._currentOptions.pagination.pageNumber = 1; // Reset to first page
203
+ return this._fetchCurrentPageData();
204
+ }
205
+
206
+ private _totalItemCount = -1;
207
+
208
+ /**
209
+ * Returns the total count value of the collection.
210
+ *
211
+ * If `CollectionViewAdapterOptions` has set `pagination.useTotalItemCount` to `true`, the API will return this value along with the collection and it will be set automatically.
212
+ * Else this adapter will attempt to dynamically calculate this value via `_calculateTotal()`.
213
+ */
214
+ public get totalItemCount() {
215
+ return this._totalItemCount;
216
+ }
217
+
218
+ //#endregion
219
+
220
+ /**
221
+ * Callback function invoked whenever data changes.
222
+ * Receives a loading state flag and the updated data collection.
223
+ */
224
+ private readonly _dataChangedCallback!: (isLoading: boolean, data: TDto[] | undefined, errorMessage: string | undefined) => void;
225
+
226
+ /**
227
+ * Timeout reference used to debounce calls to `_fetchCurrentPageData`.
228
+ */
229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
+ private _fetchCurrentPageDataTimeout?: any;
231
+
232
+ /**
233
+ * Queue of pending promises waiting for `_fetchCurrentPageData` to resolve or reject.
234
+ */
235
+ private _fetchCurrentPageDataPromises: { resolve: (value: TDto[] | PromiseLike<TDto[]>) => void; reject: (reason?: unknown) => void }[] = [];
236
+
237
+ /**
238
+ * Tracks the current in-flight request controller to allow cancellation when a new fetch starts.
239
+ */
240
+ private _currentAbortController?: AbortController;
241
+
242
+ /**
243
+ * Fetches the current page of data with debouncing support.
244
+ * Consolidates multiple concurrent calls into a single execution,
245
+ * resolving all queued promises with the same result.
246
+ *
247
+ * @returns A promise resolving to the fetched page of data.
248
+ */
249
+ private async _fetchCurrentPageData(): Promise<TDto[]> {
250
+ return new Promise((resolve, reject) => {
251
+ this._fetchCurrentPageDataPromises.push({ resolve, reject });
252
+ if (this._fetchCurrentPageDataTimeout !== undefined) {
253
+ clearTimeout(this._fetchCurrentPageDataTimeout);
254
+ }
255
+ this._fetchCurrentPageDataTimeout = setTimeout(async () => {
256
+ try {
257
+ const result = await this._fetchCurrentPageDataDebounced();
258
+ const promises = this._fetchCurrentPageDataPromises.splice(0, this._fetchCurrentPageDataPromises.length);
259
+ for (const p of promises) p.resolve(result);
260
+ } catch (err) {
261
+ const promises = this._fetchCurrentPageDataPromises.splice(0, this._fetchCurrentPageDataPromises.length);
262
+ for (const p of promises) p.reject(err);
263
+ }
264
+ }, 50);
265
+ });
266
+ }
267
+
268
+ /**
269
+ * Executes the actual data fetch operation after debounce delay.
270
+ * Updates the loading state, triggers data change callbacks,
271
+ * and handles total item count calculation if pagination is enabled.
272
+ *
273
+ * @returns A promise resolving to the fetched page of data.
274
+ */
275
+ private async _fetchCurrentPageDataDebounced(): Promise<TDto[]> {
276
+ this._isLoading = true;
277
+ this._dataChangedCallback(this._isLoading, undefined, undefined);
278
+ let abortController: AbortController | undefined;
279
+ let caughtError: unknown;
280
+
281
+ try {
282
+ // Cancel any in-flight request before starting a new one
283
+ if (this._currentAbortController) {
284
+ try {
285
+ this._currentAbortController.abort();
286
+ } catch {
287
+ // Ignore abort errors as they are expected when debouncing
288
+ }
289
+ }
290
+ abortController = new AbortController();
291
+ this._currentAbortController = abortController;
292
+
293
+ const definition = this._parseOptionsToDefinition();
294
+ const response = await this._readClient.readSelected(definition, abortController?.signal);
295
+
296
+ if (!response.ok) {
297
+ throw response.error;
298
+ }
299
+
300
+ this._pageData = response.result;
301
+
302
+ if (this._currentOptions.pagination.useTotalItemCount && response.metadata.totalCount !== undefined) {
303
+ this._totalItemCount = response.metadata.totalCount;
304
+ } else {
305
+ const pageSize = this._currentOptions.pagination.pageSize!;
306
+ const currentPageNumber = this._currentOptions.pagination.pageNumber!;
307
+ const itemsOnCurrentPageCount = this._pageData.length;
308
+ this._totalItemCount = this._calculateTotal(pageSize, currentPageNumber, itemsOnCurrentPageCount, this._totalItemCount);
309
+ }
310
+
311
+ return this._pageData;
312
+ } catch (error: unknown) {
313
+ caughtError = error;
314
+
315
+ // Do not log abort-related errors as they are expected when debouncing
316
+ if (error instanceof DOMException && error.name === 'AbortError') {
317
+ return Promise.reject(error);
318
+ }
319
+
320
+ console.error('Error fetching data:', error);
321
+ return Promise.reject(error);
322
+ } finally {
323
+ this._isLoading = false;
324
+
325
+ let errorName: string | undefined;
326
+ if (caughtError && !(caughtError instanceof DOMException && caughtError.name === 'AbortError')) {
327
+ errorName = caughtError instanceof Error ? caughtError.name : undefined;
328
+ }
329
+ this._dataChangedCallback(this._isLoading, this._pageData, errorName);
330
+
331
+ // Clear the abort controller only if it belongs to this request (avoid racing with a newer one)
332
+
333
+ if (abortController && this._currentAbortController === abortController) {
334
+ this._currentAbortController = undefined;
335
+ }
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Takes current `CollectionViewAdapterOptions` and parses to `ReadSelectedDefinitionDto` which the cornerstone API expects.
341
+ *
342
+ * @returns - `ReadSelectedDefinitionDto` object
343
+ */
344
+ private _parseOptionsToDefinition(): ReadSelectedDefinitionDto<TDto> {
345
+ const definition: ReadSelectedDefinitionDto<TDto> = {
346
+ paginationDefinition: {
347
+ skip: (this._currentOptions.pagination.pageNumber! - 1) * this._currentOptions.pagination.pageSize!,
348
+ limit: this._currentOptions.pagination.pageSize!,
349
+ },
350
+ };
351
+
352
+ // Apply ordering
353
+ const orderByPaths = this._currentOptions.ordering.orderByPaths;
354
+
355
+ if (orderByPaths && orderByPaths.length > 0) {
356
+ definition.orderingDefinition = {
357
+ order: orderByPaths.map(orderPath => ({
358
+ propertyPath: orderPath.orderByPath.map(x => toPascalCase(x)) as PropertyPathDto,
359
+ direction: orderPath.orderDirection,
360
+ })),
361
+ };
362
+ }
363
+
364
+ // Apply search
365
+ definition.searchDefinition = this._currentOptions.search.searchDefinition;
366
+
367
+ return definition;
368
+ }
369
+
370
+ /**
371
+ * Calculates the total item count given pagination inputs.
372
+ *
373
+ * For example, with 10 items per page, on page 2 with 3 items, total = 13.
374
+ * If the total cannot be inferred (e.g., a full page is returned), the previous total is returned unchanged.
375
+ *
376
+ * @param pageSize - Number of items per page
377
+ * @param currentPageNumber - Current page number (1-based)
378
+ * @param itemsOnCurrentPageCount - Number of items in the fetched page
379
+ * @param previousTotal - Previous known total to preserve when indeterminate
380
+ * @returns The computed total item count
381
+ */
382
+ private _calculateTotal(pageSize: number, currentPageNumber: number, itemsOnCurrentPageCount: number, previousTotal: number): number {
383
+ if (itemsOnCurrentPageCount < pageSize && itemsOnCurrentPageCount !== 0) {
384
+ return pageSize * (currentPageNumber - 1) + itemsOnCurrentPageCount;
385
+ } else if (itemsOnCurrentPageCount === 0 && pageSize === 0) {
386
+ return 0;
387
+ }
388
+ return previousTotal;
389
+ }
390
+ }
@@ -0,0 +1 @@
1
+ export * from './CollectionViewAdapter';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Array of properties that when combined form a path to a property.
3
+ */
4
+ export type PropertyPathDto = string[];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Options for configuring read operations.
3
+ *
4
+ * @property {boolean} includeTotalCount - Whether to include the total count of items in the response.
5
+ */
6
+ export type ReadOptionsDto = {
7
+ includeTotalCount: boolean;
8
+ };
@@ -0,0 +1,13 @@
1
+ import { ReadResultMetadataDto } from './ReadResultMetadataDto';
2
+
3
+ /**
4
+ * Represents a read result containing a collection of results and metadata.
5
+ *
6
+ * @template T The type of result in the collection.
7
+ * @property {T[]} items - The collection of results returned.
8
+ * @property {ReadResultMetadata} metadata - Metadata about the paginated result.
9
+ */
10
+ export type ReadResultDto<T> = {
11
+ results: T[];
12
+ metadata: ReadResultMetadataDto;
13
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Metadata associated with a paginated read result.
3
+ *
4
+ * @property {number} [totalCount] - The total number of items available.
5
+ */
6
+ export type ReadResultMetadataDto = {
7
+ totalCount?: number;
8
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Metadata associated with a crud result.
3
+ */
4
+ export type CrudMetadataDto = object;
@@ -0,0 +1 @@
1
+ export * from './CrudMetadataDto';
@@ -0,0 +1,4 @@
1
+ export * from './response';
2
+ export * from './read';
3
+ export * from './crud';
4
+ export * from './PropertyPathDto';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Metadata associated with a read result.
3
+ *
4
+ * @property {number} [totalCount] - The total number of items available.
5
+ */
6
+ export type ReadMetadataDto = {
7
+ totalCount?: number;
8
+ };
@@ -0,0 +1,21 @@
1
+ import { ReadSelectedPaginationDefinitionDto, ReadSelectedOrderingDefinitionDto, ReadSelectedSearchDefinitionDto } from '@data';
2
+
3
+ /**
4
+ * Defines the selection criteria for a controller to fetch multiple records
5
+ */
6
+ export type ReadSelectedDefinitionDto<T> = {
7
+ /**
8
+ * Pagination definition
9
+ */
10
+ paginationDefinition?: ReadSelectedPaginationDefinitionDto;
11
+
12
+ /**
13
+ * Ordering definition
14
+ */
15
+ orderingDefinition?: ReadSelectedOrderingDefinitionDto;
16
+
17
+ /**
18
+ * Search definition (supports both simple search and nested logical groups)
19
+ */
20
+ searchDefinition?: ReadSelectedSearchDefinitionDto<T>;
21
+ };
@@ -0,0 +1,25 @@
1
+ import { ReadSelectedCollectionOperator, ReadSelectedSearchDefinitionDto } from '@data';
2
+
3
+ /**
4
+ * Defines criteria for searching within a collection navigation property using quantifiers (Any/All).
5
+ *
6
+ * This DTO allows navigation into a collection property and applying search criteria
7
+ * with a quantifier to determine if any or all elements match.
8
+ */
9
+ export type ReadSelectedNestedCollectionCriteriaDto<T, TPropertyName extends keyof T> = {
10
+ /**
11
+ * The name of the collection navigation property to navigate into.
12
+ */
13
+ propertyName: TPropertyName;
14
+
15
+ /**
16
+ * The quantifier operator determining whether any or all elements must match.
17
+ */
18
+ collectionOperator: ReadSelectedCollectionOperator;
19
+
20
+ /**
21
+ * The search criteria to apply to elements in the collection.
22
+ * Type should be ReadSelectedSearchDefinitionDto of the collection element type.
23
+ */
24
+ criteria: ReadSelectedSearchDefinitionDto<unknown>;
25
+ };
@@ -0,0 +1,20 @@
1
+ import {ReadSelectedSearchDefinitionDto} from '@data';
2
+
3
+ /**
4
+ * Defines criteria for searching within a nested object property.
5
+ *
6
+ * This DTO allows navigation into a nested object property and applying search criteria
7
+ * to that nested object. The property name must refer to a navigation property (not a collection).
8
+ */
9
+ export type ReadSelectedNestedCriteriaDto<T, TPropertyName extends keyof T> = {
10
+ /**
11
+ * The name of the navigation property to navigate into.
12
+ */
13
+ propertyName: TPropertyName;
14
+
15
+ /**
16
+ * The search criteria to apply to the nested object.
17
+ * Type should be ReadSelectedSearchDefinitionDto of the nested object type.
18
+ */
19
+ criteria: ReadSelectedSearchDefinitionDto<unknown>;
20
+ };
@@ -0,0 +1,8 @@
1
+ import { ReadSelectedOrderingPropertyDefinitionDto } from '@data';
2
+
3
+ /**
4
+ * Represents the ordering definition for a controller.
5
+ */
6
+ export type ReadSelectedOrderingDefinitionDto = {
7
+ order: ReadSelectedOrderingPropertyDefinitionDto[];
8
+ };
@@ -0,0 +1,16 @@
1
+ import { PropertyPathDto, ReadSelectedOrderingDirection } from '@data';
2
+
3
+ /**
4
+ * Defines the ordering property for a controller.
5
+ */
6
+ export type ReadSelectedOrderingPropertyDefinitionDto = {
7
+ /**
8
+ * Gets or sets the property path.
9
+ */
10
+ propertyPath: PropertyPathDto;
11
+
12
+ /**
13
+ * Gets or sets the ordering direction.
14
+ */
15
+ direction: ReadSelectedOrderingDirection;
16
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Defines the pagination parameters for a controller.
3
+ */
4
+ export type ReadSelectedPaginationDefinitionDto = {
5
+ /**
6
+ * Pagination offset
7
+ */
8
+ skip: number;
9
+ /**
10
+ * Pagination limit
11
+ */
12
+ limit: number;
13
+ };
@@ -0,0 +1,43 @@
1
+ import {
2
+ ReadSelectedLogicalOperator,
3
+ ReadSelectedNestedCollectionCriteriaDto,
4
+ ReadSelectedNestedCriteriaDto,
5
+ ReadSelectedSearchPropertyDefinitionDto,
6
+ } from '@data';
7
+
8
+ /**
9
+ * Defines the search criteria for a controller using a recursive structure.
10
+ *
11
+ * This DTO supports complex search queries with:
12
+ * - Logical operators (AND/OR) to combine multiple criteria
13
+ * - Direct property value comparisons via `propertyCriteria`
14
+ * - Nested searches via `searches` for recursive query composition
15
+ * - Navigation into nested objects via `nestedCriteria`
16
+ * - Collection quantifier queries (Any/All) via `nestedCollectionCriteria`
17
+ */
18
+ export type ReadSelectedSearchDefinitionDto<T> = {
19
+ /**
20
+ * The logical operator to combine all criteria at this level.
21
+ */
22
+ logicalOperator: ReadSelectedLogicalOperator;
23
+
24
+ /**
25
+ * Recursive nested search definitions combined with the logical operator.
26
+ */
27
+ searches?: ReadSelectedSearchDefinitionDto<T>[];
28
+
29
+ /**
30
+ * Direct property value comparison criteria.
31
+ */
32
+ propertyCriteria?: ReadSelectedSearchPropertyDefinitionDto<T, keyof T>[];
33
+
34
+ /**
35
+ * Criteria for searching within nested object properties.
36
+ */
37
+ nestedCriteria?: ReadSelectedNestedCriteriaDto<T, keyof T>[];
38
+
39
+ /**
40
+ * Criteria for searching within collection properties using Any/All quantifiers.
41
+ */
42
+ nestedCollectionCriteria?: ReadSelectedNestedCollectionCriteriaDto<T, keyof T>[];
43
+ };