@uofx/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +444 -0
  3. package/THIRD-PARTY-NOTICES.txt +894 -0
  4. package/dist/application/dtos/index.js +24 -0
  5. package/dist/application/dtos/request/delete-instance.request.dto.js +3 -0
  6. package/dist/application/dtos/request/get-config.request.dto.js +3 -0
  7. package/dist/application/dtos/request/get-credentials.request.dto.js +3 -0
  8. package/dist/application/dtos/request/index.js +27 -0
  9. package/dist/application/dtos/request/install-instance.request.dto.js +3 -0
  10. package/dist/application/dtos/request/list-charts.request.dto.js +3 -0
  11. package/dist/application/dtos/request/set-config.request.dto.js +16 -0
  12. package/dist/application/dtos/request/setup-environment.request.dto.js +16 -0
  13. package/dist/application/dtos/request/show-logs.request.dto.js +19 -0
  14. package/dist/application/dtos/request/start-instance.request.dto.js +3 -0
  15. package/dist/application/dtos/request/stop-instance.request.dto.js +3 -0
  16. package/dist/application/dtos/response/credentials.response.dto.js +3 -0
  17. package/dist/application/dtos/response/delete-instance.response.dto.js +3 -0
  18. package/dist/application/dtos/response/index.js +26 -0
  19. package/dist/application/dtos/response/install-instance.response.dto.js +3 -0
  20. package/dist/application/dtos/response/instance-list.response.dto.js +3 -0
  21. package/dist/application/dtos/response/instance-status.response.dto.js +3 -0
  22. package/dist/application/dtos/response/setup-result.response.dto.js +3 -0
  23. package/dist/application/dtos/response/show-logs.response.dto.js +3 -0
  24. package/dist/application/dtos/response/start-instance.response.dto.js +3 -0
  25. package/dist/application/dtos/response/stop-instance.response.dto.js +3 -0
  26. package/dist/application/index.js +25 -0
  27. package/dist/application/interfaces/index.js +24 -0
  28. package/dist/application/interfaces/use-case.interface.js +3 -0
  29. package/dist/application/use-cases/config/get-config.use-case.js +66 -0
  30. package/dist/application/use-cases/config/set-config.use-case.js +49 -0
  31. package/dist/application/use-cases/credentials/get-credentials.use-case.js +57 -0
  32. package/dist/application/use-cases/index.js +28 -0
  33. package/dist/application/use-cases/instance/delete-instance.use-case.js +81 -0
  34. package/dist/application/use-cases/instance/index.js +23 -0
  35. package/dist/application/use-cases/instance/install-instance.use-case.js +424 -0
  36. package/dist/application/use-cases/instance/list-charts.use-case.js +43 -0
  37. package/dist/application/use-cases/instance/list-instances.use-case.js +62 -0
  38. package/dist/application/use-cases/instance/start-instance.use-case.js +154 -0
  39. package/dist/application/use-cases/instance/stop-instance.use-case.js +55 -0
  40. package/dist/application/use-cases/logs/show-logs.use-case.js +66 -0
  41. package/dist/application/use-cases/setup/setup-environment.use-case.js +53 -0
  42. package/dist/cli.js +286 -0
  43. package/dist/constants/config-defaults.js +23 -0
  44. package/dist/constants/defaults.js +89 -0
  45. package/dist/constants/deployment.js +39 -0
  46. package/dist/constants/environments.js +93 -0
  47. package/dist/constants/index.js +53 -0
  48. package/dist/constants/oci-artifacts.js +25 -0
  49. package/dist/constants/paths.js +92 -0
  50. package/dist/constants/timeouts.js +60 -0
  51. package/dist/di/container.js +34 -0
  52. package/dist/di/index.js +22 -0
  53. package/dist/di/modules/application.module.js +54 -0
  54. package/dist/di/modules/infrastructure.module.js +206 -0
  55. package/dist/di/modules/interceptor.module.js +68 -0
  56. package/dist/di/modules/presentation.module.js +31 -0
  57. package/dist/di/tokens.js +149 -0
  58. package/dist/domain/decorators/sensitive.decorator.js +39 -0
  59. package/dist/domain/entities/credentials-resolver.entity.js +127 -0
  60. package/dist/domain/entities/credentials.entity.js +65 -0
  61. package/dist/domain/entities/delete-instance-validation.entity.js +100 -0
  62. package/dist/domain/entities/deployment-parameters.entity.js +120 -0
  63. package/dist/domain/entities/environment-validation.entity.js +125 -0
  64. package/dist/domain/entities/index.js +29 -0
  65. package/dist/domain/entities/instance-lifecycle-state.entity.js +100 -0
  66. package/dist/domain/entities/instance-list-aggregator.entity.js +104 -0
  67. package/dist/domain/entities/instance-metadata.entity.js +86 -0
  68. package/dist/domain/entities/instance-status.entity.js +79 -0
  69. package/dist/domain/entities/instance.entity.js +128 -0
  70. package/dist/domain/entities/log-filter.entity.js +141 -0
  71. package/dist/domain/index.js +29 -0
  72. package/dist/domain/interfaces/safe-loggable.interface.js +3 -0
  73. package/dist/domain/ports/app-config.port.js +3 -0
  74. package/dist/domain/ports/base-image.port.js +3 -0
  75. package/dist/domain/ports/chart-version.port.js +3 -0
  76. package/dist/domain/ports/correlation-id.port.js +3 -0
  77. package/dist/domain/ports/credentials.port.js +3 -0
  78. package/dist/domain/ports/deployment.port.js +3 -0
  79. package/dist/domain/ports/error-handler.port.js +3 -0
  80. package/dist/domain/ports/index.js +46 -0
  81. package/dist/domain/ports/instance-manager.port.js +3 -0
  82. package/dist/domain/ports/instance-metadata.port.js +8 -0
  83. package/dist/domain/ports/instance-storage.port.js +3 -0
  84. package/dist/domain/ports/k8s-deployer.port.js +3 -0
  85. package/dist/domain/ports/logger.port.js +14 -0
  86. package/dist/domain/ports/output.port.js +3 -0
  87. package/dist/domain/ports/runtime-environment.port.js +6 -0
  88. package/dist/domain/ports/user-interaction.port.js +9 -0
  89. package/dist/domain/ports/user-settings.port.js +3 -0
  90. package/dist/domain/types/index.js +22 -0
  91. package/dist/domain/types/logger.types.js +29 -0
  92. package/dist/domain/types/validation.types.js +9 -0
  93. package/dist/domain/value-objects/acr-credentials.value-object.js +92 -0
  94. package/dist/domain/value-objects/chart-version.value-object.js +124 -0
  95. package/dist/domain/value-objects/config-log-level.value-object.js +84 -0
  96. package/dist/domain/value-objects/connection-info.value-object.js +65 -0
  97. package/dist/domain/value-objects/index.js +25 -0
  98. package/dist/domain/value-objects/instance-name.value-object.js +91 -0
  99. package/dist/domain/value-objects/jwt-key.value-object.js +97 -0
  100. package/dist/domain/value-objects/mssql-password.value-object.js +140 -0
  101. package/dist/domain/value-objects/rsa-key-pair.value-object.js +181 -0
  102. package/dist/index.js +6 -0
  103. package/dist/infrastructure/config/app-config.interface.js +3 -0
  104. package/dist/infrastructure/config/app-config.service.js +280 -0
  105. package/dist/infrastructure/config/config-validator.js +31 -0
  106. package/dist/infrastructure/config/crypto.service.js +125 -0
  107. package/dist/infrastructure/deployment/deployment.adapter.js +118 -0
  108. package/dist/infrastructure/deployment/interfaces/acr-credential-manager.interface.js +3 -0
  109. package/dist/infrastructure/deployment/interfaces/app-manager.interface.js +3 -0
  110. package/dist/infrastructure/deployment/interfaces/helm-registry.interface.js +3 -0
  111. package/dist/infrastructure/deployment/interfaces/infra-manager.interface.js +3 -0
  112. package/dist/infrastructure/deployment/interfaces/k8s-job-runner.interface.js +3 -0
  113. package/dist/infrastructure/deployment/interfaces/mssql-database-init.interface.js +3 -0
  114. package/dist/infrastructure/deployment/interfaces/mssql-helm-deployment.interface.js +3 -0
  115. package/dist/infrastructure/deployment/interfaces/mssql-storage.interface.js +3 -0
  116. package/dist/infrastructure/deployment/interfaces/mssql-user-manager.interface.js +3 -0
  117. package/dist/infrastructure/deployment/interfaces/oci-artifact.interface.js +3 -0
  118. package/dist/infrastructure/deployment/interfaces/secret-manager.interface.js +3 -0
  119. package/dist/infrastructure/deployment/interfaces/service-manager.interface.js +3 -0
  120. package/dist/infrastructure/deployment/interfaces/version-compatibility.interface.js +3 -0
  121. package/dist/infrastructure/deployment/services/acr-credential-manager.service.js +144 -0
  122. package/dist/infrastructure/deployment/services/app-manager.service.js +193 -0
  123. package/dist/infrastructure/deployment/services/base-helm-deployment.service.js +163 -0
  124. package/dist/infrastructure/deployment/services/helm-registry.service.js +126 -0
  125. package/dist/infrastructure/deployment/services/infra-manager.service.js +130 -0
  126. package/dist/infrastructure/deployment/services/k8s-job-runner.service.js +194 -0
  127. package/dist/infrastructure/deployment/services/mssql-database-init.service.js +139 -0
  128. package/dist/infrastructure/deployment/services/mssql-helm-deployment.service.js +100 -0
  129. package/dist/infrastructure/deployment/services/mssql-storage.service.js +54 -0
  130. package/dist/infrastructure/deployment/services/mssql-user-manager.service.js +66 -0
  131. package/dist/infrastructure/deployment/services/oci-artifact.service.js +289 -0
  132. package/dist/infrastructure/deployment/services/secret-manager.service.js +179 -0
  133. package/dist/infrastructure/deployment/services/service-manager.service.js +82 -0
  134. package/dist/infrastructure/deployment/services/version-compatibility.service.js +291 -0
  135. package/dist/infrastructure/environment/interfaces/hardware-info.interface.js +3 -0
  136. package/dist/infrastructure/environment/interfaces/network-checker.interface.js +3 -0
  137. package/dist/infrastructure/environment/services/hardware-info.service.js +135 -0
  138. package/dist/infrastructure/environment/services/network-checker.service.js +142 -0
  139. package/dist/infrastructure/environment/windows-environment.adapter.js +162 -0
  140. package/dist/infrastructure/errors/app-error.js +73 -0
  141. package/dist/infrastructure/errors/error-handler.interface.js +3 -0
  142. package/dist/infrastructure/errors/error-handler.js +218 -0
  143. package/dist/infrastructure/errors/exit-codes.js +27 -0
  144. package/dist/infrastructure/errors/index.js +25 -0
  145. package/dist/infrastructure/execution/builders/base-command.builder.js +122 -0
  146. package/dist/infrastructure/execution/builders/host-command.builder.js +58 -0
  147. package/dist/infrastructure/execution/builders/windows-host-command.builder.js +50 -0
  148. package/dist/infrastructure/execution/builders/wsl-command.builder.js +29 -0
  149. package/dist/infrastructure/execution/command-builder.js +252 -0
  150. package/dist/infrastructure/execution/command-executor.service.js +230 -0
  151. package/dist/infrastructure/execution/environments/wsl-execution.environment.js +70 -0
  152. package/dist/infrastructure/execution/execution-environment.factory.js +53 -0
  153. package/dist/infrastructure/execution/index.js +25 -0
  154. package/dist/infrastructure/execution/interfaces/command-builder.interface.js +3 -0
  155. package/dist/infrastructure/execution/interfaces/command-executor.interface.js +3 -0
  156. package/dist/infrastructure/execution/interfaces/execution-environment-factory.interface.js +3 -0
  157. package/dist/infrastructure/execution/interfaces/execution-environment.interface.js +7 -0
  158. package/dist/infrastructure/execution/interfaces/host-command-builder.interface.js +3 -0
  159. package/dist/infrastructure/execution/interfaces/index.js +23 -0
  160. package/dist/infrastructure/execution/interfaces/script-executor.interface.js +3 -0
  161. package/dist/infrastructure/execution/script-executor.service.js +171 -0
  162. package/dist/infrastructure/http/http-client.service.js +176 -0
  163. package/dist/infrastructure/http/index.js +18 -0
  164. package/dist/infrastructure/http/interfaces/http-client.interface.js +3 -0
  165. package/dist/infrastructure/interceptors/index.js +8 -0
  166. package/dist/infrastructure/interceptors/interceptor.factory.js +44 -0
  167. package/dist/infrastructure/interceptors/interceptor.interface.js +3 -0
  168. package/dist/infrastructure/interceptors/logging.interceptor.js +171 -0
  169. package/dist/infrastructure/logger/correlation-id.adapter.js +68 -0
  170. package/dist/infrastructure/logger/index.js +23 -0
  171. package/dist/infrastructure/logger/interfaces/index.js +22 -0
  172. package/dist/infrastructure/logger/interfaces/log-reader.repository.interface.js +7 -0
  173. package/dist/infrastructure/logger/interfaces/log-writer.repository.interface.js +7 -0
  174. package/dist/infrastructure/logger/logger.adapter.js +274 -0
  175. package/dist/infrastructure/logger/services/file-log-reader.repository.js +148 -0
  176. package/dist/infrastructure/logger/services/file-log-writer.repository.js +307 -0
  177. package/dist/infrastructure/logger/services/index.js +22 -0
  178. package/dist/infrastructure/persistence/index.js +25 -0
  179. package/dist/infrastructure/persistence/instance-metadata.adapter.js +100 -0
  180. package/dist/infrastructure/persistence/instance-storage.adapter.js +64 -0
  181. package/dist/infrastructure/persistence/interfaces/config.repository.interface.js +3 -0
  182. package/dist/infrastructure/persistence/interfaces/index.js +22 -0
  183. package/dist/infrastructure/persistence/interfaces/instance.repository.interface.js +3 -0
  184. package/dist/infrastructure/persistence/services/file-system-config.repository.js +168 -0
  185. package/dist/infrastructure/persistence/services/file-system-instance.repository.js +170 -0
  186. package/dist/infrastructure/persistence/services/index.js +22 -0
  187. package/dist/infrastructure/persistence/user-settings.adapter.js +55 -0
  188. package/dist/infrastructure/platform-detector.js +71 -0
  189. package/dist/infrastructure/platforms/windows/interfaces/microk8s.interface.js +3 -0
  190. package/dist/infrastructure/platforms/windows/interfaces/rootfs-manager.interface.js +3 -0
  191. package/dist/infrastructure/platforms/windows/interfaces/windows-features.interface.js +3 -0
  192. package/dist/infrastructure/platforms/windows/interfaces/windows-info.interface.js +3 -0
  193. package/dist/infrastructure/platforms/windows/interfaces/wsl-config.interface.js +3 -0
  194. package/dist/infrastructure/platforms/windows/interfaces/wsl-info.interface.js +3 -0
  195. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-inspection.interface.js +3 -0
  196. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-lifecycle.interface.js +3 -0
  197. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-naming.interface.js +3 -0
  198. package/dist/infrastructure/platforms/windows/interfaces/wsl-manager.interface.js +3 -0
  199. package/dist/infrastructure/platforms/windows/interfaces/wsl-resources.interface.js +8 -0
  200. package/dist/infrastructure/platforms/windows/interfaces/wsl-updater.interface.js +3 -0
  201. package/dist/infrastructure/platforms/windows/interfaces/wslconfig-parser.interface.js +3 -0
  202. package/dist/infrastructure/platforms/windows/parsers/wsl-version.parser.js +133 -0
  203. package/dist/infrastructure/platforms/windows/services/microk8s.service.js +168 -0
  204. package/dist/infrastructure/platforms/windows/services/rootfs-manager.service.js +336 -0
  205. package/dist/infrastructure/platforms/windows/services/windows-features.service.js +191 -0
  206. package/dist/infrastructure/platforms/windows/services/windows-info.service.js +138 -0
  207. package/dist/infrastructure/platforms/windows/services/wsl-config.service.js +171 -0
  208. package/dist/infrastructure/platforms/windows/services/wsl-info.service.js +226 -0
  209. package/dist/infrastructure/platforms/windows/services/wsl-instance-inspection.service.js +325 -0
  210. package/dist/infrastructure/platforms/windows/services/wsl-instance-lifecycle.service.js +442 -0
  211. package/dist/infrastructure/platforms/windows/services/wsl-instance-naming.service.js +93 -0
  212. package/dist/infrastructure/platforms/windows/services/wsl-updater.service.js +273 -0
  213. package/dist/infrastructure/platforms/windows/services/wslconfig-parser.service.js +222 -0
  214. package/dist/infrastructure/platforms/windows/wsl-base-image.adapter.js +41 -0
  215. package/dist/infrastructure/platforms/windows/wsl-instance-manager.adapter.js +150 -0
  216. package/dist/infrastructure/utils/error-formatter.util.js +29 -0
  217. package/dist/infrastructure/utils/file-operations.util.js +201 -0
  218. package/dist/infrastructure/utils/input-validator.util.js +152 -0
  219. package/dist/infrastructure/utils/retry.util.js +98 -0
  220. package/dist/presentation/controllers/config.controller.js +146 -0
  221. package/dist/presentation/controllers/credentials.controller.js +105 -0
  222. package/dist/presentation/controllers/index.js +25 -0
  223. package/dist/presentation/controllers/instance.controller.js +363 -0
  224. package/dist/presentation/controllers/logs.controller.js +103 -0
  225. package/dist/presentation/controllers/setup.controller.js +175 -0
  226. package/dist/presentation/interfaces/cli-options.interface.js +8 -0
  227. package/dist/presentation/prompts/acr-credentials.prompt.js +76 -0
  228. package/dist/presentation/prompts/index.js +21 -0
  229. package/dist/presentation/ui/cli-progress.service.js +193 -0
  230. package/dist/presentation/ui/constants/output-symbols.js +42 -0
  231. package/dist/presentation/ui/index.js +27 -0
  232. package/dist/presentation/ui/interaction.service.js +276 -0
  233. package/dist/presentation/ui/interfaces/cli-progress.interface.js +9 -0
  234. package/dist/presentation/ui/interfaces/output-formatter.interface.js +23 -0
  235. package/dist/presentation/ui/log-level.enum.js +66 -0
  236. package/dist/presentation/ui/output-builder.service.js +378 -0
  237. package/dist/presentation/ui/output-formatter.service.js +393 -0
  238. package/package.json +65 -0
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstanceMetadata = void 0;
4
+ const instance_name_value_object_1 = require("../value-objects/instance-name.value-object");
5
+ const chart_version_value_object_1 = require("../value-objects/chart-version.value-object");
6
+ /**
7
+ * 實例元資料 Entity
8
+ *
9
+ * 包含實例的元資訊,例如建立時間、版本資訊等
10
+ */
11
+ class InstanceMetadata {
12
+ constructor(name, displayName, createdAt, version, rootfsVersion, chartVersion) {
13
+ this.name = name;
14
+ this.displayName = displayName;
15
+ this.createdAt = createdAt;
16
+ this.version = version;
17
+ this.rootfsVersion = rootfsVersion;
18
+ this.chartVersion = chartVersion;
19
+ }
20
+ /**
21
+ * 建立新的實例元資料
22
+ * @param name - 實例名稱
23
+ * @param version - CLI 版本
24
+ * @param rootfsVersion - Rootfs 版本
25
+ * @param chartVersion - Helm chart 版本 (可選)
26
+ * @returns 元資料物件
27
+ */
28
+ static create(name, version, rootfsVersion, chartVersion) {
29
+ return new InstanceMetadata(name, name.toString(), new Date(), version, rootfsVersion, chartVersion);
30
+ }
31
+ /**
32
+ * 從儲存的物件重建元資料
33
+ * @param data - 儲存的元資料物件
34
+ * @returns 元資料物件
35
+ */
36
+ static fromObject(data) {
37
+ return new InstanceMetadata(instance_name_value_object_1.InstanceName.create(data.displayName), data.displayName, new Date(data.createdAt), data.version, data.rootfsVersion, data.chartVersion ? chart_version_value_object_1.ChartVersion.create(data.chartVersion) : undefined);
38
+ }
39
+ /**
40
+ * 更新 chart 版本
41
+ * @param chartVersion - 新的 chart 版本
42
+ * @returns 新的元資料物件
43
+ */
44
+ withChartVersion(chartVersion) {
45
+ return new InstanceMetadata(this.name, this.displayName, this.createdAt, this.version, this.rootfsVersion, chartVersion);
46
+ }
47
+ /**
48
+ * 取得完整的實例名稱
49
+ * @returns 完整名稱 (uofx-{name})
50
+ */
51
+ get fullName() {
52
+ return this.name.fullName;
53
+ }
54
+ /**
55
+ * 檢查是否已安裝 Helm chart
56
+ * @returns 若已安裝則回傳 true
57
+ */
58
+ get hasChartInstalled() {
59
+ return this.chartVersion !== undefined;
60
+ }
61
+ /**
62
+ * 取得建立後經過的天數
63
+ * @returns 天數
64
+ */
65
+ get daysAgo() {
66
+ const now = new Date();
67
+ const diff = now.getTime() - this.createdAt.getTime();
68
+ return Math.floor(diff / (1000 * 60 * 60 * 24));
69
+ }
70
+ /**
71
+ * 轉換為可序列化的物件
72
+ * @returns 包含元資料的物件
73
+ */
74
+ toObject() {
75
+ return {
76
+ name: this.fullName,
77
+ displayName: this.displayName,
78
+ createdAt: this.createdAt.toISOString(),
79
+ version: this.version,
80
+ rootfsVersion: this.rootfsVersion,
81
+ chartVersion: this.chartVersion?.toString(),
82
+ };
83
+ }
84
+ }
85
+ exports.InstanceMetadata = InstanceMetadata;
86
+ //# sourceMappingURL=instance-metadata.entity.js.map
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstanceStatus = void 0;
4
+ /**
5
+ * 實例狀態 Entity
6
+ *
7
+ * 表示 WSL 實例的運行狀態
8
+ */
9
+ class InstanceStatus {
10
+ constructor(name, running, uptime) {
11
+ this.name = name;
12
+ this.running = running;
13
+ this.uptime = uptime;
14
+ }
15
+ /**
16
+ * 建立停止狀態的實例
17
+ * @param name - 實例名稱
18
+ * @returns 狀態物件
19
+ */
20
+ static createStopped(name) {
21
+ return new InstanceStatus(name, false);
22
+ }
23
+ /**
24
+ * 建立運行中狀態的實例
25
+ * @param name - 實例名稱
26
+ * @param uptime - 運行時間(秒)
27
+ * @returns 狀態物件
28
+ */
29
+ static createRunning(name, uptime) {
30
+ return new InstanceStatus(name, true, uptime);
31
+ }
32
+ /**
33
+ * 檢查實例是否正在運行
34
+ * @returns 若正在運行則回傳 true
35
+ */
36
+ get isRunning() {
37
+ return this.running;
38
+ }
39
+ /**
40
+ * 檢查實例是否已停止
41
+ * @returns 若已停止則回傳 true
42
+ */
43
+ get isStopped() {
44
+ return !this.running;
45
+ }
46
+ /**
47
+ * 取得格式化的運行時間
48
+ * @returns 格式化後的運行時間字串 (例如: "2h 30m")
49
+ */
50
+ get formattedUptime() {
51
+ if (!this.uptime || !this.running) {
52
+ return null;
53
+ }
54
+ const hours = Math.floor(this.uptime / 3600);
55
+ const minutes = Math.floor((this.uptime % 3600) / 60);
56
+ if (hours > 0) {
57
+ return `${hours}h ${minutes}m`;
58
+ }
59
+ else if (minutes > 0) {
60
+ return `${minutes}m`;
61
+ }
62
+ else {
63
+ return '<1m';
64
+ }
65
+ }
66
+ /**
67
+ * 轉換為一般物件
68
+ * @returns 包含狀態資訊的物件
69
+ */
70
+ toObject() {
71
+ return {
72
+ name: this.name,
73
+ running: this.running,
74
+ uptime: this.uptime,
75
+ };
76
+ }
77
+ }
78
+ exports.InstanceStatus = InstanceStatus;
79
+ //# sourceMappingURL=instance-status.entity.js.map
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Instance = void 0;
4
+ const instance_status_entity_1 = require("./instance-status.entity");
5
+ /**
6
+ * WSL 實例 Entity (Aggregate Root)
7
+ *
8
+ * 聚合實例的元資料與狀態,提供實例管理的核心邏輯
9
+ */
10
+ class Instance {
11
+ constructor(metadata, status) {
12
+ this.metadata = metadata;
13
+ this.status = status;
14
+ }
15
+ /**
16
+ * 建立新的實例
17
+ * @param metadata - 實例元資料
18
+ * @param status - 實例狀態
19
+ * @returns 實例物件
20
+ */
21
+ static create(metadata, status) {
22
+ if (metadata.fullName !== status.name) {
23
+ throw new Error(`Instance name mismatch: metadata.fullName="${metadata.fullName}" vs status.name="${status.name}"`);
24
+ }
25
+ return new Instance(metadata, status);
26
+ }
27
+ /**
28
+ * 建立初始實例(剛建立時的狀態)
29
+ * @param metadata - 實例元資料
30
+ * @returns 實例物件(停止狀態)
31
+ */
32
+ static createInitial(metadata) {
33
+ const status = instance_status_entity_1.InstanceStatus.createStopped(metadata.fullName);
34
+ return new Instance(metadata, status);
35
+ }
36
+ /**
37
+ * 取得實例名稱
38
+ * @returns 實例名稱物件
39
+ */
40
+ get name() {
41
+ return this.metadata.name;
42
+ }
43
+ /**
44
+ * 取得完整實例名稱
45
+ * @returns 完整名稱 (uofx-{name})
46
+ */
47
+ get fullName() {
48
+ return this.metadata.fullName;
49
+ }
50
+ /**
51
+ * 取得顯示名稱
52
+ * @returns 顯示名稱
53
+ */
54
+ get displayName() {
55
+ return this.metadata.displayName;
56
+ }
57
+ /**
58
+ * 檢查實例是否正在運行
59
+ * @returns 若正在運行則回傳 true
60
+ */
61
+ get isRunning() {
62
+ return this.status.isRunning;
63
+ }
64
+ /**
65
+ * 檢查實例是否已停止
66
+ * @returns 若已停止則回傳 true
67
+ */
68
+ get isStopped() {
69
+ return this.status.isStopped;
70
+ }
71
+ /**
72
+ * 檢查是否已安裝 Helm chart
73
+ * @returns 若已安裝則回傳 true
74
+ */
75
+ get hasChartInstalled() {
76
+ return this.metadata.hasChartInstalled;
77
+ }
78
+ /**
79
+ * 更新實例狀態
80
+ * @param status - 新的狀態
81
+ * @returns 新的實例物件
82
+ */
83
+ withStatus(status) {
84
+ return new Instance(this.metadata, status);
85
+ }
86
+ /**
87
+ * 更新實例為運行狀態
88
+ * @param uptime - 運行時間(秒)
89
+ * @returns 新的實例物件
90
+ */
91
+ markAsRunning(uptime) {
92
+ const newStatus = instance_status_entity_1.InstanceStatus.createRunning(this.fullName, uptime);
93
+ return this.withStatus(newStatus);
94
+ }
95
+ /**
96
+ * 更新實例為停止狀態
97
+ * @returns 新的實例物件
98
+ */
99
+ markAsStopped() {
100
+ const newStatus = instance_status_entity_1.InstanceStatus.createStopped(this.fullName);
101
+ return this.withStatus(newStatus);
102
+ }
103
+ /**
104
+ * 轉換為顯示資訊物件
105
+ * @returns 包含完整資訊的物件
106
+ */
107
+ toDisplayInfo() {
108
+ return {
109
+ name: this.displayName,
110
+ fullName: this.fullName,
111
+ status: this.isRunning ? 'Running' : 'Stopped',
112
+ version: this.metadata.version,
113
+ chart: this.metadata.chartVersion?.toString() || 'N/A',
114
+ installed: this.metadata.createdAt.toISOString(),
115
+ uptime: this.status.formattedUptime,
116
+ };
117
+ }
118
+ /**
119
+ * 比較兩個實例是否為同一實例
120
+ * @param other - 另一個實例
121
+ * @returns 若名稱相同則回傳 true
122
+ */
123
+ equals(other) {
124
+ return this.fullName === other.fullName;
125
+ }
126
+ }
127
+ exports.Instance = Instance;
128
+ //# sourceMappingURL=instance.entity.js.map
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogFilter = void 0;
4
+ const logger_types_1 = require("../types/logger.types");
5
+ /**
6
+ * 日誌過濾器 Entity
7
+ *
8
+ * 封裝日誌過濾的業務邏輯,包括:
9
+ * - 層級過濾
10
+ * - 關聯 ID 過濾
11
+ * - 命令/命令群組過濾
12
+ * - 時間範圍過濾
13
+ */
14
+ class LogFilter {
15
+ constructor(
16
+ /** 精確匹配的日誌層級 */
17
+ level,
18
+ /** 關聯 ID */
19
+ correlationId,
20
+ /** 命令名稱 */
21
+ command,
22
+ /** 命令群組 */
23
+ commandGroup,
24
+ /** 最早時間戳記(毫秒) */
25
+ sinceTime) {
26
+ this.level = level;
27
+ this.correlationId = correlationId;
28
+ this.command = command;
29
+ this.commandGroup = commandGroup;
30
+ this.sinceTime = sinceTime;
31
+ }
32
+ /**
33
+ * 從過濾條件建立 LogFilter
34
+ * @param criteria - 過濾條件
35
+ * @returns LogFilter 實例
36
+ */
37
+ static create(criteria) {
38
+ return new LogFilter(criteria.level ? this.parseLogLevel(criteria.level) : undefined, criteria.correlation, criteria.command, criteria.commandGroup, criteria.since ? this.parseSinceTime(criteria.since) : undefined);
39
+ }
40
+ /**
41
+ * 建立空的過濾器(不過濾任何項目)
42
+ * @returns LogFilter 實例
43
+ */
44
+ static empty() {
45
+ return new LogFilter(undefined, undefined, undefined, undefined, undefined);
46
+ }
47
+ /**
48
+ * 檢查日誌項目是否符合過濾條件
49
+ * @param entry - 日誌項目
50
+ * @returns 若符合條件則回傳 true
51
+ */
52
+ matches(entry) {
53
+ // 過濾日誌層級(精確匹配)
54
+ if (this.level !== undefined && entry.level !== this.level) {
55
+ return false;
56
+ }
57
+ // 過濾 correlation ID
58
+ if (this.correlationId && entry.correlationId !== this.correlationId) {
59
+ return false;
60
+ }
61
+ // 過濾命令
62
+ if (this.command && entry.context?.command !== this.command) {
63
+ return false;
64
+ }
65
+ // 過濾命令群組
66
+ if (this.commandGroup && entry.context?.commandGroup !== this.commandGroup) {
67
+ return false;
68
+ }
69
+ // 過濾時間
70
+ if (this.sinceTime) {
71
+ const entryTime = new Date(entry.timestamp).getTime();
72
+ if (entryTime < this.sinceTime) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+ /**
79
+ * 過濾日誌陣列
80
+ * @param entries - 日誌項目陣列
81
+ * @returns 符合條件的日誌項目陣列
82
+ */
83
+ filter(entries) {
84
+ return entries.filter(entry => this.matches(entry));
85
+ }
86
+ /**
87
+ * 檢查過濾器是否為空(不過濾任何項目)
88
+ * @returns 若沒有任何過濾條件則回傳 true
89
+ */
90
+ get isEmpty() {
91
+ return (this.level === undefined &&
92
+ this.correlationId === undefined &&
93
+ this.command === undefined &&
94
+ this.commandGroup === undefined &&
95
+ this.sinceTime === undefined);
96
+ }
97
+ /**
98
+ * 解析日誌層級字串
99
+ * @param level - 層級字串 (debug, info, warn, error, fatal)
100
+ * @returns LogLevel 或 undefined
101
+ */
102
+ static parseLogLevel(level) {
103
+ return this.LEVEL_MAP[level.toLowerCase()];
104
+ }
105
+ /**
106
+ * 解析 since 時間字串
107
+ * @param since - 時間字串 (e.g., "1h", "2d", "30m", "60s")
108
+ * @returns 時間戳記(毫秒)或 null
109
+ */
110
+ static parseSinceTime(since) {
111
+ const match = since.match(/^(\d+)([smhd])$/);
112
+ if (!match) {
113
+ return undefined;
114
+ }
115
+ const value = parseInt(match[1], 10);
116
+ const unit = match[2];
117
+ const multiplier = this.TIME_MULTIPLIERS[unit];
118
+ if (!multiplier) {
119
+ return undefined;
120
+ }
121
+ const milliseconds = value * multiplier;
122
+ return Date.now() - milliseconds;
123
+ }
124
+ }
125
+ exports.LogFilter = LogFilter;
126
+ /** 時間單位對應的毫秒數 */
127
+ LogFilter.TIME_MULTIPLIERS = {
128
+ 's': 1000, // seconds
129
+ 'm': 60 * 1000, // minutes
130
+ 'h': 60 * 60 * 1000, // hours
131
+ 'd': 24 * 60 * 60 * 1000, // days
132
+ };
133
+ /** 日誌層級對應表 */
134
+ LogFilter.LEVEL_MAP = {
135
+ 'debug': logger_types_1.LogLevel.DEBUG,
136
+ 'info': logger_types_1.LogLevel.INFO,
137
+ 'warn': logger_types_1.LogLevel.WARN,
138
+ 'error': logger_types_1.LogLevel.ERROR,
139
+ 'fatal': logger_types_1.LogLevel.FATAL,
140
+ };
141
+ //# sourceMappingURL=log-filter.entity.js.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Domain Layer
4
+ *
5
+ * 系統的核心層,包含業務邏輯與規則
6
+ * 特點:零依賴,不依賴任何外部設施
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ // Value Objects
24
+ __exportStar(require("./value-objects"), exports);
25
+ // Entities
26
+ __exportStar(require("./entities"), exports);
27
+ // Ports (介面定義,供 Infrastructure 層實作)
28
+ __exportStar(require("./ports"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=safe-loggable.interface.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=app-config.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=base-image.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chart-version.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=correlation-id.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=credentials.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=deployment.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=error-handler.port.js.map
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Domain Ports (介面定義)
4
+ *
5
+ * 定義 Domain 層對外部設施的依賴介面
6
+ * 由 Infrastructure 層實作
7
+ *
8
+ * 核心業務能力 Port:
9
+ * - IInstanceManagerPort: 實例生命週期管理
10
+ * - IDeploymentPort: 部署能力
11
+ * - IInstanceStoragePort: 實例 Metadata 儲存
12
+ * - IAppConfigPort: 應用程式配置(讀取合併後的配置)
13
+ * - IUserSettingsPort: 使用者設定(寫入 ~/.uofx/config.json)
14
+ * - ILoggerPort: 日誌記錄
15
+ * - IRuntimeEnvironmentPort: 環境檢查
16
+ * - IBaseImagePort: 基礎映像管理
17
+ */
18
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
22
+ desc = { enumerable: true, get: function() { return m[k]; } };
23
+ }
24
+ Object.defineProperty(o, k2, desc);
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
30
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ __exportStar(require("./instance-manager.port"), exports);
34
+ __exportStar(require("./deployment.port"), exports);
35
+ __exportStar(require("./k8s-deployer.port"), exports);
36
+ __exportStar(require("./chart-version.port"), exports);
37
+ __exportStar(require("./credentials.port"), exports);
38
+ __exportStar(require("./instance-storage.port"), exports);
39
+ __exportStar(require("./user-settings.port"), exports);
40
+ __exportStar(require("./logger.port"), exports);
41
+ __exportStar(require("./runtime-environment.port"), exports);
42
+ __exportStar(require("./base-image.port"), exports);
43
+ __exportStar(require("./app-config.port"), exports);
44
+ __exportStar(require("./error-handler.port"), exports);
45
+ __exportStar(require("./correlation-id.port"), exports);
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=instance-manager.port.js.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * 實例 Metadata Port
4
+ *
5
+ * 定義實例 metadata 的持久化操作介面
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=instance-metadata.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=instance-storage.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=k8s-deployer.port.js.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /**
3
+ * Logger Port
4
+ *
5
+ * 定義日誌記錄能力的抽象介面
6
+ * 由 Infrastructure 層實作
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.LogLevelNames = exports.LogLevel = void 0;
10
+ // Re-export 類型供外部使用
11
+ var logger_types_1 = require("../types/logger.types");
12
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_types_1.LogLevel; } });
13
+ Object.defineProperty(exports, "LogLevelNames", { enumerable: true, get: function () { return logger_types_1.LogLevelNames; } });
14
+ //# sourceMappingURL=logger.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=output.port.js.map
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UOFX_REQUIRED_MEMORY_GB = void 0;
4
+ /** UOFX 所需最低記憶體 (GB) */
5
+ exports.UOFX_REQUIRED_MEMORY_GB = 16;
6
+ //# sourceMappingURL=runtime-environment.port.js.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * User Interaction Port
4
+ *
5
+ * 定義使用者互動的抽象介面,供 Application 和 Infrastructure 層使用
6
+ * 實作位於 Presentation 層
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=user-interaction.port.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=user-settings.port.js.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Domain Types
4
+ * 統一匯出所有 Domain 層類型定義
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ __exportStar(require("./logger.types"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Logger 類型定義
4
+ * 統一的日誌相關類型,供 Domain 和 Infrastructure 層使用
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LogLevelNames = exports.LogLevel = void 0;
8
+ /**
9
+ * 日誌級別枚舉
10
+ */
11
+ var LogLevel;
12
+ (function (LogLevel) {
13
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
14
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
15
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
16
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
17
+ LogLevel[LogLevel["FATAL"] = 4] = "FATAL";
18
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
19
+ /**
20
+ * 日誌級別名稱對應
21
+ */
22
+ exports.LogLevelNames = {
23
+ [LogLevel.DEBUG]: 'DEBUG',
24
+ [LogLevel.INFO]: 'INFO',
25
+ [LogLevel.WARN]: 'WARN',
26
+ [LogLevel.ERROR]: 'ERROR',
27
+ [LogLevel.FATAL]: 'FATAL',
28
+ };
29
+ //# sourceMappingURL=logger.types.js.map