payload

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

README

payload

import "github.com/agentstation/starmap/pkg/sources/payload"

Package payload enforces bounded resource use before source decoding.

Index

Constants

const (
    // MaxBytes bounds one provider or catalog source JSON payload.
    MaxBytes = 16 << 20
    // MaxJSONNestingDepth bounds object/array nesting before JSON decode.
    MaxJSONNestingDepth = 64
)

func ValidateJSON

func ValidateJSON(data []byte) error

ValidateJSON enforces source byte and nesting limits before decoding.

type QuarantineError

QuarantineError reports a partial result with usable records and quarantined malformed or excess siblings.

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

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

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

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

type RecordReport

RecordReport describes bounded per-record decoding.

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
}

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

DecodeJSONArray requires a valid JSON array envelope, then decodes each member independently. It decodes at most max records.

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

DecodeJSONObject requires a valid JSON object envelope, then decodes values independently in sorted key order. It decodes at most max records.

func (RecordReport) Err
func (r RecordReport) Err(collection string) error

Err returns a typed partial-result error when the report contains quarantined records.

type UnknownJSONField

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

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

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.

Generated by gomarkdoc

Documentation

Overview

Package payload enforces bounded resource use before source decoding.

Index

Constants

View Source
const (
	// MaxBytes bounds one provider or catalog source JSON payload.
	MaxBytes = 16 << 20
	// MaxJSONNestingDepth bounds object/array nesting before JSON decode.
	MaxJSONNestingDepth = 64
)

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 a partial result with usable records and quarantined malformed or excess siblings.

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 requires a valid JSON array envelope, then decodes each member independently. It decodes at most max records.

func DecodeJSONObject

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

DecodeJSONObject requires a valid JSON object envelope, then decodes values independently in sorted key order. It decodes at most max records.

func (RecordReport) Err

func (r RecordReport) Err(collection string) error

Err returns a typed partial-result error when the report contains quarantined records.

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