engine

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleCapture

type ConsoleCapture struct {
	Log   func(...interface{})
	Error func(...interface{})
	Info  func(...interface{})
	Warn  func(...interface{})
	Debug func(...interface{})
}

ConsoleCapture holds original console functions and captured output

type DatabaseOperation

type DatabaseOperation struct {
	Timestamp    time.Time     `json:"timestamp"`
	Type         string        `json:"type"` // "query" or "exec"
	SQL          string        `json:"sql"`
	Parameters   interface{}   `json:"parameters,omitempty"`
	Result       interface{}   `json:"result,omitempty"`
	Error        string        `json:"error,omitempty"`
	Duration     time.Duration `json:"duration"`
	RowsAffected int64         `json:"rowsAffected,omitempty"`
	LastInsertId int64         `json:"lastInsertId,omitempty"`
}

DatabaseOperation represents a database operation during request processing

type Engine

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

Engine wraps the JavaScript runtime and data repositories

func NewEngine

func NewEngine(appDBPath, systemDBPath string) *Engine

NewEngine creates a new JavaScript engine with separate application and system databases

func (*Engine) GetFileHandler

func (e *Engine) GetFileHandler(path string) (goja.Callable, bool)

GetFileHandler returns a registered file handler

func (*Engine) GetGlobalState

func (e *Engine) GetGlobalState() string

GetGlobalState returns the current globalState object as JSON string

func (*Engine) GetHandler

func (e *Engine) GetHandler(method, path string) (*HandlerInfo, bool)

GetHandler returns a registered HTTP handler, supporting path parameters

func (*Engine) GetRepositoryManager

func (e *Engine) GetRepositoryManager() repository.RepositoryManager

GetRepositoryManager returns the repository manager

func (*Engine) GetRequestLogger

func (e *Engine) GetRequestLogger() *RequestLogger

GetRequestLogger returns the request logger for admin interface

func (*Engine) Init

func (e *Engine) Init(filename string) error

Init loads and executes a bootstrap JavaScript file

func (*Engine) SetGlobalState

func (e *Engine) SetGlobalState(jsonData string) error

SetGlobalState sets the globalState object from a JSON string

func (*Engine) StartDispatcher

func (e *Engine) StartDispatcher()

StartDispatcher starts the job processing dispatcher

func (*Engine) SubmitJob

func (e *Engine) SubmitJob(job EvalJob)

SubmitJob submits a job to the dispatcher

type EvalJob

type EvalJob struct {
	Handler   *HandlerInfo        // pre-registered handler info (nil for direct code execution)
	Code      string              // JavaScript code to execute
	W         http.ResponseWriter // response writer
	R         *http.Request       // request
	Done      chan error          // completion signal
	Result    chan *EvalResult    // result channel for capturing execution results
	SessionID string              // session identifier for tracking
	Source    string              // source of execution ('api', 'mcp', 'file')
}

EvalJob represents a JavaScript evaluation job

type EvalResult

type EvalResult struct {
	Value      interface{} `json:"value"`           // The actual result value
	ConsoleLog []string    `json:"consoleLog"`      // Captured console output
	Error      error       `json:"error,omitempty"` // Execution error if any
}

EvalResult contains the result of JavaScript execution

type ExpressRequest

type ExpressRequest struct {
	Method   string                 `json:"method"`
	URL      string                 `json:"url"`
	Path     string                 `json:"path"`
	Query    map[string]interface{} `json:"query"`
	Headers  map[string]interface{} `json:"headers"`
	Body     interface{}            `json:"body"`
	Cookies  map[string]string      `json:"cookies"`
	IP       string                 `json:"ip"`
	Protocol string                 `json:"protocol"`
	Hostname string                 `json:"hostname"`
	Params   map[string]string      `json:"params"`
}

ExpressRequest represents an Express.js compatible request object

type ExpressResponse

type ExpressResponse struct {
	StatusCode int               `json:"statusCode"`
	Headers    map[string]string `json:"headers"`
	Cookies    []*http.Cookie    `json:"cookies"`
	// contains filtered or unexported fields
}

ExpressResponse represents an Express.js compatible response object

func (*ExpressResponse) Cookie

func (r *ExpressResponse) Cookie(name, value string, options ...interface{}) *ExpressResponse

Cookie sets a response cookie

func (*ExpressResponse) End

func (r *ExpressResponse) End(data ...interface{}) error

End ends the response

func (*ExpressResponse) Json

func (r *ExpressResponse) Json(data interface{}) error

JSON sends a JSON response

func (*ExpressResponse) Redirect

func (r *ExpressResponse) Redirect(args ...interface{}) error

Redirect redirects the request

func (*ExpressResponse) Send

func (r *ExpressResponse) Send(data interface{}) error

