feat(web): T-WEB-001 NestJS 骨架 + 连接现有 MySQL 实例

This commit is contained in:
2026-09-14 19:00:55 +08:00
parent 9b8fc6be96
commit bd6cb9fa90
18 changed files with 7763 additions and 0 deletions
@@ -0,0 +1,47 @@
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
/**
* 编译进代码的契约版本常量。
* 与 `contracts/VERSION` 必须一致;`npm run contracts:check` 在构建前校验。
* 之所以编译进代码:Docker 构建上下文是 web-server/,contracts/ 不在其中。
*/
export const CONTRACT_VERSIONS: Readonly<Record<string, string>> = Object.freeze({
'rest-api': '0.1.0',
'websocket-keypoints': '0.1.0',
'data-models': '0.1.0',
'skeleton-topology': '0.1.0',
'model-formats': '0.1.0',
database: '0.1.0',
});
/** 解析 `contracts/VERSION`(`key: value` 每行一条,`#` 起注释) */
export function parseVersionFile(content: string): Record<string, string> {
const out: Record<string, string> = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) continue;
const idx = line.indexOf(':');
if (idx <= 0) continue;
const key = line.slice(0, idx).trim();
const value = line.slice(idx + 1).trim();
if (key && value) out[key] = value;
}
return out;
}
/**
* 运行期契约版本。设置 `CONTRACTS_DIR` 时读取实时文件(部署可挂载 contracts/),
* 否则回落到编译常量。
*/
export function resolveContractVersions(contractsDir?: string): Record<string, string> {
if (!contractsDir) return { ...CONTRACT_VERSIONS };
const file = join(contractsDir, 'VERSION');
if (!existsSync(file)) return { ...CONTRACT_VERSIONS };
try {
const parsed = parseVersionFile(readFileSync(file, 'utf8'));
return Object.keys(parsed).length > 0 ? parsed : { ...CONTRACT_VERSIONS };
} catch {
return { ...CONTRACT_VERSIONS };
}
}