JSONL IaC
規劃、套用、檢視狀態、匯出宣告式 JSONL,並取得其 typed authored contract,同時掌握命名空間與破壞性變更。
iac.contract 是三種 scope 各自經驗證的 GET .../tables/iac/contract 路由:
/private/module/custom_tables/chatroom/{chatroom_id}/tables/iac/contract/private/module/custom_tables/department/{department_id}/tables/iac/contract/private/module/custom_tables/company/tables/iac/contract
它回傳 IacDocumentContractResponse,欄位為 version、kinds、resource_types 與 line。Runtime line 是一條合法的 header 範例;OpenAPI response schema 則帶出完整的 discriminated IacLine union,補上原始 JSONL plan/apply request body 無法呈現的型別契約。
/private/module/custom_tables/{scope}/tables/iac/contract回傳 authored kind、managed resource 清單與 typed IacLine carrier,讓 OpenAPI 暴露完整 discriminated union。
建立 raw JSONL plan/apply body 的 editor、validator 或 client 時使用。
- 聊天室
/private/module/custom_tables/chatroom/{chatroom_id}/tables/iac/contract - 部門
/private/module/custom_tables/department/{department_id}/tables/iac/contract - 公司
/private/module/custom_tables/company/tables/iac/contract
範圍
| 範圍 | 是否提供 | 驗證與權限 |
|---|---|---|
| 聊天室 | 可使用 | ChatRoomAccessRequired |
| 部門 | 可使用 | DepartmentAccessRequired |
| 公司 | 可使用 | CompanyAccessRequired |
回應結構
IacDocumentContractResponse| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
kinds | ("header" | "table" | "column" | "rule" | "trigger" | "view" | "grant" | "client_access" | "record" | "command" | "insight_selection" | "public_read")[] | 是 | 未指定 |
line | IacHeaderLine | IacTableLine | IacColumnLine | IacRuleLine | IacTriggerLine | IacViewLine | IacGrantLine | IacClientAccessLine | IacRecordLine | IacCommandLine | IacInsightSelectionLine | IacPublicReadLine | 是 | Optional first line of a JSONL doc: version + state namespace (spec §3.1). |
resource_types | ("table" | "column" | "rule" | "trigger" | "view" | "grant" | "client_access" | "command" | "insight_selection" | "public_read")[] | 是 | 未指定 |
version | integer | 否 | 未指定 |
範例
讀取 IaC union carrier
{
"pathParams": {
"chatroom_id": "11111111-1111-4111-8111-111111111111"
}
}{
"version": 1,
"kinds": [
"header",
"table",
"column",
"rule",
"trigger",
"view",
"grant",
"client_access",
"record",
"command",
"insight_selection",
"public_read"
],
"resource_types": [
"table",
"column",
"rule",
"trigger",
"view",
"grant",
"client_access",
"command",
"insight_selection",
"public_read"
],
"line": {
"kind": "header",
"version": 1,
"system": "",
"description": ""
}
}錯誤
| 狀態 | 發生條件 | 錯誤本文 |
|---|---|---|
| 403 | 呼叫者無法存取指定的聊天室、部門或公司 scope。 | |
/private/module/custom_tables/{scope}/tables/iac/plan解析並驗證宣告式 JSONL 文件,和現行資源比對差異,再回傳逐行動作與計畫雜湊。
每次套用前都先執行,讓人員或自動化流程檢查建立、更新、改名、刪除、漂移與警告。
- 聊天室
/private/module/custom_tables/chatroom/{chatroom_id}/tables/iac/plan - 部門
/private/module/custom_tables/department/{department_id}/tables/iac/plan - 公司
/private/module/custom_tables/company/tables/iac/plan
範圍
| 範圍 | 是否提供 | 驗證與權限 |
|---|---|---|
| 聊天室 | 可使用 | ChatRoomAccessRequired |
| 部門 | 可使用 | DepartmentAccessRequired |
| 公司 | 可使用 | CompanyAccessRequired |
回應結構
IacPlanResponse| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
actions | IacPlanAction[] | 否 | Per-line planned actions. |
errors | IacLineError[] | 否 | Doc-level parse/validate errors. |
plan_hash | string | 是 | sha256 fingerprint pinning apply to this reviewed plan (spec §6). |
summary | IacPlanSummary | 是 | Counts per action type. |
範例
規劃一張資料表與其自然鍵欄位
{
"pathParams": {
"chatroom_id": "11111111-1111-4111-8111-111111111111"
},
"body": "{\"kind\":\"header\",\"version\":1,\"system\":\"catalog-demo\",\"description\":\"Catalog example\"}\n{\"kind\":\"table\",\"ref\":\"orders\",\"spec\":{\"name\":\"IaC orders\",\"description\":\"Orders managed from JSONL\",\"key\":\"order_no\"}}\n{\"kind\":\"column\",\"table\":\"orders\",\"ref\":\"order_no\",\"spec\":{\"name\":\"Order number\",\"type\":\"string\",\"required\":true}}"
}{
"plan_hash": "9a1b2c3d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcdef",
"summary": {
"create": 2,
"adopt": 0,
"move": 0,
"update": 0,
"noop": 0,
"delete": 0,
"orphaned": 0,
"insert": 0,
"skip": 0
},
"actions": [
{
"line": 2,
"kind": "table",
"ref": "orders",
"action": "create",
"adopted": false,
"changes": [],
"drifted_fields": [],
"warnings": [],
"errors": []
},
{
"line": 3,
"kind": "column",
"ref": "orders.order_no",
"action": "create",
"adopted": false,
"changes": [],
"drifted_fields": [],
"warnings": [],
"errors": []
}
],
"errors": []
}錯誤
| 狀態 | 發生條件 | 錯誤本文 |
|---|---|---|
| 400 | 文件空白或格式錯誤,或超過位元組、行數、資料表或資料列上限。IaC 無條件可用,不存在 feature-disabled 分支。 | |
| 400 | 某一實體 JSONL 行的 `[`/`{` 巢狀超過 128 層。量測涵蓋整行(含 line envelope),字串字面值內的括號不計;比較是嚴格大於,因此 128 通過、129 中止。這個上限寫死在程式裡,不是 `CUSTOM_TABLE_IAC_MAX_*` 那組環境變數之一。 | |
/private/module/custom_tables/{scope}/tables/iac/apply重新計算計畫、核對已審閱的指紋,再依文件順序執行可套用的各行。
確認計畫仍是最新版本,且接受其中所有破壞性或漂移修正動作後才使用。
- 聊天室
/private/module/custom_tables/chatroom/{chatroom_id}/tables/iac/apply - 部門
/private/module/custom_tables/department/{department_id}/tables/iac/apply - 公司
/private/module/custom_tables/company/tables/iac/apply
範圍
| 範圍 | 是否提供 | 驗證與權限 |
|---|---|---|
| 聊天室 | 可使用 | ChatRoomAccessRequired |
| 部門 | 可使用 | DepartmentAccessRequired |
| 公司 | 可使用 | CompanyAccessRequired |
參數
| 欄位 | 位置 | 型別 | 必填 | 說明 |
|---|---|---|---|---|
plan_hash | query | sha256 | 否 | plan 回傳的 sha256 plan_hash。若不一致會回傳 409 plan_stale;請傳入此值來鎖定審閱過的計畫。 |
idempotency_key | query | string | 否 | 非同步票證流程可用的 24 小時防重複鍵;同步套用時會忽略。 |
worker | query | enum:legacy|batch|sqs|pubsub | 否 | 只有資料量觸發非同步套用時,才會使用這個背景執行器。 |
範例
套用已審閱的資料表建立計畫
{
"pathParams": {
"chatroom_id": "11111111-1111-4111-8111-111111111111"
},
"query": {
"plan_hash": "9a1b2c3d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcdef",
"worker": "legacy"
},
"body": "{\"kind\":\"header\",\"version\":1,\"system\":\"catalog-demo\",\"description\":\"Catalog example\"}\n{\"kind\":\"table\",\"ref\":\"orders\",\"spec\":{\"name\":\"IaC orders\",\"description\":\"Orders managed from JSONL\",\"key\":\"order_no\"}}\n{\"kind\":\"column\",\"table\":\"orders\",\"ref\":\"order_no\",\"spec\":{\"name\":\"Order number\",\"type\":\"string\",\"required\":true}}"
}{
"applied": {
"create": 2,
"adopt": 0,
"move": 0,
"update": 0,
"noop": 0,
"delete": 0,
"orphaned": 0,
"insert": 0,
"skip": 0
},
"results": [
{
"line": 2,
"kind": "table",
"ref": "orders",
"action": "create",
"adopted": false,
"changes": [],
"drifted_fields": [],
"warnings": [],
"errors": [],
"applied": true
},
{
"line": 3,
"kind": "column",
"ref": "orders.order_no",
"action": "create",
"adopted": false,
"changes": [],
"drifted_fields": [],
"warnings": [],
"errors": [],
"applied": true
}
],
"errors": []
}錯誤
| 狀態 | 發生條件 | 錯誤本文 |
|---|---|---|
| 400 | JSONL 文件空白、格式錯誤或超過 parse-time cap;在比對 plan、dispatch 或 mutation 之前就會失敗。 | |
| 404 | 指定的聊天室、部門或公司 scope 不存在,或呼叫者無法存取。 | |
| 409 | 審閱後文件或現行資源已有變更,導致重新計算的計畫雜湊不同。 | |
| 422 | 重新計算的計畫含驗證錯誤,因此不會執行任何動作。 | |
/private/module/custom_tables/{scope}/tables/iac/state回傳單一命名空間內受管理的資料表、欄位、規則、觸發器、檢視、授權與用戶端存取清冊,並鎖定目前範圍。
適合用來稽核資源歸屬、診斷孤立 ref,或確認先前 apply 納管了哪些資源。
- 聊天室
/private/module/custom_tables/chatroom/{chatroom_id}/tables/iac/state - 部門
/private/module/custom_tables/department/{department_id}/tables/iac/state - 公司
/private/module/custom_tables/company/tables/iac/state
範圍
| 範圍 | 是否提供 | 驗證與權限 |
|---|---|---|
| 聊天室 | 可使用 | ChatRoomAccessRequired |
| 部門 | 可使用 | DepartmentAccessRequired |
| 公司 | 可使用 | CompanyAccessRequired |
參數
| 欄位 | 位置 | 型別 | 必填 | 說明 |
|---|---|---|---|---|
system | query | string <= 100 | 否 | 來自 header.system 的狀態命名空間;省略或傳入空字串可查詢無文件命名空間的狀態。 |
回應結構
IacStateResponse| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
rows | IacStateRowResponse[] | 否 | Managed inventory for the queried system. |
total | integer | 是 | Number of rows. |
範例
列出單一 system 的受管理資源
{
"pathParams": {
"chatroom_id": "11111111-1111-4111-8111-111111111111"
},
"query": {
"system": "catalog-demo"
}
}{
"rows": [
{
"system": "catalog-demo",
"resource_type": "table",
"ref": "orders",
"resource_id": "22222222-2222-4222-8222-222222222222",
"table_id": null,
"updated_at": "2026-07-19T02:20:00Z"
},
{
"system": "catalog-demo",
"resource_type": "column",
"ref": "orders.order_no",
"resource_id": "col_33333333_3333_4333_8333_333333333333",
"table_id": "22222222-2222-4222-8222-222222222222",
"updated_at": "2026-07-19T02:20:00Z"
}
],
"total": 2
}/private/module/custom_tables/{scope}/tables/iac/export從受管理的 system、明確指定的資料表集合或整個範圍,產生內容固定且已遮蔽秘密資訊的 IaC 文件。
適合用於備份、審閱、移轉,或作為可再次匯入的宣告式文件起點。
- 聊天室
/private/module/custom_tables/chatroom/{chatroom_id}/tables/iac/export - 部門
/private/module/custom_tables/department/{department_id}/tables/iac/export - 公司
/private/module/custom_tables/company/tables/iac/export
範圍
| 範圍 | 是否提供 | 驗證與權限 |
|---|---|---|
| 聊天室 | 可使用 | ChatRoomAccessRequired |
| 部門 | 可使用 | DepartmentAccessRequired |
| 公司 | 可使用 | CompanyAccessRequired |
參數
| 欄位 | 位置 | 型別 | 必填 | 說明 |
|---|---|---|---|---|
system | query | string <= 100 | 否 | 要匯出的受管理 system 或標籤名稱;系統會合併狀態清冊與同名標籤中的資料表。 |
table_ids | query | list[uuid] | 否 | 明確指定要匯出的資料表 UUID;多張資料表請重複使用 table_ids query key。 |
include_records | query | boolean | 否 | 設為 true 時,替每張資料表加入最多 CUSTOM_TABLE_IAC_MAX_RECORDS 筆種子 record 行。 |
範例
匯出單一 system,但不包含資料列
{
"pathParams": {
"chatroom_id": "11111111-1111-4111-8111-111111111111"
},
"query": {
"system": "catalog-demo",
"include_records": "false"
}
}"{\"kind\":\"header\",\"version\":1,\"system\":\"catalog-demo\",\"description\":\"\"}\n{\"kind\":\"table\",\"ref\":\"orders\",\"spec\":{\"name\":\"IaC orders\",\"description\":\"Orders managed from JSONL\",\"key\":\"order_no\"}}\n{\"kind\":\"column\",\"table\":\"orders\",\"ref\":\"order_no\",\"spec\":{\"name\":\"Order number\",\"type\":\"string\",\"required\":true}}\n"錯誤
| 狀態 | 發生條件 | 錯誤本文 |
|---|---|---|
| 400 | 指定的資料表無效、參照資料表無法解析,或匯出內容會超過設定上限。IaC 無條件可用,不存在 feature-disabled 分支。 | |