feat(types): Phase 14.3 共用型別系統 (#97-#100)
建立 Pydantic → TypeScript 自動生成工具鏈: 1. scripts/generate-schemas.py - 從 Pydantic 模型生成 JSON Schema - 正確處理 Pydantic 2.x 的 $defs 格式 - 支援 Approval/Incident/Terminal/Playbook/CSRF 模型 2. packages/shared-types/ - @awoooi/shared-types 套件 - 44 個型別定義,40 個介面 - json-schema-to-typescript 自動生成 3. 前端整合 - apps/web 加入 @awoooi/shared-types 依賴 - typecheck 通過 使用方式: cd packages/shared-types pnpm generate # 重新生成型別 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
24
packages/shared-types/package.json
Normal file
24
packages/shared-types/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@awoooi/shared-types",
|
||||
"version": "1.0.0",
|
||||
"description": "AWOOOI 前後端共用型別定義 (自動生成自 Pydantic)",
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"scripts": {
|
||||
"generate:schema": "cd ../../apps/api && python ../../scripts/generate-schemas.py",
|
||||
"generate:types": "json2ts -i ./schemas/api-types.json -o ./src/api-types.ts --bannerComment \"/* Auto-generated from Pydantic models - DO NOT EDIT */\" --unreachableDefinitions",
|
||||
"generate": "pnpm generate:schema && pnpm generate:types",
|
||||
"clean": "rm -rf ./schemas/*.json ./src/api-types.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"json-schema-to-typescript": "^15.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"schemas"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
2212
packages/shared-types/schemas/api-types.json
Normal file
2212
packages/shared-types/schemas/api-types.json
Normal file
File diff suppressed because it is too large
Load Diff
1352
packages/shared-types/src/api-types.ts
Normal file
1352
packages/shared-types/src/api-types.ts
Normal file
File diff suppressed because it is too large
Load Diff
16
packages/shared-types/src/index.ts
Normal file
16
packages/shared-types/src/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @awoooi/shared-types
|
||||
* ====================
|
||||
* 前後端共用型別定義
|
||||
*
|
||||
* 自動生成自 Pydantic 模型,請勿手動編輯 api-types.ts
|
||||
*
|
||||
* 使用方式:
|
||||
* import type { ApprovalRequest, IncidentResponse } from '@awoooi/shared-types'
|
||||
*
|
||||
* 重新生成:
|
||||
* pnpm --filter @awoooi/shared-types generate
|
||||
*/
|
||||
|
||||
// 自動生成的 API 型別 (執行 pnpm generate 後產生)
|
||||
export * from './api-types'
|
||||
14
packages/shared-types/tsconfig.json
Normal file
14
packages/shared-types/tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user