mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-09-17 16:15:14 +00:00
7cda0d7896
Migrates from xarmian/pad to PerpetualSoftware/pad across the entire
repo and updates the product subtitle to "Collaborate with your AI
agents".
Go module rename
- go.mod: github.com/xarmian/pad → github.com/PerpetualSoftware/pad
- All Go imports updated across cmd/pad, internal/{cli,server,store,
models,collections,items,events,metrics,webhooks} (~130 files)
- Test fixtures with the literal repo slug ("xarmian/pad" in JSON
shapes, SSH/HTTPS git URL strings, workspace_context fixtures)
also updated, including the secondary repo entry
(xarmian/pad-web → PerpetualSoftware/pad-web — pad-web was also
moved to the org per branch context)
Docs / config
- README badges, install instructions, brew tap, Docker image, source
build path, sponsor link (sponsor link kept as personal @xarmian)
- Subtitle: "Project management for developers and AI agents." →
"Collaborate with your AI agents." (README, manifests, web layout
meta, .goreleaser homebrew description)
- CONTRIBUTING.md, SECURITY.md, skills/INSTALL.md
- .goreleaser.yaml: homebrew_casks owner, GHCR image, release github
owner, cosign cert-identity regex, comments
- .github/workflows/release.yml: tap/release comments
- deploy/k8s/deployment.yaml: container image
- docs/deployment.md: clone URL
- web/static/{site.webmanifest,manifest.json}: description
- web/src/routes/+layout.svelte: meta description + og:description
Brew tap path is PerpetualSoftware/tap/pad (CamelCase, matches
GitHub user case). GHCR image is ghcr.io/perpetualsoftware/pad
(lowercased per GHCR's URL normalization). CODEOWNERS @xarmian and
FUNDING.yml github: xarmian intentionally retained — those are the
personal maintainer / sponsor account, separate from the org repo.
Verification: go build ./..., go test ./... (all pkgs pass), web
build, and make install all clean (TASK-844, TASK-845).
143 lines
3.4 KiB
Go
143 lines
3.4 KiB
Go
package items
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/PerpetualSoftware/pad/internal/models"
|
|
)
|
|
|
|
// ValidateFields checks field values against the collection schema.
|
|
// It validates required fields are present, types are correct, and select
|
|
// values are within the allowed options. It applies defaults for missing
|
|
// optional fields, mutating the fields map in place.
|
|
func ValidateFields(fields map[string]any, schema models.CollectionSchema) error {
|
|
var errs []string
|
|
|
|
for _, def := range schema.Fields {
|
|
val, exists := fields[def.Key]
|
|
|
|
// Apply default if field is missing and a default is defined
|
|
if !exists || val == nil {
|
|
if def.Required {
|
|
if def.Default != nil {
|
|
fields[def.Key] = def.Default
|
|
continue
|
|
}
|
|
errs = append(errs, fmt.Sprintf("field %q is required", def.Key))
|
|
continue
|
|
}
|
|
if def.Default != nil {
|
|
fields[def.Key] = def.Default
|
|
}
|
|
continue
|
|
}
|
|
|
|
// Validate by type
|
|
if err := validateFieldType(def, val); err != nil {
|
|
errs = append(errs, err.Error())
|
|
}
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
return fmt.Errorf("field validation failed: %s", strings.Join(errs, "; "))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateFieldType(def models.FieldDef, val any) error {
|
|
switch def.Type {
|
|
case "text", "url":
|
|
if _, ok := val.(string); !ok {
|
|
return fmt.Errorf("field %q must be a string", def.Key)
|
|
}
|
|
case "number":
|
|
switch val.(type) {
|
|
case float64, int, int64, float32:
|
|
// ok
|
|
default:
|
|
return fmt.Errorf("field %q must be a number", def.Key)
|
|
}
|
|
case "checkbox":
|
|
if _, ok := val.(bool); !ok {
|
|
return fmt.Errorf("field %q must be a boolean", def.Key)
|
|
}
|
|
case "date":
|
|
s, ok := val.(string)
|
|
if !ok {
|
|
return fmt.Errorf("field %q must be a date string (ISO 8601)", def.Key)
|
|
}
|
|
if s != "" {
|
|
// Accept YYYY-MM-DD or full RFC3339
|
|
if _, err := time.Parse("2006-01-02", s); err != nil {
|
|
if _, err := time.Parse(time.RFC3339, s); err != nil {
|
|
return fmt.Errorf("field %q has invalid date format (expected YYYY-MM-DD or RFC3339)", def.Key)
|
|
}
|
|
}
|
|
}
|
|
case "select":
|
|
s, ok := val.(string)
|
|
if !ok {
|
|
return fmt.Errorf("field %q must be a string", def.Key)
|
|
}
|
|
if s != "" && len(def.Options) > 0 {
|
|
found := false
|
|
for _, opt := range def.Options {
|
|
if opt == s {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
return fmt.Errorf("field %q value %q is not in allowed options %v", def.Key, s, def.Options)
|
|
}
|
|
}
|
|
case "multi_select":
|
|
// Accept a slice of strings
|
|
switch v := val.(type) {
|
|
case []any:
|
|
for i, item := range v {
|
|
s, ok := item.(string)
|
|
if !ok {
|
|
return fmt.Errorf("field %q item %d must be a string", def.Key, i)
|
|
}
|
|
if len(def.Options) > 0 {
|
|
found := false
|
|
for _, opt := range def.Options {
|
|
if opt == s {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
return fmt.Errorf("field %q value %q is not in allowed options %v", def.Key, s, def.Options)
|
|
}
|
|
}
|
|
}
|
|
case []string:
|
|
for _, s := range v {
|
|
if len(def.Options) > 0 {
|
|
found := false
|
|
for _, opt := range def.Options {
|
|
if opt == s {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
return fmt.Errorf("field %q value %q is not in allowed options %v", def.Key, s, def.Options)
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
return fmt.Errorf("field %q must be an array of strings", def.Key)
|
|
}
|
|
case "relation":
|
|
if _, ok := val.(string); !ok {
|
|
return fmt.Errorf("field %q must be a string (item ID)", def.Key)
|
|
}
|
|
}
|
|
return nil
|
|
}
|