@gsb-core/core
Version:
GSB core services and classes for platform-independent web applications
131 lines (130 loc) • 6.45 kB
TypeScript
import { GsbEntityDef, GsbProperty, GsbPropertyDef } from '../../models/gsb-entity-def.model';
/**
* Service for managing Entity Definitions (Database Tables) in the application
*/
export declare class EntityDefService {
private entityService;
private validatorService;
private ENTITY_NAME;
private useCache;
private cacheService;
private static instance;
constructor(useCache?: boolean);
static readonly PROPERTY_DEFINITIONS: GsbPropertyDef[];
static getInstance(useCache?: boolean): EntityDefService;
/**
* Get an entity definition by ID or name
* @param def The entity definition to get
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns The entity definition or null if not found
*/
getEntityDef(def: GsbEntityDef, token?: string, tenantCode?: string): Promise<GsbEntityDef | null>;
/**
* Search for entity definitions
* @param searchTerm The search term
* @param page The page number (starting from 1)
* @param pageSize The number of items per page
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns An array of entity definitions and the total count
*/
searchEntityDefs(searchTerm: string, page?: number, pageSize?: number, includeSystemDefs?: boolean, token?: string, tenantCode?: string): Promise<{
entityDefs: GsbEntityDef[];
totalCount: number;
}>;
/**
* Create a new entity definition with enhanced validation and advanced property mapping
* @param entityDef The entity definition to create
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns The created entity definition ID
* @throws Error with message from API if the request fails
*/
createEntityDef(entityDef: GsbEntityDef, token?: string, tenantCode?: string): Promise<GsbEntityDef>;
createOrUpdateEntityDef(entityDef: GsbEntityDef, token?: string, tenantCode?: string): Promise<GsbEntityDef>;
/**
* Get default properties for a new entity definition.
* Note: lastUpdateDate and createDate properties are included here for display in the UI
* but the actual values of these fields are automatically managed by the GSB system.
*
* @param defName The name of the entity definition
* @returns Array of default GsbProperty objects
*/
getDefaultProperties(defName: string): GsbProperty[];
/**
* Update an existing entity definition
* @param entityDef The entity definition to update
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns True if updated successfully, false otherwise
* @throws Error with message from API if the request fails
*/
updateEntityDef(entityDef: GsbEntityDef, token?: string, tenantCode?: string): Promise<GsbEntityDef>;
/**
* Delete an entity definition (soft delete)
* @param id The entity definition ID to delete
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns True if deleted successfully
* @throws Error with message from API if the request fails
*/
deleteEntityDef(id: string, token?: string, tenantCode?: string): Promise<boolean>;
/**
* Check uniqueness of name and dbTableName
* @param nameToCheck The name to check for uniqueness
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns Matching entity defs with only name and dbTableName fields
*/
checkNameUniqueness(nameToCheck: string, token?: string, tenantCode?: string): Promise<{
entityDefs: Pick<GsbEntityDef, 'name' | 'dbTableName' | 'id'>[];
totalCount: number;
}>;
/**
* Check if reference property name is already used in the referenced entity
* @param refPropName Reference property name to check
* @param refEntityId ID of the referenced entity
* @returns Promise with validation result
*/
checkRefPropNameUniqueness(refPropName: string, refEntityId: string): Promise<{
isValid: boolean;
validationMessage: string;
}>;
/**
* Add a column to an existing entity definition
* @param entityDefId The entity definition ID
* @param property The column properties
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns true if successful
*/
addProperty(property: GsbProperty, entityDef?: GsbEntityDef, token?: string, tenantCode?: string): Promise<GsbProperty>;
/**
* Update a column in an existing entity definition
* @param entityDefId The entity definition ID
* @param property The column properties
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns true if successful
*/
updateProperty(property: GsbProperty, entityDef?: GsbEntityDef, token?: string, tenantCode?: string): Promise<GsbProperty>;
/**
* Remove a column from an entity definition
* @param columnIdentifier The column ID or name to remove
* @param entityDefId The entity definition ID
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns true if successful
*/
removeProperty(property: GsbProperty, entityDef?: GsbEntityDef, token?: string, tenantCode?: string): Promise<boolean>;
/**
* Get all entity definitions metadata with their properties
*
* This method caches the results and returns from cache if available
* @param token Optional custom token to use for this request
* @param tenantCode Optional custom tenant code to use for this request
* @returns Array of entity definitions with their properties
*/
getAllDefinitions(token?: string, tenantCode?: string): Promise<GsbEntityDef[]>;
}