mock

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package mock provides mock data sources for testing and development.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompileOptions

type CompileOptions struct {
	ConfigDir   string
	Helpers     *js.CompiledHelpers
	ValueParser *ValueParser // Global CSV value parser
}

CompileOptions contains options for compiling mock sources.

type Source

type Source interface {
	// Data returns the mock data.
	// For JS: executes the function with ctx, sql, input, tc (transform context)
	// For static sources: returns the pre-parsed data (ctx unchanged, tc ignored)
	Data(ctx map[string]any, sql string, input map[string]any, tc *js.TransformContext) (any, map[string]any, error)
}

Source represents a mock data source.

func Compile

func Compile(m *config.Mock, opts CompileOptions) (Source, error)

Compile compiles a Mock into a Source.

type ValueParser

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

ValueParser parses CSV cell values using custom JavaScript.

func CompileValueParser

func CompileValueParser(jsCode string, helpers *js.CompiledHelpers) (*ValueParser, error)

CompileValueParser compiles a custom value parser from inline JavaScript code.

func (*ValueParser) Parse

func (p *ValueParser) Parse(value string) (any, error)

Parse parses a single cell value using the custom JS. Execution is limited to JSTimeout to prevent infinite loops.

Jump to

Keyboard shortcuts

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