Package config

import "github.com/ornew/hff/config"

Generated from this checkout's Go source. Released versions are also on pkg.go.dev.

Overview

Package config encodes and decodes versioned HFF engine and PostgreSQL binding configurations as JSON. A document contains schema, capability, limit, and binding data; executable SQL translators and developer-authored trusted predicates remain in a host-owned Registry and are referenced by ID.

Encode validates and serializes existing configurations. Decode strictly validates one document and returns configurations for engine.New and sql.Build. Neither function compiles a filter or contacts a database.

A typical service decodes a saved configuration once at startup, constructs an Engine from Loaded.Engine, compiles each filter, and builds a SQL WHERE expression using Loaded.SQL. See the serialized configuration guide for a complete example and the versioned configuration design record for the wire format.

Index

Constants

Source

const MaxDocumentBytes = 4 << 20

MaxDocumentBytes bounds the encoded JSON document accepted by Decode.

Source

const MaxDocumentDepth = 512

MaxDocumentDepth bounds nested JSON arrays and objects, counting the root object as depth one.

Functions

func Encode

Source

func Encode(e engine.Config, backend sql.Config, registry Registry) ([]byte, error)

Encode serializes a validated engine configuration and its PostgreSQL bindings into deterministic version-1 JSON. Developer-authored TrustedSQL conditions must match exactly one Registry.Predicates entry; only the ID is written. Executable SQL translators are represented by declaration ID. Build still validates whether a particular Program can use the bindings.

Types

type Loaded

Source

type Loaded struct {
	Engine	engine.Config
	SQL	sql.Config
}

Loaded contains the validated engine and PostgreSQL Build configurations. Construct an Engine with engine.New(engine.WithConfig(&loaded.Engine)), then pass loaded.SQL to sql.Build with sql.WithConfig(&loaded.SQL).

func Decode

Source

func Decode(data []byte, registry Registry) (Loaded, error)

Decode parses one strict version-1 document into reusable Go configurations. Unknown versions, fields, kinds, capabilities, and registry IDs fail. It never accepts SQL source or executable functions from JSON; supplied registry entries are host-owned and must remain stable while the configurations are used. Decode does not contact a database or build a particular query.

type Registry

Source

type Registry struct {
	// Predicates resolves named developer-authored TrustedSQL conditions.
	Predicates	map[string]sql.SQLPredicate
	// Methods resolves SQL extension translators to registered Go functions.
	Methods	map[string]sql.MethodImplementation
}

Registry contains fixed host-owned implementations referenced by stable ID in a configuration document. Neither SQL source nor executable functions are read from JSON. Maps may be nil when the document uses no such IDs.

Explore HFF
Search documentation

Search the language specification and guides.