Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
var _ PrimitiveZogSchema[bool] = &BoolSchema[bool]{}

type BoolSchema[T ~bool] struct {
preTransforms []p.PreTransform
tests []p.Test
postTransforms []p.PostTransform
preTransforms []PreTransform
tests []Test
postTransforms []PostTransform
defaultVal *T
required *p.Test
required *Test
catch *T
coercer conf.CoercerFunc
coercer CoercerFunc
}

// ! INTERNALS
Expand All @@ -26,7 +26,7 @@ func (v *BoolSchema[T]) getType() zconst.ZogType {
}

// Sets the coercer for the schema
func (v *BoolSchema[T]) setCoercer(c conf.CoercerFunc) {
func (v *BoolSchema[T]) setCoercer(c CoercerFunc) {
v.coercer = c
}

Expand All @@ -44,7 +44,7 @@ func Bool(opts ...SchemaOption) *BoolSchema[bool] {
}

// Parse data into destination pointer
func (v *BoolSchema[T]) Parse(data any, dest *T, options ...ExecOption) p.ZogIssueList {
func (v *BoolSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList {
errs := p.NewErrsList()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand All @@ -66,7 +66,7 @@ func (v *BoolSchema[T]) process(ctx *p.SchemaCtx) {
}

// Validate data against schema
func (v *BoolSchema[T]) Validate(val *T, options ...ExecOption) p.ZogIssueList {
func (v *BoolSchema[T]) Validate(val *T, options ...ExecOption) ZogIssueList {
errs := p.NewErrsList()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand All @@ -90,7 +90,7 @@ func (v *BoolSchema[T]) validate(ctx *p.SchemaCtx) {

// GLOBAL METHODS

func (v *BoolSchema[T]) Test(t p.Test, options ...TestOption) *BoolSchema[T] {
func (v *BoolSchema[T]) Test(t Test, options ...TestOption) *BoolSchema[T] {
for _, opt := range options {
opt(&t)
}
Expand All @@ -107,18 +107,18 @@ func (v *BoolSchema[T]) TestFunc(testFunc p.TestFunc, options ...TestOption) *Bo
}

// Adds pretransform function to schema
func (v *BoolSchema[T]) PreTransform(transform p.PreTransform) *BoolSchema[T] {
func (v *BoolSchema[T]) PreTransform(transform PreTransform) *BoolSchema[T] {
if v.preTransforms == nil {
v.preTransforms = []p.PreTransform{}
v.preTransforms = []PreTransform{}
}
v.preTransforms = append(v.preTransforms, transform)
return v
}

// Adds posttransform function to schema
func (v *BoolSchema[T]) PostTransform(transform p.PostTransform) *BoolSchema[T] {
func (v *BoolSchema[T]) PostTransform(transform PostTransform) *BoolSchema[T] {
if v.postTransforms == nil {
v.postTransforms = []p.PostTransform{}
v.postTransforms = []PostTransform{}
}
v.postTransforms = append(v.postTransforms, transform)
return v
Expand Down
24 changes: 12 additions & 12 deletions numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type Numeric = constraints.Ordered
var _ PrimitiveZogSchema[int] = &NumberSchema[int]{}

type NumberSchema[T Numeric] struct {
preTransforms []p.PreTransform
tests []p.Test
postTransforms []p.PostTransform
preTransforms []PreTransform
tests []Test
postTransforms []PostTransform
defaultVal *T
required *p.Test
required *Test
catch *T
coercer conf.CoercerFunc
}
Expand All @@ -29,7 +29,7 @@ func (v *NumberSchema[T]) getType() zconst.ZogType {
}

// Sets the coercer for the schema
func (v *NumberSchema[T]) setCoercer(c conf.CoercerFunc) {
func (v *NumberSchema[T]) setCoercer(c CoercerFunc) {
v.coercer = c
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func Int32(opts ...SchemaOption) *NumberSchema[int32] {
}

// parses the value and stores it in the destination
func (v *NumberSchema[T]) Parse(data any, dest *T, options ...ExecOption) p.ZogIssueList {
func (v *NumberSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList {
errs := p.NewErrsList()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand All @@ -144,7 +144,7 @@ func (v *NumberSchema[T]) process(ctx *p.SchemaCtx) {
}

// Validates a number pointer
func (v *NumberSchema[T]) Validate(data *T, options ...ExecOption) p.ZogIssueList {
func (v *NumberSchema[T]) Validate(data *T, options ...ExecOption) ZogIssueList {
errs := p.NewErrsList()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand All @@ -167,18 +167,18 @@ func (v *NumberSchema[T]) validate(ctx *p.SchemaCtx) {

// GLOBAL METHODS

func (v *NumberSchema[T]) PreTransform(transform p.PreTransform) *NumberSchema[T] {
func (v *NumberSchema[T]) PreTransform(transform PreTransform) *NumberSchema[T] {
if v.preTransforms == nil {
v.preTransforms = []p.PreTransform{}
v.preTransforms = []PreTransform{}
}
v.preTransforms = append(v.preTransforms, transform)
return v
}

// Adds posttransform function to schema
func (v *NumberSchema[T]) PostTransform(transform p.PostTransform) *NumberSchema[T] {
func (v *NumberSchema[T]) PostTransform(transform PostTransform) *NumberSchema[T] {
if v.postTransforms == nil {
v.postTransforms = []p.PostTransform{}
v.postTransforms = []PostTransform{}
}
v.postTransforms = append(v.postTransforms, transform)
return v
Expand Down Expand Up @@ -215,7 +215,7 @@ func (v *NumberSchema[T]) Catch(val T) *NumberSchema[T] {
}

// custom test function call it -> schema.Test(test, options)
func (v *NumberSchema[T]) Test(t p.Test, opts ...TestOption) *NumberSchema[T] {
func (v *NumberSchema[T]) Test(t Test, opts ...TestOption) *NumberSchema[T] {
for _, opt := range opts {
opt(&t)
}
Expand Down
16 changes: 8 additions & 8 deletions pointers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
var _ ComplexZogSchema = &PointerSchema{}

type PointerSchema struct {
// preTransforms []p.PreTransform
tests []p.Test
// preTransforms []PreTransform
tests []Test
schema ZogSchema
required *p.Test
// postTransforms []p.PostTransform
required *Test
// postTransforms []PostTransform
// defaultVal *any
// catch *any
}
Expand All @@ -32,13 +32,13 @@ func (v *PointerSchema) setCoercer(c conf.CoercerFunc) {
// Ptr creates a pointer ZogSchema
func Ptr(schema ZogSchema) *PointerSchema {
return &PointerSchema{
tests: []p.Test{},
tests: []Test{},
schema: schema,
}
}

// Parse the data into the destination pointer
func (v *PointerSchema) Parse(data any, dest any, options ...ExecOption) p.ZogIssueMap {
func (v *PointerSchema) Parse(data any, dest any, options ...ExecOption) ZogIssueMap {
errs := p.NewErrsMap()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand Down Expand Up @@ -94,7 +94,7 @@ func (v *PointerSchema) process(ctx *p.SchemaCtx) {
}

// Validates a pointer pointer
func (v *PointerSchema) Validate(data any, options ...ExecOption) p.ZogIssueMap {
func (v *PointerSchema) Validate(data any, options ...ExecOption) ZogIssueMap {
errs := p.NewErrsMap()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand Down Expand Up @@ -126,7 +126,7 @@ func (v *PointerSchema) validate(ctx *p.SchemaCtx) {
// Validate Existing Pointer

func (v *PointerSchema) NotNil(options ...TestOption) *PointerSchema {
r := p.Test{
r := Test{
IssueCode: zconst.IssueCodeNotNil,
}
for _, opt := range options {
Expand Down
36 changes: 18 additions & 18 deletions slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
var _ ComplexZogSchema = &SliceSchema{}

type SliceSchema struct {
preTransforms []p.PreTransform
tests []p.Test
preTransforms []PreTransform
tests []Test
schema ZogSchema
postTransforms []p.PostTransform
required *p.Test
postTransforms []PostTransform
required *Test
defaultVal any
// catch any
coercer conf.CoercerFunc
Expand Down Expand Up @@ -49,7 +49,7 @@ func Slice(schema ZogSchema, opts ...SchemaOption) *SliceSchema {
}

// Validates a slice
func (v *SliceSchema) Validate(data any, options ...ExecOption) p.ZogIssueMap {
func (v *SliceSchema) Validate(data any, options ...ExecOption) ZogIssueMap {
errs := p.NewErrsMap()
defer errs.Free()

Expand Down Expand Up @@ -138,7 +138,7 @@ func (v *SliceSchema) validate(ctx *p.SchemaCtx) {
}

// Only supports parsing from data=slice[any] to a dest =&slice[] (this can be typed. Doesn't have to be any)
func (v *SliceSchema) Parse(data any, dest any, options ...ExecOption) p.ZogIssueMap {
func (v *SliceSchema) Parse(data any, dest any, options ...ExecOption) ZogIssueMap {
errs := p.NewErrsMap()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
Expand Down Expand Up @@ -233,18 +233,18 @@ func (v *SliceSchema) process(ctx *p.SchemaCtx) {
}

// Adds pretransform function to schema
func (v *SliceSchema) PreTransform(transform p.PreTransform) *SliceSchema {
func (v *SliceSchema) PreTransform(transform PreTransform) *SliceSchema {
if v.preTransforms == nil {
v.preTransforms = []p.PreTransform{}
v.preTransforms = []PreTransform{}
}
v.preTransforms = append(v.preTransforms, transform)
return v
}

// Adds posttransform function to schema
func (v *SliceSchema) PostTransform(transform p.PostTransform) *SliceSchema {
func (v *SliceSchema) PostTransform(transform PostTransform) *SliceSchema {
if v.postTransforms == nil {
v.postTransforms = []p.PostTransform{}
v.postTransforms = []PostTransform{}
}
v.postTransforms = append(v.postTransforms, transform)
return v
Expand Down Expand Up @@ -284,7 +284,7 @@ func (v *SliceSchema) Default(val any) *SliceSchema {
// !TESTS

// custom test function call it -> schema.Test(t z.Test, opts ...TestOption)
func (v *SliceSchema) Test(t p.Test, opts ...TestOption) *SliceSchema {
func (v *SliceSchema) Test(t Test, opts ...TestOption) *SliceSchema {
for _, opt := range opts {
opt(&t)
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (v *SliceSchema) Len(n int, options ...TestOption) *SliceSchema {
// Slice contains a specific value
func (v *SliceSchema) Contains(value any, options ...TestOption) *SliceSchema {
v.tests = append(v.tests,
p.Test{
Test{
IssueCode: zconst.IssueCodeContains,
Params: make(map[string]any, 1),
ValidateFunc: func(val any, ctx Ctx) bool {
Expand All @@ -363,8 +363,8 @@ func (v *SliceSchema) Contains(value any, options ...TestOption) *SliceSchema {
return v
}

func sliceMin(n int) p.Test {
t := p.Test{
func sliceMin(n int) Test {
t := Test{
IssueCode: zconst.IssueCodeMin,
Params: make(map[string]any, 1),
ValidateFunc: func(val any, ctx Ctx) bool {
Expand All @@ -378,8 +378,8 @@ func sliceMin(n int) p.Test {
t.Params[zconst.IssueCodeMin] = n
return t
}
func sliceMax(n int) p.Test {
t := p.Test{
func sliceMax(n int) Test {
t := Test{
IssueCode: zconst.IssueCodeMax,
Params: make(map[string]any, 1),
ValidateFunc: func(val any, ctx Ctx) bool {
Expand All @@ -393,8 +393,8 @@ func sliceMax(n int) p.Test {
t.Params[zconst.IssueCodeMax] = n
return t
}
func sliceLength(n int) p.Test {
t := p.Test{
func sliceLength(n int) Test {
t := Test{
IssueCode: zconst.IssueCodeLen,
Params: make(map[string]any, 1),
ValidateFunc: func(val any, ctx Ctx) bool {
Expand Down
Loading
Loading