Send sends a response

func (*ExpressResponse) Set

func (r *ExpressResponse) Set(name, value string) *ExpressResponse

Set sets a response header

func (*ExpressResponse) Status

func (r *ExpressResponse) Status(code interface{}) *ExpressResponse

Status sets the HTTP status code

type HTTPRequest

type HTTPRequest struct {
	URL     string                 `json:"url"`
	Method  string                 `json:"method"`
	Headers map[string]string      `json:"headers"`
	Body    interface{}            `json:"body"`
	Query   map[string]interface{} `json:"query"`
	Timeout int                    `json:"timeout"` // seconds
}

HTTPRequest represents a JavaScript HTTP request configuration

type HTTPResponse

type HTTPResponse struct {
	Status     int               `json:"status"`
	StatusText string            `json:"statusText"`
	Headers    map[string]string `json:"headers"`
	Body       string            `json:"body"`
	JSON       interface{}       `json:"json"`
	OK         bool              `json:"ok"`
	URL        string            `json:"url"`
	Error      string            `json:"error,omitempty"`
}

HTTPResponse represents a JavaScript HTTP response

type HandlerInfo

type HandlerInfo struct {
	Fn          goja.Callable          // JavaScript function
	ContentType string                 // MIME type override
	Options     map[string]interface{} // Handler options (middleware, auth, etc.)
}

HandlerInfo contains handler function and metadata

type LogEntry

type LogEntry struct {
	Timestamp time.Time   `json:"timestamp"`
	Level     string      `json:"level"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data,omitempty"`
}

LogEntry represents a single log message during request processing

type RequestLog

type RequestLog struct {
	ID          string                 `json:"id"`
	Method      string                 `json:"method"`
	Path        string                 `json:"path"`
	URL         string                 `json:"url"`
	Status      int                    `json:"status"`
	StartTime   time.Time              `json:"startTime"`
	EndTime     time.Time              `json:"endTime"`
	Duration    time.Duration          `json:"duration"`
	Headers     map[string]interface{} `json:"headers"`
	Query       map[string]interface{} `json:"query"`
	Body        string                 `json:"body,omitempty"`
	Response    string                 `json:"response,omitempty"`
	Logs        []LogEntry             `json:"logs"`
	DatabaseOps []DatabaseOperation    `json:"databaseOps"`
	Error       string                 `json:"error,omitempty"`
	RemoteIP    string                 `json:"remoteIP"`
}

RequestLog represents a single request and its associated logs

type RequestLogger

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

RequestLogger manages request logging and provides real-time access

func NewRequestLogger

func NewRequestLogger(maxLogs int) *RequestLogger

NewRequestLogger creates a new request logger

func (*RequestLogger) AddDatabaseOperation

func (rl *RequestLogger) AddDatabaseOperation(requestID string, dbOp DatabaseOperation)

AddDatabaseOperation adds a database operation to a specific request

func (*RequestLogger) AddLog

func (rl *RequestLogger) AddLog(requestID, level, message string, data interface{})

AddLog adds a log entry to a specific request

func (*RequestLogger) ClearLogs

func (rl *RequestLogger) ClearLogs()

ClearLogs clears all request logs

func (*RequestLogger) FinishRequest

func (rl *RequestLogger) FinishRequest(requestID string, status int, response string, err error)

FinishRequest completes a request log entry

func (*RequestLogger) GetAllRequests

func (rl *RequestLogger) GetAllRequests() []*RequestLog

GetAllRequests returns all request logs in reverse chronological order

func (*RequestLogger) GetRecentRequests

func (rl *RequestLogger) GetRecentRequests(count int) []*RequestLog

GetRecentRequests returns the most recent N requests

func (*RequestLogger) GetRequestByID

func (rl *RequestLogger) GetRequestByID(requestID string) (*RequestLog, bool)

GetRequestByID returns a specific request log

func (*RequestLogger) GetStats

func (rl *RequestLogger) GetStats() map[string]interface{}

GetStats returns basic statistics about the logged requests

func (*RequestLogger) RequestLoggerMiddleware

func (rl *RequestLogger) RequestLoggerMiddleware(next http.HandlerFunc) http.HandlerFunc

RequestLoggerMiddleware creates an HTTP middleware that captures request logs

func (*RequestLogger) StartRequest

func (rl *RequestLogger) StartRequest(r *http.Request) *RequestLog

StartRequest creates a new request log entry

type ResponseRecorder

type ResponseRecorder struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseRecorder captures HTTP response for logging

func (*ResponseRecorder) Write

func (rr *ResponseRecorder) Write(b []byte) (int, error)

func (*ResponseRecorder) WriteHeader

func (rr *ResponseRecorder) WriteHeader(status int)

Jump to

Keyboard shortcuts

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