@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,307 @@
1
+ "use strict";
2
+ /**
3
+ * File Log Writer Repository
4
+ * 負責將日誌寫入檔案系統
5
+ *
6
+ * 功能:
7
+ * - JSON Lines 格式(每行一個 JSON 物件)
8
+ * - 每日檔案命名:uofx-YYYY-MM-DD.jsonl
9
+ * - 檔案大小輪替
10
+ * - 舊檔案自動清理
11
+ * - 錯誤隔離(寫入失敗不影響主程式)
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
30
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
32
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
34
+ };
35
+ var __importStar = (this && this.__importStar) || (function () {
36
+ var ownKeys = function(o) {
37
+ ownKeys = Object.getOwnPropertyNames || function (o) {
38
+ var ar = [];
39
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
+ return ar;
41
+ };
42
+ return ownKeys(o);
43
+ };
44
+ return function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ })();
52
+ var __metadata = (this && this.__metadata) || function (k, v) {
53
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
54
+ };
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.FileLogWriterRepository = void 0;
57
+ const fs = __importStar(require("fs"));
58
+ const path = __importStar(require("path"));
59
+ const os = __importStar(require("os"));
60
+ const tsyringe_1 = require("tsyringe");
61
+ const logger_types_1 = require("../../../domain/types/logger.types");
62
+ const index_1 = require("../../../constants/index");
63
+ const file_operations_util_1 = require("../../utils/file-operations.util");
64
+ /**
65
+ * 預設配置
66
+ */
67
+ const DEFAULT_CONFIG = {
68
+ path: path.join(os.homedir(), index_1.WINDOWS_PATHS.USER_CONFIG_DIR, 'logs', 'uofx.log'),
69
+ maxSize: index_1.LOG_DEFAULTS.MAX_FILE_SIZE,
70
+ maxFiles: index_1.LOG_DEFAULTS.MAX_BACKUP_COUNT,
71
+ format: 'json',
72
+ level: logger_types_1.LogLevel.DEBUG,
73
+ enabled: true,
74
+ dailyRotation: true,
75
+ };
76
+ /**
77
+ * File Log Writer Repository 實作
78
+ */
79
+ let FileLogWriterRepository = class FileLogWriterRepository {
80
+ constructor() {
81
+ this.initialized = false;
82
+ this.currentDate = '';
83
+ this.currentFilePath = '';
84
+ // 使用默認配置
85
+ // 如果未來需要自定義配置,應該從 IAppConfig 注入
86
+ this.config = DEFAULT_CONFIG;
87
+ this.baseDir = path.dirname(this.config.path);
88
+ this.updateCurrentFilePath();
89
+ }
90
+ /**
91
+ * 更新當前檔案路徑(根據日期)
92
+ */
93
+ updateCurrentFilePath() {
94
+ const today = this.getDateString();
95
+ if (this.currentDate !== today) {
96
+ this.currentDate = today;
97
+ if (this.config.dailyRotation) {
98
+ this.currentFilePath = path.join(this.baseDir, `uofx-${today}.jsonl`);
99
+ }
100
+ else {
101
+ this.currentFilePath = this.config.path;
102
+ }
103
+ }
104
+ }
105
+ /**
106
+ * 取得當前日期字串(YYYY-MM-DD)
107
+ */
108
+ getDateString() {
109
+ const now = new Date();
110
+ const year = now.getFullYear();
111
+ const month = String(now.getMonth() + 1).padStart(2, '0');
112
+ const day = String(now.getDate()).padStart(2, '0');
113
+ return `${year}-${month}-${day}`;
114
+ }
115
+ /**
116
+ * 初始化 Repository
117
+ */
118
+ async init() {
119
+ if (this.initialized)
120
+ return;
121
+ try {
122
+ if (!fs.existsSync(this.baseDir)) {
123
+ fs.mkdirSync(this.baseDir, { recursive: true });
124
+ }
125
+ this.initialized = true;
126
+ }
127
+ catch {
128
+ // 靜默處理:日誌目錄建立失敗不應影響主程式
129
+ // 後續寫入操作會各自處理錯誤
130
+ }
131
+ }
132
+ /**
133
+ * 關閉 Repository
134
+ */
135
+ async close() {
136
+ this.initialized = false;
137
+ }
138
+ /**
139
+ * 檢查是否應該記錄此級別的日誌
140
+ */
141
+ shouldLog(level) {
142
+ return this.config.enabled && level >= this.config.level;
143
+ }
144
+ /**
145
+ * 設定日誌級別
146
+ */
147
+ setLogLevel(level) {
148
+ this.config.level = level;
149
+ }
150
+ /**
151
+ * 同步寫入日誌
152
+ */
153
+ write(entry) {
154
+ if (!this.shouldLog(entry.level)) {
155
+ return;
156
+ }
157
+ try {
158
+ this.ensureInitialized();
159
+ this.updateCurrentFilePath();
160
+ this.rotateIfNeededSync();
161
+ this.cleanupOldFilesSync();
162
+ const logLine = this.formatEntry(entry);
163
+ fs.appendFileSync(this.currentFilePath, logLine + '\n', 'utf8');
164
+ }
165
+ catch {
166
+ // 靜默處理:日誌寫入失敗不應影響主程式
167
+ }
168
+ }
169
+ /**
170
+ * 非同步寫入日誌
171
+ */
172
+ async writeAsync(entry) {
173
+ if (!this.shouldLog(entry.level)) {
174
+ return;
175
+ }
176
+ try {
177
+ await this.init();
178
+ this.updateCurrentFilePath();
179
+ await this.rotateIfNeeded();
180
+ await this.cleanupOldFiles();
181
+ const logLine = this.formatEntry(entry);
182
+ await fs.promises.appendFile(this.currentFilePath, logLine + '\n', 'utf8');
183
+ }
184
+ catch {
185
+ // 靜默處理:日誌寫入失敗不應影響主程式
186
+ }
187
+ }
188
+ /**
189
+ * 取得日誌檔案路徑
190
+ */
191
+ getLogFilePath() {
192
+ this.updateCurrentFilePath();
193
+ return this.currentFilePath;
194
+ }
195
+ /**
196
+ * 清除日誌檔案
197
+ */
198
+ async clearLogFile() {
199
+ try {
200
+ if (fs.existsSync(this.currentFilePath)) {
201
+ await fs.promises.writeFile(this.currentFilePath, '', 'utf8');
202
+ }
203
+ const files = await fs.promises.readdir(this.baseDir);
204
+ for (const file of files) {
205
+ if (file.startsWith('uofx-') && file.endsWith('.jsonl')) {
206
+ try {
207
+ await fs.promises.unlink(path.join(this.baseDir, file));
208
+ }
209
+ catch {
210
+ // 忽略不存在的檔案
211
+ }
212
+ }
213
+ }
214
+ }
215
+ catch {
216
+ // 靜默處理:清理日誌失敗不應影響主程式
217
+ }
218
+ }
219
+ /**
220
+ * 格式化日誌項目
221
+ */
222
+ formatEntry(entry) {
223
+ if (this.config.format === 'json') {
224
+ return JSON.stringify(entry);
225
+ }
226
+ const parts = [
227
+ entry.timestamp,
228
+ logger_types_1.LogLevelNames[entry.level].padEnd(5),
229
+ entry.context?.component ? `[${entry.context.component}]` : '',
230
+ entry.message,
231
+ ];
232
+ let result = parts.filter(Boolean).join(' ');
233
+ if (entry.error) {
234
+ result += ` | Error: ${entry.error.name}: ${entry.error.message}`;
235
+ }
236
+ return result;
237
+ }
238
+ /**
239
+ * 確保已初始化
240
+ */
241
+ ensureInitialized() {
242
+ if (!this.initialized) {
243
+ if (!fs.existsSync(this.baseDir)) {
244
+ fs.mkdirSync(this.baseDir, { recursive: true });
245
+ }
246
+ this.initialized = true;
247
+ }
248
+ }
249
+ /**
250
+ * 檢查並執行日誌輪轉(非同步)
251
+ */
252
+ async rotateIfNeeded() {
253
+ const needsRotation = await (0, file_operations_util_1.shouldRotate)(this.currentFilePath, this.config.maxSize);
254
+ if (needsRotation) {
255
+ await (0, file_operations_util_1.rotateLogFiles)({
256
+ filePath: this.currentFilePath,
257
+ maxFiles: this.config.maxFiles,
258
+ });
259
+ }
260
+ }
261
+ /**
262
+ * 檢查並執行日誌輪轉(同步)
263
+ */
264
+ rotateIfNeededSync() {
265
+ const needsRotation = (0, file_operations_util_1.shouldRotateSync)(this.currentFilePath, this.config.maxSize);
266
+ if (needsRotation) {
267
+ (0, file_operations_util_1.rotateLogFilesSync)({
268
+ filePath: this.currentFilePath,
269
+ maxFiles: this.config.maxFiles,
270
+ });
271
+ }
272
+ }
273
+ /**
274
+ * 清理過期的日誌檔案(非同步)
275
+ */
276
+ async cleanupOldFiles() {
277
+ if (!this.config.dailyRotation) {
278
+ return;
279
+ }
280
+ await (0, file_operations_util_1.cleanupOldLogFiles)({
281
+ baseDir: this.baseDir,
282
+ filePrefix: 'uofx-',
283
+ fileExtension: '.jsonl',
284
+ maxFiles: this.config.maxFiles,
285
+ });
286
+ }
287
+ /**
288
+ * 清理過期的日誌檔案(同步)
289
+ */
290
+ cleanupOldFilesSync() {
291
+ if (!this.config.dailyRotation) {
292
+ return;
293
+ }
294
+ (0, file_operations_util_1.cleanupOldLogFilesSync)({
295
+ baseDir: this.baseDir,
296
+ filePrefix: 'uofx-',
297
+ fileExtension: '.jsonl',
298
+ maxFiles: this.config.maxFiles,
299
+ });
300
+ }
301
+ };
302
+ exports.FileLogWriterRepository = FileLogWriterRepository;
303
+ exports.FileLogWriterRepository = FileLogWriterRepository = __decorate([
304
+ (0, tsyringe_1.injectable)(),
305
+ __metadata("design:paramtypes", [])
306
+ ], FileLogWriterRepository);
307
+ //# sourceMappingURL=file-log-writer.repository.js.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Logger Services
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./file-log-writer.repository"), exports);
21
+ __exportStar(require("./file-log-reader.repository"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Persistence Infrastructure
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./instance-storage.adapter"), exports);
21
+ __exportStar(require("./user-settings.adapter"), exports);
22
+ __exportStar(require("./instance-metadata.adapter"), exports);
23
+ __exportStar(require("./interfaces"), exports);
24
+ __exportStar(require("./services"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.InstanceMetadataAdapter = void 0;
43
+ const tsyringe_1 = require("tsyringe");
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ /**
47
+ * 實例 Metadata Adapter
48
+ *
49
+ * 實作 IInstanceMetadataPort,負責 metadata 的檔案系統持久化
50
+ */
51
+ let InstanceMetadataAdapter = class InstanceMetadataAdapter {
52
+ constructor() {
53
+ this.METADATA_FILENAME = 'metadata.json';
54
+ }
55
+ /**
56
+ * 儲存實例 metadata
57
+ */
58
+ save(metadata, installPath) {
59
+ const metadataPath = this.getMetadataPath(installPath);
60
+ // 確保目錄存在
61
+ if (!fs.existsSync(installPath)) {
62
+ fs.mkdirSync(installPath, { recursive: true });
63
+ }
64
+ fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2), 'utf8');
65
+ }
66
+ /**
67
+ * 載入實例 metadata
68
+ */
69
+ load(installPath) {
70
+ const metadataPath = this.getMetadataPath(installPath);
71
+ if (!fs.existsSync(metadataPath)) {
72
+ return null;
73
+ }
74
+ try {
75
+ const content = fs.readFileSync(metadataPath, 'utf8');
76
+ return JSON.parse(content);
77
+ }
78
+ catch {
79
+ return null;
80
+ }
81
+ }
82
+ /**
83
+ * 檢查 metadata 是否存在
84
+ */
85
+ exists(installPath) {
86
+ const metadataPath = this.getMetadataPath(installPath);
87
+ return fs.existsSync(metadataPath);
88
+ }
89
+ /**
90
+ * 取得 metadata 檔案路徑
91
+ */
92
+ getMetadataPath(installPath) {
93
+ return path.join(installPath, this.METADATA_FILENAME);
94
+ }
95
+ };
96
+ exports.InstanceMetadataAdapter = InstanceMetadataAdapter;
97
+ exports.InstanceMetadataAdapter = InstanceMetadataAdapter = __decorate([
98
+ (0, tsyringe_1.injectable)()
99
+ ], InstanceMetadataAdapter);
100
+ //# sourceMappingURL=instance-metadata.adapter.js.map
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.InstanceStorageAdapter = void 0;
16
+ const tsyringe_1 = require("tsyringe");
17
+ const tokens_1 = require("../../di/tokens");
18
+ /**
19
+ * 實例儲存 Adapter
20
+ *
21
+ * 實作 IInstanceStoragePort,負責實例 Metadata 的持久化操作
22
+ */
23
+ let InstanceStorageAdapter = class InstanceStorageAdapter {
24
+ constructor(instanceRepo) {
25
+ this.instanceRepo = instanceRepo;
26
+ }
27
+ /**
28
+ * 儲存實例 metadata
29
+ */
30
+ async saveInstance(metadata) {
31
+ await this.instanceRepo.save(metadata);
32
+ }
33
+ /**
34
+ * 載入實例 metadata
35
+ */
36
+ async loadInstance(name) {
37
+ return await this.instanceRepo.load(name);
38
+ }
39
+ /**
40
+ * 刪除實例 metadata
41
+ */
42
+ async deleteInstance(name) {
43
+ await this.instanceRepo.delete(name);
44
+ }
45
+ /**
46
+ * 列出所有實例 metadata
47
+ */
48
+ async listInstances() {
49
+ return await this.instanceRepo.listAll();
50
+ }
51
+ /**
52
+ * 檢查實例 metadata 是否存在
53
+ */
54
+ async instanceExists(name) {
55
+ return await this.instanceRepo.exists(name);
56
+ }
57
+ };
58
+ exports.InstanceStorageAdapter = InstanceStorageAdapter;
59
+ exports.InstanceStorageAdapter = InstanceStorageAdapter = __decorate([
60
+ (0, tsyringe_1.injectable)(),
61
+ __param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.FileInstanceRepository)),
62
+ __metadata("design:paramtypes", [Object])
63
+ ], InstanceStorageAdapter);
64
+ //# sourceMappingURL=instance-storage.adapter.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.repository.interface.js.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Persistence Interfaces
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./instance.repository.interface"), exports);
21
+ __exportStar(require("./config.repository.interface"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=instance.repository.interface.js.map