user-setting.ts
Overview
The user-setting.ts file defines TypeScript interfaces and type aliases related to user information, tenant data, and system status monitoring within an application. Its primary purpose is to provide structured typing for user profiles, tenant management, and system health metrics, which are essential for ensuring type safety and clarity when handling these entities across the system.
This file does not contain executable code such as classes or functions but instead focuses on defining the shape and expected properties of data objects used elsewhere in the application. These interfaces enable consistent data handling for user settings, authentication states, tenant user roles, and system monitoring components.
Detailed Documentation of Interfaces and Types
1. IUserInfo
Represents detailed information about a user in the system, including authentication status, profile details, and timestamps.
Property | Type | Description |
|---|---|---|
|
| Authentication token for user sessions. |
|
| Optional user avatar image or data (type flexible). |
|
| Preferred UI color scheme for the user. |
|
| Date string when the user account was created. |
|
| Timestamp (epoch) for account creation time. |
|
| User's email address. |
|
| Unique identifier for the user. |
|
| Indicates if the user is active (typically "true" or "false"). |
|
| Indicates if the user is anonymous. |
|
| Indicates if the user has been authenticated. |
|
| Flag for superuser (admin) privileges. |
|
| Preferred language setting of the user. |
|
| Last login timestamp as a string. |
|
| The channel used for user login (e.g., web, mobile). |
|
| User's display nickname. |
|
| Hashed password string. |
|
| Status of the user account (e.g., active, suspended). |
|
| User's timezone setting. |
|
| Last update date of user info. |
|
| Timestamp for last update time. |
Usage Example:
const currentUser: IUserInfo = {
access_token: "abc123",
color_schema: "dark",
create_date: "2023-01-01",
create_time: 1672531200,
email: "[email protected]",
id: "user-001",
is_active: "true",
is_anonymous: "false",
is_authenticated: "true",
is_superuser: false,
language: "en",
last_login_time: "2024-05-30T10:15:00Z",
login_channel: "web",
nickname: "john_doe",
password: "hashed_password",
status: "active",
timezone: "UTC+0",
update_date: "2024-05-30",
update_time: 1717000000,
};
2. TaskExecutorElapsed
A type alias representing a record/dictionary where keys are strings and values are arrays of numbers. Typically used to track elapsed times or durations for task executors.
type TaskExecutorElapsed = Record<string, number[]>;
Example:
const executorTimes: TaskExecutorElapsed = {
"executor1": [120, 130, 110],
"executor2": [210, 190],
};
3. TaskExecutorHeartbeatItem
Describes the heartbeat status of a task executor instance, which is a monitoring snapshot of task execution metrics.
Property | Type | Description |
|---|---|---|
|
| Time the executor instance was booted. |
|
| Currently unused or reserved field (always null). |
|
| Number of completed tasks. |
|
| Number of failed tasks. |
|
| Task execution lag metric (e.g., delay in ms). |
|
| Name of the executor instance. |
|
| Current timestamp of the heartbeat. |
|
| Number of pending tasks. |
4. ISystemStatus
Aggregates system health and status information from multiple subsystems:
Property | Type | Description |
|---|---|---|
|
| Status info for Elasticsearch cluster. |
|
| Status info for storage service. |
|
| Status info for database service. |
|
| Status info for Redis cache. |
|
| Heartbeat data for task executors, keyed by executor name. |
5. Es
Represents Elasticsearch status details.
Property | Type | Description |
|---|---|---|
|
| Current status (e.g., "green"). |
|
| Response time or elapsed duration. |
|
| Error message if any. |
|
| Number of nodes in the cluster. |
|
| Number of active shards. |
6. Storage
Storage service status data.
Property | Type | Description |
|---|---|---|
|
| Current storage status. |
|
| Elapsed time for health check. |
|
| Error message if present. |
7. Database
Database service status data.
Property | Type | Description |
|---|---|---|
|
| Current database status. |
|
| Elapsed time for health check. |
|
| Error message if present. |
8. Redis
Redis cache status data.
Property | Type | Description |
|---|---|---|
|
| Current Redis status. |
|
| Elapsed time for health check. |
|
| Error message if present. |
|
| Number of pending Redis operations. |
9. ITenantUser
Represents a user within a tenant (multi-tenant system), including role and delta time information.
Property | Type | Description |
|---|---|---|
|
| Unique tenant user identifier. |
|
| Avatar URL or string. |
|
| Time difference in seconds (e.g., from UTC or server). |
|
| Email address of the tenant user. |
|
| Active status flag. |
|
| Anonymous status flag. |
|
| Authentication status. |
|
| Superuser flag. |
|
| Nickname or display name. |
|
| Role of the tenant user (e.g., admin). |
|
| User status within tenant. |
|
| Last updated date. |
|
| System-wide user ID associated with tenant user. |
10. ITenant
Represents tenant information, typically for the tenant itself (organization or group).
Property | Type | Description |
|---|---|---|
|
| Avatar or logo for the tenant. |
|
| Time difference in seconds relative to some reference time. |
|
| Contact email for the tenant. |
|
| Tenant display name. |
|
| Role of the current user in the tenant context. |
|
| Unique identifier for the tenant. |
|
| Date of last update. |
Implementation Details and Algorithms
Data Typing Focus: This file exclusively provides structural typing with interfaces and type aliases. It does not contain runtime logic, algorithms, or method implementations.
System Monitoring: The
ISystemStatusinterface groups health information from multiple services such as Elasticsearch, database, Redis, and storage, along with heartbeat information for task executors. This design supports centralized monitoring and health-check mechanisms.Tenant and User Separation: The distinction between
ITenantUserandITenantsupports a multi-tenant system architecture, where users can have roles scoped within tenants, enabling role-based access control and isolation.
Interaction with Other Parts of the System
Authentication and User Management:
IUserInfois likely used in authentication modules, session management, and user profile components to maintain consistent user data.System Health Dashboard:
ISystemStatusand related interfaces are probably consumed by monitoring dashboards or health check API endpoints to display system and service statuses.Multi-Tenant Support:
ITenantUserandITenantinterfaces integrate with tenant management modules, enforcing role-based permissions and user scoping within tenants.Task Executors Monitoring: Through
TaskExecutorHeartbeatItemandTaskExecutorElapsed, the system can monitor task execution performance and health, possibly connected to background job runners or worker pools.
Visual Diagram: Class Diagram of Interfaces in user-setting.ts
classDiagram
class IUserInfo {
+access_token: string
+avatar?: any
+color_schema: string
+create_date: string
+create_time: number
+email: string
+id: string
+is_active: string
+is_anonymous: string
+is_authenticated: string
+is_superuser: boolean
+language: string
+last_login_time: string
+login_channel: string
+nickname: string
+password: string
+status: string
+timezone: string
+update_date: string
+update_time: number
}
class TaskExecutorHeartbeatItem {
+boot_at: string
+current: null
+done: number
+failed: number
+lag: number
+name: string
+now: string
+pending: number
}
class ISystemStatus {
+es: Es
+storage: Storage
+database: Database
+redis: Redis
+task_executor_heartbeat: Record<string, TaskExecutorHeartbeatItem[]>
}
class Es {
+status: string
+elapsed: number
+error: string
+number_of_nodes: number
+active_shards: number
}
class Storage {
+status: string
+elapsed: number
+error: string
}
class Database {
+status: string
+elapsed: number
+error: string
}
class Redis {
+status: string
+elapsed: number
+error: string
+pending: number
}
class ITenantUser {
+id: string
+avatar: string
+delta_seconds: number
+email: string
+is_active: string
+is_anonymous: string
+is_authenticated: string
+is_superuser: boolean
+nickname: string
+role: string
+status: string
+update_date: string
+user_id: string
}
class ITenant {
+avatar: string
+delta_seconds: number
+email: string
+nickname: string
+role: string
+tenant_id: string
+update_date: string
}
ISystemStatus --> Es
ISystemStatus --> Storage
ISystemStatus --> Database
ISystemStatus --> Redis
ISystemStatus --> TaskExecutorHeartbeatItem
Summary
The user-setting.ts file is a foundational piece of the application’s type system, defining key interfaces for users, tenants, and system health metrics. It supports application modules involved in authentication, user profile management, multi-tenant role management, and infrastructure health monitoring. The clear separation of concerns and comprehensive typing improves maintainability and reduces errors related to data handling in these critical areas.