Help us shape the future of Go! Take the 2026 Go Developer Survey

javascript

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package javascript evaluates Spectre payload normaliser scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModuleDeclaration added in v0.19.0

func ModuleDeclaration() string

ModuleDeclaration returns the TypeScript declaration of the spectre module.

func WriteModuleDeclaration added in v0.19.0

func WriteModuleDeclaration(output string) error

WriteModuleDeclaration writes the module declaration to output, creating its parent directory.

Types

type Direction added in v0.13.0

type Direction string

Direction names the proxy that decodes an endpoint's traffic.

const (
	// Ingress endpoints type responses from the proxied service. Patterns omit the host.
	Ingress Direction = "ingress"
	// Egress endpoints type requests to a dependency. Patterns include its host.
	Egress Direction = "egress"
)

type Endpoint added in v0.12.0

type Endpoint struct {
	// contains filtered or unexported fields
}

Endpoint maps a protocol-specific request pattern to a payload type, or marks it ignored so matching requests are skipped instead of compared.

func (Endpoint) Direction added in v0.13.0

func (e Endpoint) Direction() Direction

Direction returns the proxy that uses the endpoint.

func (Endpoint) Ignore added in v0.23.0

func (e Endpoint) Ignore() bool

Ignore reports whether matching requests are skipped instead of compared.

func (Endpoint) Pattern added in v0.12.0

func (e Endpoint) Pattern() string

Pattern returns the protocol-specific pattern the endpoint matches.

func (Endpoint) Protocol added in v0.19.0

func (e Endpoint) Protocol() Protocol

Protocol returns the protocol key that interprets the endpoint.

func (Endpoint) Type added in v0.19.0

func (e Endpoint) Type() schema.TypeRef

Type returns the fully qualified name of the endpoint's payload type.

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator owns the JavaScript runtime for one payload normalisation. It is confined to its caller because Sobek runtime access is not synchronized.

func (*Evaluator) Close

func (e *Evaluator) Close()

Close releases the evaluator's context watcher.

func (*Evaluator) NormaliseField added in v0.11.0

func (e *Evaluator) NormaliseField(target FieldTarget, value Option[any]) (Option[any], error)

NormaliseField invokes the normaliser registered for a JSON field path. None stands for an absent field in both the argument and the result.

func (*Evaluator) NormaliseMessage added in v0.11.0

func (e *Evaluator) NormaliseMessage(target schema.TypeRef, value Option[any]) (Option[any], error)

NormaliseMessage invokes the normaliser registered for an object type. None stands for an absent message in both the argument and the result.

type FieldTarget added in v0.19.0

type FieldTarget struct {
	// contains filtered or unexported fields
}

FieldTarget identifies a JSON field path relative to an explicitly named type. The two components remain separate because namespace names can overlap field paths.

func NewFieldTarget added in v0.19.0

func NewFieldTarget(typeName schema.TypeRef, path string) FieldTarget

NewFieldTarget creates a target without resolving it against a schema.

func (FieldTarget) Path added in v0.19.0

func (t FieldTarget) Path() string

Path returns the JSON field path relative to the root type.

func (FieldTarget) String added in v0.19.0

func (t FieldTarget) String() string

String returns a human-readable target name, not a unique identity.

func (FieldTarget) Type added in v0.19.0

func (t FieldTarget) Type() schema.TypeRef

Type returns the fully qualified name of the target's root object type.

type Program

type Program struct {
	// contains filtered or unexported fields
}

Program is one immutable set of scripts, shared by all payload normalisations. It retains no runtime-local callback state.

func NewProgram

func NewProgram(ctx context.Context, evaluationTimeout time.Duration, declarations fs.FS, scripts fs.FS) (*Program, error)

NewProgram type-checks every TypeScript script against the schema declarations, links them, then evaluates them once within evaluationTimeout to collect their registrations.

func (*Program) Endpoints added in v0.12.0

func (p *Program) Endpoints(direction Direction) []Endpoint

Endpoints returns the endpoints declared for a direction, in declaration order.

func (*Program) Fields

func (p *Program) Fields() []FieldTarget

Fields returns the declared type names and JSON field paths, sorted by type then path.

func (*Program) Messages

func (p *Program) Messages() []schema.TypeRef

Messages returns the object type names declared by the scripts.

func (*Program) NewEvaluator

func (p *Program) NewEvaluator(ctx context.Context) (*Evaluator, error)

NewEvaluator creates an isolated evaluator for one payload normalisation. Re-evaluation must reproduce the registrations used to build the schema plan.

func (*Program) Schema added in v0.19.0

func (p *Program) Schema() *schema.Schema

Schema returns the payload types the scripts were checked against.

type Protocol added in v0.25.0

type Protocol string

Protocol names the protocol that scripts declare endpoints for, e.g. "http".

const ProtocolHTTP Protocol = "http"

ProtocolHTTP is the protocol of HTTP servers, including gRPC and Connect.

Jump to

Keyboard shortcuts

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