@intellegens/cornerstone-client 0.0.9 → 0.0.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.
- package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.d.ts +12 -0
- package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.js +2 -0
- package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.d.ts +12 -0
- package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.js +2 -0
- package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.d.ts +12 -0
- package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/AnythingDto.d.ts +15 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/AnythingDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/AnythingManuallyMappedDto.d.ts +15 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/AnythingManuallyMappedDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PersonDto.d.ts +38 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PersonDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PersonManuallyMappedDto.d.ts +38 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PersonManuallyMappedDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PetDto.d.ts +15 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PetDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PetManuallyMappedDto.d.ts +15 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/PetManuallyMappedDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/VehicleDto.d.ts +127 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/VehicleDto.js +2 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/VehicleManuallyMappedDto.d.ts +127 -0
- package/data/_generated/Cornerstone/Fixtures/DTOs/VehicleManuallyMappedDto.js +2 -0
- package/data/_generated/index.d.ts +11 -0
- package/data/_generated/index.js +11 -0
- package/data/api/dto/ReadSelectedDefinition.d.ts +18 -0
- package/data/api/dto/ReadSelectedDefinition.js +17 -0
- package/data/api/dto/ReadSelectedFilteringDefinition.d.ts +14 -0
- package/data/api/dto/ReadSelectedFilteringDefinition.js +13 -0
- package/data/api/dto/ReadSelectedFilteringPropertyDefinition.d.ts +22 -0
- package/data/api/dto/ReadSelectedFilteringPropertyDefinition.js +21 -0
- package/data/api/dto/ReadSelectedOrderingDefinition.d.ts +7 -0
- package/data/api/dto/ReadSelectedOrderingDefinition.js +6 -0
- package/data/api/dto/ReadSelectedOrderingPropertyDefinition.d.ts +14 -0
- package/data/api/dto/ReadSelectedOrderingPropertyDefinition.js +14 -0
- package/data/api/dto/ReadSelectedPaginationDefinition.d.ts +13 -0
- package/data/api/dto/ReadSelectedPaginationDefinition.js +13 -0
- package/data/api/dto/index.d.ts +6 -0
- package/data/api/dto/index.js +6 -0
- package/data/api/enum/ReadSelectedComparisonOperator.d.ts +13 -0
- package/data/api/enum/ReadSelectedComparisonOperator.js +25 -0
- package/data/api/enum/ReadSelectedLogicalOperator.d.ts +15 -0
- package/data/api/enum/ReadSelectedLogicalOperator.js +16 -0
- package/data/api/enum/ReadSelectedOrderingDirection.d.ts +13 -0
- package/data/api/enum/ReadSelectedOrderingDirection.js +14 -0
- package/data/api/enum/ReadSelectedPropertyType.d.ts +22 -0
- package/data/api/enum/ReadSelectedPropertyType.js +32 -0
- package/data/api/enum/index.d.ts +4 -0
- package/data/api/enum/index.js +4 -0
- package/data/api/index.d.ts +3 -0
- package/data/api/index.js +3 -0
- package/data/api/interface/IIdentifiable.d.ts +10 -0
- package/data/api/interface/IIdentifiable.js +1 -0
- package/data/api/interface/IIdentifiableByGuid.d.ts +9 -0
- package/data/api/interface/IIdentifiableByGuid.js +1 -0
- package/data/api/interface/index.d.ts +2 -0
- package/data/api/interface/index.js +2 -0
- package/data/api/read/ReadSelectedDefinition.d.ts +2 -0
- package/data/api/read/ReadSelectedDefinition.js +2 -0
- package/data/api/read/ReadSelectedFilteringDefinition.d.ts +2 -0
- package/data/api/read/ReadSelectedFilteringDefinition.js +2 -0
- package/data/api/read/ReadSelectedFilteringPropertyDefinition.d.ts +2 -0
- package/data/api/read/ReadSelectedFilteringPropertyDefinition.js +2 -0
- package/data/api/read/ReadSelectedOrderingDefinition.d.ts +2 -0
- package/data/api/read/ReadSelectedOrderingDefinition.js +2 -0
- package/data/api/read/ReadSelectedOrderingPropertyDefinition.d.ts +2 -0
- package/data/api/read/ReadSelectedOrderingPropertyDefinition.js +2 -0
- package/data/api/read/ReadSelectedPaginationDefinition.d.ts +2 -0
- package/data/api/read/ReadSelectedPaginationDefinition.js +2 -0
- package/data/api/read/index.d.ts +6 -0
- package/data/api/read/index.js +6 -0
- package/data/auth/User/index.d.ts +12 -0
- package/data/auth/User/index.js +1 -0
- package/data/auth/UserInfo/index.d.ts +14 -0
- package/data/auth/UserInfo/index.js +1 -0
- package/data/auth/index.d.ts +2 -0
- package/data/auth/index.js +2 -0
- package/data/index.d.ts +2 -0
- package/data/index.js +3 -0
- package/package.json +4 -3
- package/services/api/client/ApiCrudControllerClient/index.d.ts +11 -0
- package/services/api/client/ApiCrudControllerClient/index.js +11 -0
- package/services/api/client/ApiReadControllerClient/index.d.ts +34 -0
- package/services/api/client/ApiReadControllerClient/index.js +74 -0
- package/services/api/client/index.d.ts +2 -2
- package/services/api/client/index.js +2 -2
- package/services/api/initialization/index.d.ts +14 -2
- package/services/api/initialization/index.js +20 -4
- package/services/auth/index.d.ts +1 -1
- package/services/auth/index.js +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReadSelectedOrderingDirection } from '@data';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the ordering property for a controller.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ReadSelectedOrderingPropertyDefinition {
|
|
6
|
+
/**
|
|
7
|
+
* Gets or sets the property path.
|
|
8
|
+
*/
|
|
9
|
+
PropertyPath: string;
|
|
10
|
+
/**
|
|
11
|
+
* Gets or sets the sort direction.
|
|
12
|
+
*/
|
|
13
|
+
Direction: ReadSelectedOrderingDirection;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReadSelectedOrderingDirection } from '@data';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the ordering property for a controller.
|
|
4
|
+
*/
|
|
5
|
+
export class ReadSelectedOrderingPropertyDefinition {
|
|
6
|
+
/**
|
|
7
|
+
* Gets or sets the property path.
|
|
8
|
+
*/
|
|
9
|
+
PropertyPath;
|
|
10
|
+
/**
|
|
11
|
+
* Gets or sets the sort direction.
|
|
12
|
+
*/
|
|
13
|
+
Direction = ReadSelectedOrderingDirection.Ascending;
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './ReadSelectedDefinition';
|
|
2
|
+
export * from './ReadSelectedFilteringDefinition';
|
|
3
|
+
export * from './ReadSelectedFilteringPropertyDefinition';
|
|
4
|
+
export * from './ReadSelectedOrderingDefinition';
|
|
5
|
+
export * from './ReadSelectedOrderingPropertyDefinition';
|
|
6
|
+
export * from './ReadSelectedPaginationDefinition';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './ReadSelectedDefinition';
|
|
2
|
+
export * from './ReadSelectedFilteringDefinition';
|
|
3
|
+
export * from './ReadSelectedFilteringPropertyDefinition';
|
|
4
|
+
export * from './ReadSelectedOrderingDefinition';
|
|
5
|
+
export * from './ReadSelectedOrderingPropertyDefinition';
|
|
6
|
+
export * from './ReadSelectedPaginationDefinition';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the basic comparison operators that can be used in a controller.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum ReadSelectedComparisonOperator {
|
|
5
|
+
/**
|
|
6
|
+
* Represents the equal comparison operator.
|
|
7
|
+
*/
|
|
8
|
+
Equal = 0,
|
|
9
|
+
/**
|
|
10
|
+
* Represents the not equal comparison operator.
|
|
11
|
+
*/
|
|
12
|
+
NotEqual = 1
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the basic comparison operators that can be used in a controller.
|
|
3
|
+
*/
|
|
4
|
+
export var ReadSelectedComparisonOperator;
|
|
5
|
+
(function (ReadSelectedComparisonOperator) {
|
|
6
|
+
//#region Any type
|
|
7
|
+
/**
|
|
8
|
+
* Represents the equal comparison operator.
|
|
9
|
+
*/
|
|
10
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["Equal"] = 0] = "Equal";
|
|
11
|
+
/**
|
|
12
|
+
* Represents the not equal comparison operator.
|
|
13
|
+
*/
|
|
14
|
+
ReadSelectedComparisonOperator[ReadSelectedComparisonOperator["NotEqual"] = 1] = "NotEqual";
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region Number
|
|
17
|
+
// ...
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region String
|
|
20
|
+
// ...
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region Time
|
|
23
|
+
// ...
|
|
24
|
+
//#endregion
|
|
25
|
+
})(ReadSelectedComparisonOperator || (ReadSelectedComparisonOperator = {}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the logical operators that can be used in a controller.
|
|
3
|
+
* - The `And` operator combines multiple conditions, requiring all of them to be true.
|
|
4
|
+
* - The `Or` operator combines multiple conditions, requiring at least one of them to be true.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ReadSelectedLogicalOperator {
|
|
7
|
+
/**
|
|
8
|
+
* Represents the logical AND operator.
|
|
9
|
+
*/
|
|
10
|
+
And = 0,
|
|
11
|
+
/**
|
|
12
|
+
* Represents the logical OR operator.
|
|
13
|
+
*/
|
|
14
|
+
Or = 1
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the logical operators that can be used in a controller.
|
|
3
|
+
* - The `And` operator combines multiple conditions, requiring all of them to be true.
|
|
4
|
+
* - The `Or` operator combines multiple conditions, requiring at least one of them to be true.
|
|
5
|
+
*/
|
|
6
|
+
export var ReadSelectedLogicalOperator;
|
|
7
|
+
(function (ReadSelectedLogicalOperator) {
|
|
8
|
+
/**
|
|
9
|
+
* Represents the logical AND operator.
|
|
10
|
+
*/
|
|
11
|
+
ReadSelectedLogicalOperator[ReadSelectedLogicalOperator["And"] = 0] = "And";
|
|
12
|
+
/**
|
|
13
|
+
* Represents the logical OR operator.
|
|
14
|
+
*/
|
|
15
|
+
ReadSelectedLogicalOperator[ReadSelectedLogicalOperator["Or"] = 1] = "Or";
|
|
16
|
+
})(ReadSelectedLogicalOperator || (ReadSelectedLogicalOperator = {}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents options for ordering directions
|
|
3
|
+
*/
|
|
4
|
+
export var ReadSelectedOrderingDirection;
|
|
5
|
+
(function (ReadSelectedOrderingDirection) {
|
|
6
|
+
/**
|
|
7
|
+
* Ascending ordering
|
|
8
|
+
*/
|
|
9
|
+
ReadSelectedOrderingDirection[ReadSelectedOrderingDirection["Ascending"] = 0] = "Ascending";
|
|
10
|
+
/**
|
|
11
|
+
* Descending ordering
|
|
12
|
+
*/
|
|
13
|
+
ReadSelectedOrderingDirection[ReadSelectedOrderingDirection["Descending"] = 1] = "Descending";
|
|
14
|
+
})(ReadSelectedOrderingDirection || (ReadSelectedOrderingDirection = {}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the basic property types that can be used in a controller.
|
|
3
|
+
* - The ReadSelectedPropertyType enum defines the basic property types that can be used in a fetch controller. These types include boolean, integer, long, and string.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ReadSelectedPropertyType {
|
|
6
|
+
/**
|
|
7
|
+
* Represents a boolean property type.
|
|
8
|
+
*/
|
|
9
|
+
Bool = 0,
|
|
10
|
+
/**
|
|
11
|
+
* Represents an integer property type.
|
|
12
|
+
*/
|
|
13
|
+
Int = 100,
|
|
14
|
+
/**
|
|
15
|
+
* Represents a long property type.
|
|
16
|
+
*/
|
|
17
|
+
Long = 101,
|
|
18
|
+
/**
|
|
19
|
+
* Represents a string property type.
|
|
20
|
+
*/
|
|
21
|
+
String = 200
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the basic property types that can be used in a controller.
|
|
3
|
+
* - The ReadSelectedPropertyType enum defines the basic property types that can be used in a fetch controller. These types include boolean, integer, long, and string.
|
|
4
|
+
*/
|
|
5
|
+
export var ReadSelectedPropertyType;
|
|
6
|
+
(function (ReadSelectedPropertyType) {
|
|
7
|
+
//#region Boolean
|
|
8
|
+
/**
|
|
9
|
+
* Represents a boolean property type.
|
|
10
|
+
*/
|
|
11
|
+
ReadSelectedPropertyType[ReadSelectedPropertyType["Bool"] = 0] = "Bool";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region Number
|
|
14
|
+
/**
|
|
15
|
+
* Represents an integer property type.
|
|
16
|
+
*/
|
|
17
|
+
ReadSelectedPropertyType[ReadSelectedPropertyType["Int"] = 100] = "Int";
|
|
18
|
+
/**
|
|
19
|
+
* Represents a long property type.
|
|
20
|
+
*/
|
|
21
|
+
ReadSelectedPropertyType[ReadSelectedPropertyType["Long"] = 101] = "Long";
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region string
|
|
24
|
+
/**
|
|
25
|
+
* Represents a string property type.
|
|
26
|
+
*/
|
|
27
|
+
ReadSelectedPropertyType[ReadSelectedPropertyType["String"] = 200] = "String";
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region Time
|
|
30
|
+
// ...
|
|
31
|
+
//#endregion
|
|
32
|
+
})(ReadSelectedPropertyType || (ReadSelectedPropertyType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './ReadSelectedDefinition';
|
|
2
|
+
export * from './ReadSelectedFilteringDefinition';
|
|
3
|
+
export * from './ReadSelectedFilteringPropertyDefinition';
|
|
4
|
+
export * from './ReadSelectedOrderingDefinition';
|
|
5
|
+
export * from './ReadSelectedOrderingPropertyDefinition';
|
|
6
|
+
export * from './ReadSelectedPaginationDefinition';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './ReadSelectedDefinition';
|
|
2
|
+
export * from './ReadSelectedFilteringDefinition';
|
|
3
|
+
export * from './ReadSelectedFilteringPropertyDefinition';
|
|
4
|
+
export * from './ReadSelectedOrderingDefinition';
|
|
5
|
+
export * from './ReadSelectedOrderingPropertyDefinition';
|
|
6
|
+
export * from './ReadSelectedPaginationDefinition';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a user with an identifier and email address.
|
|
3
|
+
*
|
|
4
|
+
* @template TId The type of the user identifier.
|
|
5
|
+
*
|
|
6
|
+
* @param {TId} id The unique identifier for the user.
|
|
7
|
+
* @param {string} email The email address associated with the user.
|
|
8
|
+
*/
|
|
9
|
+
export type User<TId> = {
|
|
10
|
+
id: TId;
|
|
11
|
+
email: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { User } from '@data';
|
|
2
|
+
/**
|
|
3
|
+
* Represents user information along with access token expiry.
|
|
4
|
+
*
|
|
5
|
+
* @template TId The type of the user identifier.
|
|
6
|
+
* @template TUser The type of the user object, defaulting to `User<TId>`.
|
|
7
|
+
*
|
|
8
|
+
* @param {TUser} user The user object containing user details.
|
|
9
|
+
* @param {Date} accessTokenExpiry The date and time when the access token will expire.
|
|
10
|
+
*/
|
|
11
|
+
export type UserInfo<TId, TUser = User<TId>> = {
|
|
12
|
+
user: TUser;
|
|
13
|
+
accessTokenExpiry: Date;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/data/index.d.ts
ADDED
package/data/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intellegens/cornerstone-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"demo": "
|
|
8
|
+
"build": "npm run transpile-types && tsc",
|
|
9
|
+
"demo": "npm run build && npx vite build && npx tsx ./demo",
|
|
10
|
+
"transpile-types": "cd ../utils/cli && npm run cli zod-gen -- --input '../../client/src/data/_generated/json' --output '../../client/src/data/_generated'"
|
|
10
11
|
},
|
|
11
12
|
"author": "",
|
|
12
13
|
"license": "MIT",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiReadControllerClient } from '@services';
|
|
2
|
+
/**
|
|
3
|
+
* Generic API client for consuming any Cornerstone CrudController
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class ApiReadControllerClient
|
|
7
|
+
* @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
|
|
8
|
+
* @template TDto - Data Transfer Object representing the entity
|
|
9
|
+
*/
|
|
10
|
+
export declare class ApiCrudControllerClient<TKey, TDto> extends ApiReadControllerClient<TKey, TDto> {
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiReadControllerClient } from '@services';
|
|
2
|
+
/**
|
|
3
|
+
* Generic API client for consuming any Cornerstone CrudController
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class ApiReadControllerClient
|
|
7
|
+
* @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
|
|
8
|
+
* @template TDto - Data Transfer Object representing the entity
|
|
9
|
+
*/
|
|
10
|
+
export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IIdentifiable, ReadSelectedDefinition } from '@data';
|
|
2
|
+
/**
|
|
3
|
+
* Generic API client for consuming any Cornerstone ReadController
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class ApiReadControllerClient
|
|
7
|
+
* @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
|
|
8
|
+
* @template TDto - Data Transfer Object representing the entity
|
|
9
|
+
*/
|
|
10
|
+
export declare class ApiReadControllerClient<TKey, TDto = IIdentifiable<TKey>> {
|
|
11
|
+
private readonly baseControllerPath;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param baseControllerPath Base path to API controller
|
|
15
|
+
*/
|
|
16
|
+
constructor(baseControllerPath: string);
|
|
17
|
+
/**
|
|
18
|
+
* Fetches selected entities based on a filter definition.
|
|
19
|
+
* @param {any} definition - The filter definition object
|
|
20
|
+
* @returns {Promise<TDto[]>} List of entities that match the selection criteria
|
|
21
|
+
*/
|
|
22
|
+
readSelected(definition: ReadSelectedDefinition): Promise<TDto[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Fetches a single entity by its ID.
|
|
25
|
+
* @param {TKey} id - The ID of the entity
|
|
26
|
+
* @returns {Promise<TDto | undefined>} The requested entity
|
|
27
|
+
*/
|
|
28
|
+
readSingle(id: TKey): Promise<TDto>;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches all entities from the read controller.
|
|
31
|
+
* @returns {Promise<TDto[]>} List of all entities
|
|
32
|
+
*/
|
|
33
|
+
readAll(): Promise<TDto[]>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { apiInitializationService } from '@services';
|
|
2
|
+
/**
|
|
3
|
+
* Generic API client for consuming any Cornerstone ReadController
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class ApiReadControllerClient
|
|
7
|
+
* @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
|
|
8
|
+
* @template TDto - Data Transfer Object representing the entity
|
|
9
|
+
*/
|
|
10
|
+
export class ApiReadControllerClient {
|
|
11
|
+
baseControllerPath;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param baseControllerPath Base path to API controller
|
|
15
|
+
*/
|
|
16
|
+
constructor(baseControllerPath) {
|
|
17
|
+
this.baseControllerPath = baseControllerPath;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetches selected entities based on a filter definition.
|
|
21
|
+
* @param {any} definition - The filter definition object
|
|
22
|
+
* @returns {Promise<TDto[]>} List of entities that match the selection criteria
|
|
23
|
+
*/
|
|
24
|
+
async readSelected(definition) {
|
|
25
|
+
try {
|
|
26
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSelected`);
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: { 'Content-Type': 'application/json' },
|
|
30
|
+
body: JSON.stringify(definition),
|
|
31
|
+
credentials: 'include',
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok)
|
|
34
|
+
throw new Error('Failed to fetch selected records');
|
|
35
|
+
return response.json();
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching selected records');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fetches a single entity by its ID.
|
|
43
|
+
* @param {TKey} id - The ID of the entity
|
|
44
|
+
* @returns {Promise<TDto | undefined>} The requested entity
|
|
45
|
+
*/
|
|
46
|
+
async readSingle(id) {
|
|
47
|
+
try {
|
|
48
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSingle?id=${encodeURIComponent(String(id))}`);
|
|
49
|
+
const response = await fetch(url, { credentials: 'include' });
|
|
50
|
+
if (!response.ok)
|
|
51
|
+
throw new Error('Failed to fetch single record');
|
|
52
|
+
return response.json();
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching single record');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetches all entities from the read controller.
|
|
60
|
+
* @returns {Promise<TDto[]>} List of all entities
|
|
61
|
+
*/
|
|
62
|
+
async readAll() {
|
|
63
|
+
try {
|
|
64
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadAll`);
|
|
65
|
+
const response = await fetch(url, { credentials: 'include' });
|
|
66
|
+
if (!response.ok)
|
|
67
|
+
throw new Error('Failed to fetch all records');
|
|
68
|
+
return response.json();
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
throw err instanceof Error ? err : new Error('Unknown error fetching all records');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './ApiReadControllerClient';
|
|
2
|
+
export * from './ApiCrudControllerClient';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './ApiReadControllerClient';
|
|
2
|
+
export * from './ApiCrudControllerClient';
|
|
@@ -54,11 +54,23 @@ export declare class ApiInitializationService {
|
|
|
54
54
|
* Composes a full API URL for a provided endpoint path.
|
|
55
55
|
*
|
|
56
56
|
* @async
|
|
57
|
-
* @param
|
|
57
|
+
* @param relativeEndpointPathSections Relative endpoint path sections
|
|
58
58
|
* @return {Promise<string | undefined>} Returns the API endpoint's URL
|
|
59
59
|
* @throws {Error} Throws error if API base URL detection fails
|
|
60
60
|
*/
|
|
61
|
-
getApiUrl(
|
|
61
|
+
getApiUrl(...relativeEndpointPathSections: string[]): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Removes starting '/' character
|
|
64
|
+
* @param str String to remove the starting '/' character from
|
|
65
|
+
* @returns String with starting '/' character removed
|
|
66
|
+
*/
|
|
67
|
+
private removeStartsWithSlashChar;
|
|
68
|
+
/**
|
|
69
|
+
* Removes ending '/' character
|
|
70
|
+
* @param str String to remove the ending '/' character from
|
|
71
|
+
* @returns String with ending '/' character removed
|
|
72
|
+
*/
|
|
73
|
+
private removeEndsWithSlashChar;
|
|
62
74
|
}
|
|
63
75
|
/**
|
|
64
76
|
* Singleton instance of ApiInitializationService
|