Documentation
¶
Overview ¶
Package parser validates and transforms Lambda payloads using typed schemas.
Index ¶
- func Parse[T any](ctx context.Context, input any, schema Schema[T]) (T, error)
- func WrapHandler[I, T, R any](schema Schema[T], handler func(context.Context, T) (R, error)) func(context.Context, I) (R, error)
- func WrapSafeHandler[I, T, R any](schema Schema[T], handler func(context.Context, Result[T]) (R, error)) func(context.Context, I) (R, error)
- type Field
- type Issue
- type ObjectSchema
- func (s *ObjectSchema) Extend(fields ...Field) *ObjectSchema
- func (s *ObjectSchema) Omit(names ...string) *ObjectSchema
- func (s *ObjectSchema) Validate(ctx context.Context, input any) (any, []Issue, error)
- func (s *ObjectSchema) ValidateSafe(ctx context.Context, input any) (any, []Issue, error)
- func (s *ObjectSchema) WithUnknownFields(policy UnknownFields) *ObjectSchema
- type ParseError
- type Result
- type SafeSchema
- type Schema
- func Any[T any](schema Schema[T]) Schema[any]
- func Array[T any](schema Schema[T], minimum ...int) Schema[[]T]
- func Base64Encoded[T any](schema Schema[T]) Schema[T]
- func Boolean() Schema[any]
- func Dictionary(schema Schema[any]) Schema[any]
- func DynamoDBMarshalled[T any](schema Schema[T]) Schema[T]
- func Enum(values ...string) Schema[any]
- func JSONStringified[T any](schema Schema[T]) Schema[T]
- func Literal(value any) Schema[any]
- func Null() Schema[any]
- func Nullable[T any](schema Schema[T]) Schema[any]
- func Number() Schema[any]
- func Pipe[A, B any](first Schema[A], next Schema[B]) Schema[B]
- func Refine[T any](schema Schema[T], predicate func(T) bool, message string) Schema[T]
- func String() Schema[any]
- func Transform[A, B any](schema Schema[A], convert func(context.Context, A) (B, error)) Schema[B]
- func Typed[T any](schema Schema[any]) Schema[T]
- func Union(schemas ...Schema[any]) Schema[any]
- func Unknown() Schema[any]
- type SchemaFunc
- type UnknownFields
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WrapHandler ¶
func WrapHandler[I, T, R any](schema Schema[T], handler func(context.Context, T) (R, error)) func(context.Context, I) (R, error)
WrapHandler parses before calling the business handler and preserves shared invocation identity. Context, operational errors and panics are not replaced.
Types ¶
type Field ¶
type Field struct {
Name string
Schema Schema[any]
Optional bool
// contains filtered or unexported fields
}
Field retains declaration order, including validation issue order. Optional distinguishes absence from null. WithDefault applies only to absent values.
func (Field) WithDefault ¶
type Issue ¶
type Issue struct {
Message string `json:"message"`
Path []any `json:"path,omitempty"`
Code string `json:"code,omitempty"`
Expected string `json:"expected,omitempty"`
Errors [][]Issue `json:"errors,omitempty"`
// Continuable marks a check failure that preserves the parsed value's type.
// It controls union/refinement evaluation and is not part of serialized errors.
Continuable bool `json:"-"`
}
Issue maps Standard Schema's message/path contract. Code and Expected retain useful built-in diagnostics without requiring a specific validation engine.
type ObjectSchema ¶
type ObjectSchema struct {
// contains filtered or unexported fields
}
func Object ¶
func Object(fields ...Field) *ObjectSchema
func (*ObjectSchema) Extend ¶
func (s *ObjectSchema) Extend(fields ...Field) *ObjectSchema
func (*ObjectSchema) Omit ¶
func (s *ObjectSchema) Omit(names ...string) *ObjectSchema
Omit returns a schema without the named fields, retaining validation order.
func (*ObjectSchema) ValidateSafe ¶
func (*ObjectSchema) WithUnknownFields ¶
func (s *ObjectSchema) WithUnknownFields(policy UnknownFields) *ObjectSchema
type ParseError ¶
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type Result ¶
type Result[T any] struct { Success bool Data T Error *ParseError OriginalEvent any }
Result includes the original event only on validation failure. The event is retained by reference, as in the reference safeParse contract.
type SafeSchema ¶
SafeSchema optionally aggregates additional envelope failures in safe mode.
type Schema ¶
Schema returns nil issues for success. A non-nil slice, including an empty slice, denotes validation failure. Unexpected errors propagate even in safe parsing, matching a thrown Standard Schema validator exception.
func Base64Encoded ¶
Base64Encoded follows the reference's gzip-JSON, JSON, then UTF-8 text fallback. Malformed Base64 errors propagate rather than becoming schema issues.
func DynamoDBMarshalled ¶
DynamoDBMarshalled decodes raw AttributeValue objects before schema validation. Raw binary values and large integers retain the Commons conversion contract.
func JSONStringified ¶
func Typed ¶
Typed converts validated output using ordinary Go JSON tags and types. Schema transforms run before decoding; incompatible output types are operational errors.
type SchemaFunc ¶
type UnknownFields ¶
type UnknownFields uint8
const ( StripUnknown UnknownFields = iota PreserveUnknown RejectUnknown )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package envelopes validates Lambda envelopes and extracts typed payloads.
|
Package envelopes validates Lambda envelopes and extracts typed payloads. |
|
Package schemas contains reference-derived Lambda event schemas.
|
Package schemas contains reference-derived Lambda event schemas. |