All files / src/utils constants.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                    2x         2x                     177x 177x                 8x    
/**
 * System Constants
 *
 * Shared constants used across the application
 */
 
/**
 * Reserved entity IDs that cannot be used for user-created entities
 * These correspond to system entities with hardcoded schemas
 */
export const RESERVED_ENTITY_IDS = ['entity', 'role', 'user'] as const
 
/**
 * Visibility levels for entities
 */
export const VISIBILITY_LEVELS = ['flow-members', 'restricted', 'public'] as const
 
export type VisibilityLevel = (typeof VISIBILITY_LEVELS)[number]
 
/**
 * Check if an entity name would conflict with a reserved system entity ID
 * @param name - The proposed entity name
 * @returns true if the name conflicts with a reserved ID
 */
export function isReservedEntityName(name: string): boolean {
  // Normalize the name the same way the backend does
  const proposedId = name.toLowerCase().replace(/[^a-z0-9-]/g, '-')
  return RESERVED_ENTITY_IDS.includes(proposedId as any)
}
 
/**
 * Get a user-friendly error message for reserved entity names
 * @param name - The proposed entity name
 * @returns An error message explaining the conflict
 */
export function getReservedNameError(name: string): string {
  return `Entity name "${name}" conflicts with reserved system entity. Reserved names: ${RESERVED_ENTITY_IDS.join(', ')}`
}