docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// 跨子图连线事务:从真实端点向共同祖先暴露端口,并在祖先画布上保存唯一逻辑边。
|
||||
package platform
|
||||
|
||||
import (
|
||||
@@ -11,11 +12,14 @@ import (
|
||||
)
|
||||
|
||||
// Endpoints name real nodes, never transient projected copies or client-created ports.
|
||||
// canvasConnectionEndpoint 引用真实所有者画布中的节点,公开请求不能把投影副本或临时端口当真实节点。
|
||||
type canvasConnectionEndpoint struct {
|
||||
Board string `json:"board_id"`
|
||||
Node string `json:"node_id"`
|
||||
Handle string `json:"handle"`
|
||||
}
|
||||
|
||||
// canvasConnectionInput 包含两端真实位置、边配置与完整参与画布版本表。
|
||||
type canvasConnectionInput struct {
|
||||
Source canvasConnectionEndpoint `json:"source"`
|
||||
Target canvasConnectionEndpoint `json:"target"`
|
||||
@@ -27,6 +31,7 @@ type canvasConnectionInput struct {
|
||||
}
|
||||
|
||||
// Paths run from a leaf board upwards to (but excluding) the coordinator.
|
||||
// connectionPath 从叶画布向协调者向上追溯,不含协调者本身;循环、过深、归档或断链都视为所有权冲突。
|
||||
func connectionPath(r *http.Request, tx *sql.Tx, project, workspace, coordinator, board string) ([]subgraphRelation, error) {
|
||||
path := []subgraphRelation{}
|
||||
seen := map[string]bool{}
|
||||
@@ -51,6 +56,7 @@ func connectionPath(r *http.Request, tx *sql.Tx, project, workspace, coordinator
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// connectionNode 查找已校验节点数组中的对象,返回引用以便后续原地追加端口。
|
||||
func connectionNode(doc map[string]any, id string) map[string]any {
|
||||
for _, value := range doc["nodes"].([]any) {
|
||||
node := value.(map[string]any)
|
||||
@@ -63,6 +69,7 @@ func connectionNode(doc map[string]any, id string) map[string]any {
|
||||
|
||||
// Reuse ports by logical endpoint, including legacy ports with non-derived IDs.
|
||||
// A derived ID collision must never retarget an existing port.
|
||||
// connectionPort 先按逻辑端点复用旧端口,否则由方向/节点/handle 派生 ID;同 ID 异目标不能覆盖。
|
||||
func connectionPort(data map[string]any, node, handle, direction string) (string, bool, error) {
|
||||
ports, _ := data["ports"].([]any)
|
||||
sum := sha256.Sum256([]byte(direction + "/" + node + "/" + handle))
|
||||
@@ -85,6 +92,7 @@ func connectionPort(data map[string]any, node, handle, direction string) (string
|
||||
return id, true, nil
|
||||
}
|
||||
|
||||
// exposeConnectionEndpoint 逐层把真实端点转成父 frame 的 port 端点,返回祖先映射及实际新增端口清单。
|
||||
func exposeConnectionEndpoint(endpoint canvasConnectionEndpoint, direction string, path []subgraphRelation, documents map[string]map[string]any) (canvasConnectionEndpoint, []any, error) {
|
||||
node := connectionNode(documents[endpoint.Board], endpoint.Node)
|
||||
if node == nil {
|
||||
@@ -117,6 +125,7 @@ func exposeConnectionEndpoint(endpoint canvasConnectionEndpoint, direction strin
|
||||
return endpoint, created, nil
|
||||
}
|
||||
|
||||
// createCanvasConnection 校验 v2、幂等键与编辑权限后收集参与者;所有快照校验通过才开始持久化。
|
||||
func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request, project, account string) error {
|
||||
if r.Method != http.MethodPost {
|
||||
reject(w, 405, "method_not_allowed")
|
||||
@@ -176,6 +185,7 @@ func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request,
|
||||
reject(w, 403, "forbidden")
|
||||
return nil
|
||||
}
|
||||
// 在已授权且持锁后先重放相同请求回执,避免重试因版本已推进而误判冲突。
|
||||
action, hash := "create_connection", payloadDigest(input)
|
||||
done, err := transactionRetry(w, r, tx, project, account, coordinator, action, key, hash)
|
||||
if err != nil || done {
|
||||
@@ -211,6 +221,7 @@ func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
}
|
||||
// Require the lowest common ancestor, so the logical edge has one owner.
|
||||
// 两侧路径在协调者以下不得还有共同子画布,否则协调者不是最低共同祖先,边会放错所有者。
|
||||
left := map[string]bool{}
|
||||
for _, relation := range paths[0] {
|
||||
left[relation.Child] = true
|
||||
@@ -225,6 +236,7 @@ func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request,
|
||||
for id := range participants {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
// 稳定排序参与者,生成可重复的版本要求、快照与事务记录。
|
||||
sort.Strings(ids)
|
||||
before := []canvasSnapshot{}
|
||||
snapshots := map[string]canvasSnapshot{}
|
||||
@@ -250,6 +262,7 @@ func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
documents[id] = doc
|
||||
}
|
||||
// 版本表必须恰好覆盖所有参与者,缺漏返回 required_board_ids,陈旧版本返回 412。
|
||||
if len(input.Expected) != len(ids) {
|
||||
reply(w, 428, response{"error": "version_required", "details": response{"required_board_ids": ids}})
|
||||
return nil
|
||||
@@ -293,6 +306,7 @@ func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request,
|
||||
mapped = append(mapped, exposed)
|
||||
created = append(created, ports...)
|
||||
}
|
||||
// 保存的是映射后祖先端点,但回执同时保留原始 source/target,供调用方恢复逻辑身份。
|
||||
edge := map[string]any{"id": input.Edge.ID, "source": mapped[0].Node, "sourceHandle": mapped[0].Handle, "target": mapped[1].Node, "targetHandle": mapped[1].Handle}
|
||||
if input.Edge.Data != nil {
|
||||
edge["data"] = input.Edge.Data
|
||||
@@ -336,6 +350,7 @@ func (s *service) createCanvasConnection(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
result := response{"transaction_id": id, "parent": snapshots[coordinator], "snapshots": updated, "connection": response{"board_id": coordinator, "edge": edge, "source": input.Source, "target": input.Target}, "created_ports": created, "undo_receipt": response{"transaction_id": id, "valid_for_seconds": 604800, "expires_at": expiry}}
|
||||
encoded, _ := json.Marshal(result)
|
||||
// before 快照和 after_versions 支持七天撤销;响应体与幂等摘要一同入库,提交后才对外确认。
|
||||
prior, _ := json.Marshal(before)
|
||||
after, _ := json.Marshal(versions)
|
||||
_, err = tx.ExecContext(r.Context(), `INSERT INTO canvas_transactions(project,workspace_id,board_id,id,account_id,action,idempotency_key,payload_hash,response_status,response_body,before_state,after_versions) VALUES($1,$2,$3,$4,$5,$6,$7,$8,201,$9,$10,$11)`, project, workspace, coordinator, id, account, action, key, hash, encoded, prior, after)
|
||||
|
||||
Reference in New Issue
Block a user