feat: publish immutable workflow definitions with typed SDK

This commit is contained in:
2026-09-18 00:28:00 +08:00
parent a664ec9370
commit 520e98d9d1
33 changed files with 2603 additions and 11 deletions

View File

@@ -233,7 +233,7 @@ func writeError(w http.ResponseWriter, id string, err error) {
if !errors.As(err, &known) {
known = fault.Unavailable
}
status := map[string]int{"INVALID_ARGUMENT": 400, "UNAUTHENTICATED": 401, "PERMISSION_DENIED": 403, "NOT_FOUND": 404, "STATE_CONFLICT": 409, "IDEMPOTENCY_CONFLICT": 409, "BODY_TOO_LARGE": 413, "UNSUPPORTED_MEDIA_TYPE": 415, "DELIVERY_LEASE_LOST": 409, "EVENT_HISTORY_EXPIRED": 410, "SUBSCRIPTION_LIMIT": 409}[known.Code]
status := map[string]int{"INVALID_ARGUMENT": 400, "UNAUTHENTICATED": 401, "PERMISSION_DENIED": 403, "NOT_FOUND": 404, "STATE_CONFLICT": 409, "IDEMPOTENCY_CONFLICT": 409, "BODY_TOO_LARGE": 413, "UNSUPPORTED_MEDIA_TYPE": 415, "DELIVERY_LEASE_LOST": 409, "EVENT_HISTORY_EXPIRED": 410, "SUBSCRIPTION_LIMIT": 409, "WORKFLOW_DEFINITION_LIMIT": 409, "WORKFLOW_VERSION_LIMIT": 409}[known.Code]
if status == 0 {
status = 503
}
@@ -299,6 +299,18 @@ func exactFields(raw []byte, t reflect.Type) error {
}
return nil
}
if t.Kind() == reflect.Map {
var values map[string]json.RawMessage
if err := json.Unmarshal(raw, &values); err != nil {
return err
}
for _, value := range values {
if err := exactFields(value, t.Elem()); err != nil {
return err
}
}
return nil
}
if t.Kind() != reflect.Struct {
return nil
}
@@ -307,11 +319,13 @@ func exactFields(raw []byte, t reflect.Type) error {
return err
}
names := map[string]reflect.Type{}
nullable := map[string]bool{}
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
name := strings.Split(field.Tag.Get("json"), ",")[0]
if name != "" && name != "-" {
names[name] = field.Type
nullable[name] = field.Tag.Get("nullable") == "true"
if field.Tag.Get("required") == "true" {
if _, ok := object[name]; !ok {
return errors.New("missing required field")
@@ -324,6 +338,9 @@ func exactFields(raw []byte, t reflect.Type) error {
if !ok {
return errors.New("unknown field")
}
if nullable[name] && bytes.Equal(bytes.TrimSpace(value), []byte("null")) {
continue
}
if err := exactFields(value, field); err != nil {
return err
}