first version

This commit is contained in:
2026-08-16 12:46:15 +08:00
commit 932fce1b9e
40 changed files with 4005 additions and 0 deletions
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiAuthCenterOptions.cs。
*/
package simapi.configurations
/**
* 认证中心配置(对齐 C# SimApiAuthCenterOptions)。
*/
public class SimApiAuthCenterOptions {
/**
* 认证中心地址。
*/
public var server: String = ""
/**
* 应用 Id。
*/
public var appId: String = ""
/**
* 应用密钥。
*/
public var appKey: String = ""
/**
* 开启则使用内部网关透传的 Middleware。
* 注意:只有内部应用需要开启这个,也就是 api 通过内部网关代理后。
*/
public var useMiddleware: Bool = false
/**
* 是否使用 IAM 认证。
*/
public var useIam: Bool = false
public init() {}
}
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiDocOptions.cs。
*/
package simapi.configurations
import std.collection.*
/**
* 文档组配置(对齐 C# SimApiDocGroupOption)。
*/
public class SimApiDocGroup {
public var id: String = ""
public var name: String = ""
public var description: String = ""
public init() {}
public init(id: String, name: String, description!: String = "") {
this.id = id
this.name = name
this.description = description
}
}
/**
* 文档授权配置(对齐 C# SimApiAuthOption)。
* Type 支持 "SimApiAuth"、"ClientCredentials"、"Implicit"、"AuthorizationCode"、"Password"。
*/
public class SimApiAuthOption {
/**
* 认证方式(默认 ["SimApiAuth"])。
* `type` 是仓颉关键字,用反引号转义以对齐 C# 属性名 Type。
*/
public var `type`: Array<String> = ["SimApiAuth"]
/**
* 认证描述(默认 "认证服务器颁发的AccessToken")。
*/
public var description: String = "认证服务器颁发的AccessToken"
/**
* 授权地址。
*/
public var authorizationUrl: String = ""
/**
* Token 地址。
*/
public var tokenUrl: String = ""
/**
* 授权范围。
*/
public var scopes: HashMap<String, String> = HashMap<String, String>()
public init() {}
}
/**
* 文档相关配置(默认值与 C# 一致)。
*/
public class SimApiDocOptions {
/**
* 文档组配置(默认 [new("api", "Api", "Api接口文档")])。
*/
public var apiGroups: ArrayList<SimApiDocGroup> = ArrayList<SimApiDocGroup>()
/**
* 授权配置(默认 SimApiAuthOption())。
*/
public var apiAuth = SimApiAuthOption()
/**
* 文档页面标题(默认 "API接口文档")。
*/
public var documentTitle: String = "API接口文档"
/**
* 接口支持的调用方式(默认仅 POST)。
*/
public var supportedMethods: Array<String> = ["POST"]
public init() {
apiGroups.add(SimApiDocGroup("api", "Api", description: "Api接口文档"))
}
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiExceptionOptions.cs。
*/
package simapi.configurations
import std.collection.*
/**
* 异常处理相关配置(默认值与 C# 一致)。
*/
public class SimApiExceptionOptions {
/**
* 跳过不做业务错误处理的状态码(默认 [200, 301, 302])。
*/
public var skipStatusCodes: HashSet<Int64> = HashSet<Int64>([200, 301, 302])
public init() {}
}
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiHttpClientOptions.cs。
*/
package simapi.configurations
/**
* HTTP 客户端配置。
*/
public class SimApiHttpClientOptions {
public var server: String = ""
public var appId: String = ""
public var appKey: String = ""
public var signName: String = "sign"
public var timestampName: String = "timestamp"
public var nonceName: String = "nonce"
public var appIdName: ?String = Some("appId")
public var signFields: Array<String> = []
public init() {}
}
+65
View File
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiJobOptions.cs。
*/
package simapi.configurations
import std.collection.*
/**
* 任务调度服务器配置(对齐 C# SimApiJobServerConfig)。
*/
public class SimApiJobServer {
/**
* 队列(默认 ["default"])。
*/
public var queues: Array<String> = ["default"]
/**
* 工作线程数(默认 5)。
*/
public var workerNum: Int64 = 5
public init() {}
}
/**
* 任务调度相关配置(默认值与 C# 一致)。
*/
public class SimApiJobOptions {
/**
* WebUi 地址,设置为 null 表示不启用(默认 /jobs)。
*/
public var dashboardUrl: ?String = Some("/jobs")
/**
* WebUi 用户(默认 admin)。
*/
public var dashboardAuthUser: String = "admin"
/**
* WebUi 密码(默认 Admin@123!)。
*/
public var dashboardAuthPass: String = "Admin@123!"
/**
* 设置为 null 使用默认 redis 配置。
*/
public var redisConfiguration: ?String = None
/**
* 设置为 null 使用默认 redis 配置。
*/
public var database: ?Int64 = None
/**
* 任务服务器配置(默认 [new()])。
*/
public var servers: ArrayList<SimApiJobServer> = ArrayList<SimApiJobServer>()
public init() {
servers.add(SimApiJobServer())
}
}
+190
View File
@@ -0,0 +1,190 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiOptions.cs。
*/
package simapi.configurations
import std.collection.*
/**
* SimApi 全局配置:对应 C# 的 SimApi.Configurations.SimApiOptions。
*/
public class SimApiOptions {
/**
* Redis 配置;配置则使用 Redis,不配则自动使用 InMemory。
*/
public var redisConfiguration: String = ""
/**
* 原样返回给前端的配置信息。
*/
public var webConfig: HashMap<String, Any> = HashMap<String, Any>()
/**
* WebConfig 返回是否包含版本信息。
*/
public var webConfigIncludeVersion: Bool = true
/**
* 是否启用后台任务系统(占位,未实现)。
*/
public var enableJob: Bool = false
/**
* 启用 Token 认证。
*/
public var enableSimApiAuth: Bool = false
/**
* 启用缓存功能(默认 true)。
*/
public var enableSimApiCache: Bool = true
/**
* 启用网关授权(占位,未实现)。
*/
public var enableSimApiAuthGate: Bool = false
/**
* 开启 S3 兼容存储(占位,未实现)。
*/
public var enableSimApiStorage: Bool = false
/**
* 启用在线文档(占位,未实现)。
*/
public var enableSimApiDoc: Bool = false
/**
* 是否启用 Synapse(占位,未实现)。
*/
public var enableSynapse: Bool = false
/**
* 启用全部 CORS(默认 true)。
*/
public var enableCors: Bool = true
/**
* 启用异常拦截(默认 true)。
*/
public var enableSimApiException: Bool = true
/**
* 启用返回结果拦截(默认 true)。
*/
public var enableSimApiResponseFilter: Bool = true
/**
* 启用请求日志中间件。
*/
public var enableRequestLog: Bool = false
/**
* 开启 ForwardHeaders(默认 true)。
*/
public var enableForwardHeaders: Bool = true
/**
* 将 url 格式化为小写(默认 true)。
*/
public var enableLowerUrl: Bool = true
/**
* 启用格式化 Console Logger(默认 true)。
*/
public var enableLogger: Bool = true
/**
* 是否启用 SimApiHttpClient。
*/
public var enableSimApiHttpClient: Bool = false
public var simApiJobOptions = SimApiJobOptions()
public var simApiDocOptions = SimApiDocOptions()
public var simApiStorageOptions = SimApiStorageOptions()
public var simApiSynapseOptions = SimApiSynapseOptions()
public var simApiAuthCenterOptions = SimApiAuthCenterOptions()
public var simApiHttpClientOptions = SimApiHttpClientOptions()
public var simApiExceptionOptions = SimApiExceptionOptions()
public var simApiRouteOptions = SimApiRouteOptions()
public var simApiRequestLogOptions = SimApiRequestLogOptions()
public init() {}
// ===== .NET 风格配置回调(对齐 C# ConfigureSimApiXxx(opt => ...) =====
/**
* 配置路由选项。
* @param configure 路由配置回调。
*/
public func configureSimApiRoute(configure: (SimApiRouteOptions) -> Unit): Unit {
configure(simApiRouteOptions)
}
/**
* 配置异常处理选项。
* @param configure 异常配置回调。
*/
public func configureSimApiException(configure: (SimApiExceptionOptions) -> Unit): Unit {
configure(simApiExceptionOptions)
}
/**
* 配置 HTTP 客户端选项。
* @param configure 客户端配置回调。
*/
public func configureSimApiHttpClient(configure: (SimApiHttpClientOptions) -> Unit): Unit {
configure(simApiHttpClientOptions)
}
/**
* 配置文档选项(占位)。
* @param configure 文档配置回调。
*/
public func configureSimApiDoc(configure: (SimApiDocOptions) -> Unit): Unit {
configure(simApiDocOptions)
}
/**
* 配置存储选项(占位)。
* @param configure 存储配置回调。
*/
public func configureSimApiStorage(configure: (SimApiStorageOptions) -> Unit): Unit {
configure(simApiStorageOptions)
}
/**
* 配置任务调度选项(占位)。
* @param configure 任务配置回调。
*/
public func configureSimApiJob(configure: (SimApiJobOptions) -> Unit): Unit {
configure(simApiJobOptions)
}
/**
* 配置 Synapse 选项(占位)。
* @param configure Synapse 配置回调。
*/
public func configureSimApiSynapse(configure: (SimApiSynapseOptions) -> Unit): Unit {
configure(simApiSynapseOptions)
}
/**
* 配置请求日志选项(对齐 C# ConfigureSimApiRequestLog)。
* @param configure 请求日志配置回调。
*/
public func configureSimApiRequestLog(configure: (SimApiRequestLogOptions) -> Unit): Unit {
configure(simApiRequestLogOptions)
}
/**
* 配置认证中心选项(对齐 C# ConfigureSimApiAuthCenter)。
* @param configure 认证中心配置回调。
*/
public func configureSimApiAuthCenter(configure: (SimApiAuthCenterOptions) -> Unit): Unit {
configure(simApiAuthCenterOptions)
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiRequestLogOptions.cs。
*/
package simapi.configurations
/**
* 请求日志配置。
*/
public class SimApiRequestLogOptions {
/**
* 是否打印完整的请求 Header。
*/
public var showFullHeader: Bool = false
/**
* 是否打印完整的响应体。
*/
public var showFullResponse: Bool = false
/**
* 请求字段显示最长长度(0 表示不截断)。
*/
public var requestStringLogLength: Int64 = 0
public init() {}
}
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiRouteOptions.cs。
*/
package simapi.configurations
/**
* 路由相关配置(默认值与 C# 一致)。
*/
public class SimApiRouteOptions {
/**
* 退出登录路由(默认 /auth/logout)。
*/
public var logoutRoute: ?String = Some("/auth/logout")
/**
* 用户信息路由(默认 /user/info)。
*/
public var userInfoRoute: ?String = Some("/user/info")
/**
* 前端配置路由(默认 /config)。
*/
public var webConfigRoute: ?String = Some("/config")
public init() {}
}
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiStorageOptions.cs。
*/
package simapi.configurations
/**
* 存储相关配置(占位:仓颉版暂未实现 S3/MinIO 存储)。
*/
public class SimApiStorageOptions {
public var endpoint: String = ""
public var accessKey: String = ""
public var secretKey: String = ""
public var bucket: String = ""
public var serveUrl: String = ""
public init() {}
}
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* 对齐 C# 的 Configurations/SimApiSynapseOptions.cs。
*/
package simapi.configurations
/**
* MQTT 通信配置(默认值与 C# 一致)。
*/
public class SimApiSynapseOptions {
/**
* Mqtt 服务器的 Websocket 地址。
*/
public var websocket: String = ""
public var username: String = ""
public var password: String = ""
public var sysName: String = ""
public var appName: String = ""
public var appId: String = ""
/**
* RPC 超时秒数(默认 3)。
*/
public var rpcTimeout: Int64 = 3
/**
* Event 是否使用负载均衡:订阅 $queue 主题,消息分发给不同 AppId。
* false 时多个 AppId 都可同时收到消息(默认 false)。
*/
public var eventLoadBalancing: Bool = false
/**
* 启用分布式配置存储(默认 true)。
*/
public var enableConfigStore: Bool = true
/**
* 禁用事件客户端(默认 false)。
*/
public var disableEventClient: Bool = false
/**
* 禁用 RPC 客户端(默认 false)。
*/
public var disableRpcClient: Bool = false
public init() {}
}