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

access_token

string

Authentication token for user sessions.

avatar

any

Optional user avatar image or data (type flexible).

color_schema

string

Preferred UI color scheme for the user.

create_date

string

Date string when the user account was created.

create_time

number

Timestamp (epoch) for account creation time.

email

string

User's email address.

id

string

Unique identifier for the user.

is_active

string

Indicates if the user is active (typically "true" or "false").

is_anonymous

string

Indicates if the user is anonymous.

is_authenticated

string

Indicates if the user has been authenticated.

is_superuser

boolean

Flag for superuser (admin) privileges.

language

string

Preferred language setting of the user.

last_login_time

string

Last login timestamp as a string.

login_channel

string

The channel used for user login (e.g., web, mobile).

nickname

string

User's display nickname.

password

string

Hashed password string.

status

string

Status of the user account (e.g., active, suspended).

timezone

string

User's timezone setting.

update_date

string

Last update date of user info.

update_time

number

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

boot_at

string

Time the executor instance was booted.

current

null

Currently unused or reserved field (always null).

done

number

Number of completed tasks.

failed

number

Number of failed tasks.

lag

number

Task execution lag metric (e.g., delay in ms).

name

string

Name of the executor instance.

now

string

Current timestamp of the heartbeat.

pending

number

Number of pending tasks.


4. ISystemStatus

Aggregates system health and status information from multiple subsystems:

Property

Type

Description

es

Es

Status info for Elasticsearch cluster.

storage

Storage

Status info for storage service.

database

Database

Status info for database service.

redis

Redis

Status info for Redis cache.

task_executor_heartbeat

Record<string, TaskExecutorHeartbeatItem[]>

Heartbeat data for task executors, keyed by executor name.


5. Es

Represents Elasticsearch status details.

Property

Type

Description

status

string

Current status (e.g., "green").

elapsed

number

Response time or elapsed duration.

error

string

Error message if any.

number_of_nodes

number

Number of nodes in the cluster.

active_shards

number

Number of active shards.


6. Storage

Storage service status data.

Property

Type

Description

status

string

Current storage status.

elapsed

number

Elapsed time for health check.

error

string

Error message if present.


7. Database

Database service status data.

Property

Type

Description

status

string

Current database status.

elapsed

number

Elapsed time for health check.

error

string

Error message if present.


8. Redis

Redis cache status data.

Property

Type

Description

status

string

Current Redis status.

elapsed

number

Elapsed time for health check.

error

string

Error message if present.

pending

number

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

id

string

Unique tenant user identifier.

avatar

string

Avatar URL or string.

delta_seconds

number

Time difference in seconds (e.g., from UTC or server).

email

string

Email address of the tenant user.

is_active

string

Active status flag.

is_anonymous

string

Anonymous status flag.

is_authenticated

string

Authentication status.

is_superuser

boolean

Superuser flag.

nickname

string

Nickname or display name.

role

string

Role of the tenant user (e.g., admin).

status

string

User status within tenant.

update_date

string

Last updated date.

user_id

string

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

string

Avatar or logo for the tenant.

delta_seconds

number

Time difference in seconds relative to some reference time.

email

string

Contact email for the tenant.

nickname

string

Tenant display name.

role

string

Role of the current user in the tenant context.

tenant_id

string

Unique identifier for the tenant.

update_date

string

Date of last update.


Implementation Details and Algorithms


Interaction with Other Parts of the System


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.