sourcepayload

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sourcepayload enforces bounded resource use before source decoding.

Index

Constants

View Source
const MaxJSONNestingDepth = 64

MaxJSONNestingDepth bounds object/array nesting before JSON decode.

Variables

This section is empty.

Functions

func ValidateJSON

func ValidateJSON(data []byte) error

ValidateJSON enforces source byte and nesting limits before decoding.

Types

type QuarantineError

type QuarantineError struct {
	// Collection identifies the affected source collection.
	Collection string
	// Report describes the usable and quarantined records.
	Report RecordReport
}

QuarantineError reports that usable records were returned while malformed or excess siblings were quarantined.

func (*QuarantineError) Error

func (e *QuarantineError) Error() string

Error implements error.

func (*QuarantineError) Unwrap

func (e *QuarantineError) Unwrap() error

Unwrap exposes the first record error for standard errors.Is/errors.As use.

type RecordIssue

type RecordIssue struct {
	// Subject identifies the record within its collection.
	Subject string
	// Err is the typed decode or validation failure.
	Err error
}

RecordIssue describes one malformed member of an otherwise valid collection. Subject is a stable collection-relative identity and never contains raw input.

type RecordReport

type RecordReport struct {
	// Accepted is the number of successfully decoded records.
	Accepted int
	// Rejected includes malformed and excess records.
	Rejected int
	// Issues contains bounded details for malformed records.
	Issues []RecordIssue
	// Truncated reports that excess records were not decoded.
	Truncated bool
}

RecordReport describes bounded per-record decoding.

func DecodeJSONArray

func DecodeJSONArray[T any](data json.RawMessage, collection string, limit int) ([]T, RecordReport, error)

DecodeJSONArray decodes members independently after requiring a valid JSON array envelope. At most max records are decoded.

func DecodeJSONObject

func DecodeJSONObject[T any](data json.RawMessage, collection string, limit int) (map[string]T, RecordReport, error)

DecodeJSONObject decodes object values independently in sorted key order after requiring a valid JSON object envelope. At most max records are decoded.

func (RecordReport) Err

func (r RecordReport) Err(collection string) error

Err returns a typed partial-result error when records were quarantined.

type UnknownJSONField

type UnknownJSONField struct {
	Path     string `json:"path" yaml:"path"`
	Checksum string `json:"checksum" yaml:"checksum"`
}

UnknownJSONField is reviewable evidence for one additive source field that was not promoted into the typed schema.

func FingerprintValue

func FingerprintValue(path string, value any) UnknownJSONField

FingerprintValue returns path/digest evidence for an unrecognized typed value.

func UnknownJSONFields

func UnknownJSONFields(data []byte, schema any, prefix string) ([]UnknownJSONField, error)

UnknownJSONFields returns deterministic path/digest evidence for top-level JSON members not declared by schema. Raw values are intentionally omitted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL