@gsb-core/core
Version:
GSB core services and classes for platform-independent web applications
66 lines (65 loc) • 2.74 kB
TypeScript
import { QueryParams } from '../types/query-params';
import { SortCol, PropertyValue } from '../types/query';
import { GsbSaveRequest } from '../types/requests';
/**
* ServiceHelper provides common utility functions for GSB services.
* It standardizes operations like query preparation, entity validation, etc.
*/
export declare class ServiceHelper {
/**
* Prepares a standard query with pagination, sorting, and tenant info
*
* @param entityDefName - Entity name to query
* @param page - Page number (1-based)
* @param pageSize - Number of items per page
* @param whereClauses - Optional where clauses for filtering
* @param sortCols - Optional sort columns (defaults to lastUpdateDate desc)
* @param selectCols - Optional columns to select
* @param calcTotalCount - Whether to calculate total count (default: true)
* @returns Prepared QueryParams object
*/
static prepareQuery(entityDefName: string, page?: number, pageSize?: number, whereClauses?: PropertyValue[], sortCols?: SortCol[], selectCols?: string[], calcTotalCount?: boolean): QueryParams<any>;
/**
* Prepares a standard save request with tenant information
*
* @param entityDefName - Entity name to save
* @param entity - Entity data to save
* @param isNew - Whether this is a new entity
* @returns Prepared GsbSaveRequest object
*/
static prepareSaveRequest(entityDefName: string, entity: any, isNew?: boolean): GsbSaveRequest;
/**
* Gets authorization header with GSB token
*
* @returns Authorization header or undefined if no token
*/
static getAuthHeader(): {
Authorization: string;
} | undefined;
/**
* Gets tenant information for a request
*
* @returns Tenant code or undefined if no tenant
*/
static getTenantInfo(): string | undefined;
/**
* Validates if a user has permission to access a resource
*
* @param permissionKey - The permission key to check
* @param userPermissions - The user's permissions
* @returns True if user has permission, false otherwise
*/
static hasPermission(permissionKey: string, userPermissions: string[]): boolean;
/**
* Checks if a reference property name already exists in the referenced entity
*
* @param refPropName - The reference property name to check
* @param refEntityId - The ID of the referenced entity
* @param tables - Array of available tables/entities
* @returns Object containing validation result and message
*/
static checkRefPropNameUniqueness(refPropName: string, refEntityId: string, tables: any[]): {
isValid: boolean;
message: string;
};
}