Skip to content

Commit

Permalink
feat: number schema now supports any number (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oudwins authored Feb 22, 2025
1 parent 0e57a5b commit 6af9605
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions internals/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package internals

import "time"
import (
"time"

"golang.org/x/exp/constraints"
)

// takes the data as input and returns the new data which will then be passed onto the next functions. If the function returns an error all validation will be skipped & the error will be returned. You may return a ZogIssue or an error. If its an error it will be wraped inside a ZogIssue
type PreTransform = func(data any, ctx Ctx) (out any, err error)
Expand All @@ -10,5 +14,5 @@ type PostTransform = func(dataPtr any, ctx Ctx) error

// Primitive types that can be used in Zod schemas
type ZogPrimitive interface {
~string | ~int | ~int64 | ~int32 | ~float64 | ~float32 | ~bool | time.Time
~string | ~bool | time.Time | constraints.Ordered
}
5 changes: 2 additions & 3 deletions numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"github.com/Oudwins/zog/conf"
p "github.com/Oudwins/zog/internals"
"github.com/Oudwins/zog/zconst"
"golang.org/x/exp/constraints"
)

type Numeric interface {
~int | ~int64 | ~int32 | ~float64 | ~float32
}
type Numeric = constraints.Ordered

var _ PrimitiveZogSchema[int] = &NumberSchema[int]{}

Expand Down

0 comments on commit 6af9605

Please sign in to comment.