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

javascript

package
v0.18.1 Latest Latest
Warning

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

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

Documentation

Overview

Package javascript evaluates Spectre payload normaliser scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 raw HTTP request pattern to the RPC method that types it.

func (Endpoint) Direction added in v0.13.0

func (e Endpoint) Direction() Direction

Direction returns the proxy that uses the endpoint.

func (Endpoint) Method added in v0.12.0

func (e Endpoint) Method() string

Method returns the full name of the RPC method that types the endpoint.

func (Endpoint) Pattern added in v0.12.0

func (e Endpoint) Pattern() string

Pattern returns the net/http.ServeMux pattern the endpoint matches.

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 string,
	value any,
	present bool,
) (normalised any, normalisedPresent bool, err error)

NormaliseField invokes the normaliser registered for a protobuf field.

func (*Evaluator) NormaliseMessage added in v0.11.0

func (e *Evaluator) NormaliseMessage(
	target string,
	value any,
	present bool,
) (normalised any, normalisedPresent bool, err error)

NormaliseMessage invokes the normaliser registered for a protobuf message.

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, scripts fs.FS) (*Program, error)

NewProgram parses and links every .js file in scripts, then evaluates them once in one runtime to validate their combined registrations.

func (*Program) Endpoints added in v0.12.0

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

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

func (*Program) Fields

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

Fields returns the protobuf fields declared by the scripts.

func (*Program) Messages

func (p *Program) Messages() []string

Messages returns the protobuf messages 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.

Jump to

Keyboard shortcuts

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