Documentation
¶
Overview ¶
Package tsengine provides async response utilities with event loop support.
Package tsengine provides shared bcrypt utilities for JavaScript runtime.
Package tsengine provides compiled JavaScript caching utilities.
Package tsengine provides TypeScript compilation utilities.
Package tsengine provides custom console implementation for JavaScript runtime.
Package tsengine provides shared crypto utilities for JavaScript runtime.
Package tsengine provides error handling utilities for TypeScript execution.
Package tsengine provides event loop management for async operations.
Package tsengine provides TypeScript execution capabilities for TurboScript.
This package implements a TypeScript execution engine using the goja JavaScript VM and esbuild for compilation. It provides a secure, sandboxed environment for executing TypeScript code with built-in utilities and performance optimizations.
Package tsengine provides file resolution utilities for TypeScript/JavaScript files.
Package tsengine provides Node.js compatibility modules for the goja runtime.
Package tsengine provides plugin utilities for the TypeScript execution engine.
Package tsengine provides response transformation utilities for TypeScript functions.
Package tsengine provides JavaScript runtime management utilities.
Package tsengine provides JavaScript runtime management utilities.
Package tsengine provides comprehensive stacktrace utilities for error debugging.
Package tsengine provides shared utilities for cache handling.
Package tsengine provides turboEmail utilities for email sending.
Package tsengine provides turboJob utilities for background job processing.
Package tsengine provides turboMarkdownHtml and turboHtml utilities for content processing.
Package tsengine provides shared utilities for database query handling.
Package tsengine provides JavaScript runtime management utilities.
Index ¶
- Constants
- func RegisterCustomConsole(rt *goja.Runtime)
- func RegisterNodeJSModules(rt *goja.Runtime, registry *require.Registry)
- func RegisterSharedBcryptModule(rt *goja.Runtime, registry *require.Registry)
- func RegisterSharedCryptoModule(rt *goja.Runtime, registry *require.Registry)
- func RegisterSharedPluginModule(rt *goja.Runtime, registry *require.Registry)
- type AsyncResponseUtils
- func (aru *AsyncResponseUtils) ExecuteHandleAsyncWithTimeout(tsPath string, event any, preserveResponse bool, timeoutSeconds int) (json.RawMessage, error)
- func (aru *AsyncResponseUtils) SetCacheConfig(cacheConfig *config.CacheConfig)
- func (aru *AsyncResponseUtils) SetDatabase(db *sql.DB)
- func (aru *AsyncResponseUtils) SetDatabaseManager(dbManager any)
- func (aru *AsyncResponseUtils) SetMarkdownBasePath(basePath string)
- func (aru *AsyncResponseUtils) SetServer(server interface{})
- func (aru *AsyncResponseUtils) StartEventLoop()
- func (aru *AsyncResponseUtils) TerminateEventLoop()
- type CacheUtils
- type CachedContent
- type CachedJS
- type CompilerUtils
- type DBJobManager
- type DataSource
- type DetailedError
- type ErrorUtils
- func (eu *ErrorUtils) CheckForDataSourcesError(resultStr, tsPath string) error
- func (eu *ErrorUtils) CheckForExecutionError(resultStr, tsPath string) error
- func (eu *ErrorUtils) CheckForTSExecutionError(resultStr, tsPath string) error
- func (eu *ErrorUtils) ProcessHandleError(errorData any, tsPath string) error
- func (eu *ErrorUtils) ProcessResponseHandlerError(errorData any, tsPath string) error
- type EventLoopManager
- func (elm *EventLoopManager) ClearInterval(interval *eventloop.Interval)
- func (elm *EventLoopManager) ClearTimeout(timer *eventloop.Timer)
- func (elm *EventLoopManager) InjectAsyncTurboBroadcast(rt *goja.Runtime) error
- func (elm *EventLoopManager) InjectAsyncTurboCache(rt *goja.Runtime, cacheUtils *TurboCacheUtils) error
- func (elm *EventLoopManager) InjectAsyncTurboEmail(rt *goja.Runtime) error
- func (elm *EventLoopManager) InjectAsyncTurboJob(rt *goja.Runtime) error
- func (elm *EventLoopManager) InjectAsyncTurboQuery(rt *goja.Runtime) error
- func (elm *EventLoopManager) RunAsyncWithCompletionTimeout(tsCode string, setupFn func(*goja.Runtime), timeoutSeconds int) (any, error)
- func (elm *EventLoopManager) RunOnLoop(fn func(*goja.Runtime)) bool
- func (elm *EventLoopManager) SetDatabase(db *sql.DB)
- func (elm *EventLoopManager) SetDatabaseManager(dbManager any)
- func (elm *EventLoopManager) SetInterval(fn func(*goja.Runtime), interval time.Duration) *eventloop.Interval
- func (elm *EventLoopManager) SetServer(server interface{})
- func (elm *EventLoopManager) SetTimeout(fn func(*goja.Runtime), timeout time.Duration) *eventloop.Timer
- func (elm *EventLoopManager) SetTurboCacheUtils(turboCacheUtils *TurboCacheUtils)
- func (elm *EventLoopManager) SetTurboEmailUtils(turboEmailUtils *TurboEmailUtils)
- func (elm *EventLoopManager) SetTurboJobUtils(turboJobUtils *TurboJobUtils)
- func (elm *EventLoopManager) Start()
- func (elm *EventLoopManager) Stop()
- func (elm *EventLoopManager) Terminate()
- type FileResolver
- type JSRuntime
- type JobManager
- type ResponseUtils
- type RuntimeUtils
- type StackTraceFrame
- type StackTraceUtils
- func (stu *StackTraceUtils) LogAndWrapError(err error, errorType, message string, context map[string]any) *DetailedError
- func (stu *StackTraceUtils) LogAndWrapErrorWithSource(err error, errorType, message, sourceLocation string, context map[string]any) *DetailedError
- func (stu *StackTraceUtils) NewError(errorType, message string, context map[string]any) *DetailedError
- func (stu *StackTraceUtils) NewErrorf(errorType, format string, args ...any) *DetailedError
- func (stu *StackTraceUtils) WrapError(err error, errorType, message string, context map[string]any) *DetailedError
- func (stu *StackTraceUtils) WrapErrorWithSource(err error, errorType, message, sourceLocation string, context map[string]any) *DetailedError
- func (stu *StackTraceUtils) WrapErrorf(err error, errorType string, format string, args ...any) *DetailedError
- type TSExecutor
- func (e *TSExecutor) ExecuteHandleAsyncWithTimeout(tsPath string, event map[string]any, timeoutSeconds int) (json.RawMessage, error)
- func (e *TSExecutor) ExecuteHandleAutoWithTimeout(tsPath string, event map[string]any, timeoutSeconds int) (json.RawMessage, error)
- func (e *TSExecutor) ResolveFile(filePath string) (string, error)
- func (e *TSExecutor) ResolveFileQuiet(filePath string) (string, error)
- func (e *TSExecutor) SetCacheConfig(cacheConfig *config.CacheConfig)
- func (e *TSExecutor) SetDatabase(db any)
- func (e *TSExecutor) SetDatabaseManager(dbManager any)
- func (e *TSExecutor) SetEmailService(emailService *email.Service)
- func (e *TSExecutor) SetJobManager(jobManager JobManager)
- func (e *TSExecutor) SetMarkdownBasePath(basePath string)
- func (e *TSExecutor) SetServer(server interface{})
- func (e *TSExecutor) TerminateAsync()
- type TSResult
- type TurboCacheUtils
- type TurboEmailUtils
- type TurboJobUtils
- type TurboMarkdownUtils
- type TurboQueryUtils
Constants ¶
const ( ErrorTypeUnknown = "Unknown TypeScript error" ErrorTypeExecution = "TypeScript execution error" ErrorTypeResponse = "TypeScript response handler error" ErrorTypeDataSource = "TypeScript data source error" )
Error type constants for TypeScript execution.
const ( ErrorTypeAsyncExecution = "AsyncExecution" ErrorTypeJSCompilation = "JSCompilation" ErrorTypeHandleFunction = "HandleFunction" ErrorTypeDatabaseQuery = "DatabaseQuery" ErrorTypeJobDispatch = "JobDispatch" ErrorTypeBroadcast = "Broadcast" ErrorTypeEmailService = "EmailService" ErrorTypeCacheOperation = "CacheOperation" ErrorTypeMarkdownProcessing = "MarkdownProcessing" ErrorTypeAuthVerification = "AuthVerification" ErrorTypeConfigurationLoad = "ConfigurationLoad" ErrorTypeFileSystem = "FileSystem" ErrorTypeNetworkOperation = "NetworkOperation" ErrorTypeValidation = "Validation" ErrorTypeTimeout = "Timeout" ErrorTypeResourceExhaustion = "ResourceExhaustion" )
Common error types for TurboScript.
const ( NullString = "null" UndefinedString = "undefined" JSONFormat = "json" )
Common string constants.
Variables ¶
This section is empty.
Functions ¶
func RegisterCustomConsole ¶
RegisterCustomConsole registers a custom console object that integrates with TurboScript logger.
This replaces the default goja_nodejs console with our own implementation that prefixes all console output with [CONSOLE] tags and routes them through our structured logging system.
func RegisterNodeJSModules ¶
RegisterNodeJSModules registers essential Node.js modules that argon2 and other packages need.
func RegisterSharedBcryptModule ¶
RegisterSharedBcryptModule registers a bcryptjs-compatible module in the goja runtime. This is a shared implementation to avoid code duplication across runtime utilities.
func RegisterSharedCryptoModule ¶
RegisterSharedCryptoModule registers the crypto module and all helpers in the goja runtime.
Types ¶
type AsyncResponseUtils ¶
type AsyncResponseUtils struct {
// contains filtered or unexported fields
}
AsyncResponseUtils handles TypeScript response execution with async support.
func NewAsyncResponseUtils ¶
func NewAsyncResponseUtils(cacheUtils *CacheUtils, runtimeUtils *RuntimeUtils, errorUtils *ErrorUtils) *AsyncResponseUtils
NewAsyncResponseUtils creates a new async response utilities instance.
func (*AsyncResponseUtils) ExecuteHandleAsyncWithTimeout ¶
func (aru *AsyncResponseUtils) ExecuteHandleAsyncWithTimeout(tsPath string, event any, preserveResponse bool, timeoutSeconds int) (json.RawMessage, error)
ExecuteHandleAsyncWithTimeout executes TypeScript handle function with async support and configurable timeout.
func (*AsyncResponseUtils) SetCacheConfig ¶
func (aru *AsyncResponseUtils) SetCacheConfig(cacheConfig *config.CacheConfig)
SetCacheConfig sets the cache configuration for turboCache operations.
func (*AsyncResponseUtils) SetDatabase ¶
func (aru *AsyncResponseUtils) SetDatabase(db *sql.DB)
SetDatabase sets the database connection.
func (*AsyncResponseUtils) SetDatabaseManager ¶
func (aru *AsyncResponseUtils) SetDatabaseManager(dbManager any)
SetDatabaseManager sets the database manager for multi-connection support.
func (*AsyncResponseUtils) SetMarkdownBasePath ¶
func (aru *AsyncResponseUtils) SetMarkdownBasePath(basePath string)
SetMarkdownBasePath sets the base path for turboMarkdownHtml function.
func (*AsyncResponseUtils) SetServer ¶
func (aru *AsyncResponseUtils) SetServer(server interface{})
SetServer sets the server reference for broadcasting capabilities.
func (*AsyncResponseUtils) StartEventLoop ¶
func (aru *AsyncResponseUtils) StartEventLoop()
StartEventLoop starts the event loop for async operations.
func (*AsyncResponseUtils) TerminateEventLoop ¶
func (aru *AsyncResponseUtils) TerminateEventLoop()
TerminateEventLoop terminates the event loop and cleans up resources.
type CacheUtils ¶
type CacheUtils struct {
// contains filtered or unexported fields
}
CacheUtils manages compiled JavaScript code caching.
func NewCacheUtils ¶
func NewCacheUtils(compiler *CompilerUtils) *CacheUtils
NewCacheUtils creates a new cache utilities instance.
func (*CacheUtils) ClearOldCache ¶
func (cu *CacheUtils) ClearOldCache(maxAge time.Duration)
ClearOldCache clears compilation cache entries older than the specified duration.
func (*CacheUtils) GetCompiledJS ¶
func (cu *CacheUtils) GetCompiledJS(tsPath string) (string, error)
GetCompiledJS gets compiled JavaScript with caching.
type CachedContent ¶
CachedContent holds processed content with metadata for caching.
type CompilerUtils ¶
type CompilerUtils struct {
// contains filtered or unexported fields
}
CompilerUtils provides utilities for TypeScript compilation.
func NewCompilerUtils ¶
func NewCompilerUtils() *CompilerUtils
NewCompilerUtils creates a new compiler utilities instance.
func NewCompilerUtilsWithConfig ¶
func NewCompilerUtilsWithConfig(cfg *config.TypeScriptCompilerConfig) *CompilerUtils
NewCompilerUtilsWithConfig creates a new compiler utilities instance with configuration.
func (*CompilerUtils) ConvertTSToJS ¶
func (c *CompilerUtils) ConvertTSToJS(tsPath string) (string, error)
ConvertTSToJS converts TypeScript to JavaScript with proper module resolution.
type DBJobManager ¶
type DBJobManager interface {
JobManager
DispatchJobWithReturn(jobPath string, payload map[string]any) (string, error)
}
DBJobManager extends the basic JobManager interface with database-specific methods. To avoid import cycles, we use a type assertion in ExecuteJob when a database job manager is detected.
type DataSource ¶
type DataSource struct {
Name string `json:"name"`
Source string `json:"source"`
SingleRecord bool `json:"single_record,omitempty"`
ExplicitNotFound bool `json:"explicit_not_found,omitempty"`
Query string `json:"query,omitempty"` // For database source
Params []any `json:"params,omitempty"` // For database source
URL string `json:"url,omitempty"` // For URL source
Method string `json:"method,omitempty"` // For URL source (default: GET)
Headers map[string]string `json:"headers,omitempty"` // For URL source
Body any `json:"body,omitempty"` // For URL source
Timeout int `json:"timeout,omitempty"` // For URL source (in milliseconds)
Key string `json:"key,omitempty"` // For Redis source
Pattern string `json:"pattern,omitempty"` // For Redis source
Command string `json:"command,omitempty"` // For Redis source
Path string `json:"path,omitempty"` // For file source
Format string `json:"format,omitempty"` // For file source
Encoding string `json:"encoding,omitempty"` // For file source
Endpoint string `json:"endpoint,omitempty"` // For API source
Auth map[string]any `json:"auth,omitempty"` // For API source
}
DataSource represents a data source configuration from TypeScript.
type DetailedError ¶
type DetailedError struct {
OriginalError error `json:"original_error"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
GoStackTrace []StackTraceFrame `json:"go_stacktrace"`
JSStackTrace string `json:"js_stacktrace,omitempty"`
Context map[string]any `json:"context,omitempty"`
ErrorType string `json:"error_type"`
SourceLocation string `json:"source_location,omitempty"`
RuntimeDebugInfo string `json:"runtime_debug_info,omitempty"`
}
DetailedError represents an enhanced error with full debugging information.
func (*DetailedError) Error ¶
func (de *DetailedError) Error() string
Error implements the error interface.
func (*DetailedError) String ¶
func (de *DetailedError) String() string
String provides a comprehensive string representation of the error.
type ErrorUtils ¶
type ErrorUtils struct{}
ErrorUtils handles various types of TypeScript execution errors.
func NewErrorUtils ¶
func NewErrorUtils() *ErrorUtils
NewErrorUtils creates a new error utilities instance.
func (*ErrorUtils) CheckForDataSourcesError ¶
func (eu *ErrorUtils) CheckForDataSourcesError(resultStr, tsPath string) error
CheckForDataSourcesError checks if the result string contains a data sources error.
func (*ErrorUtils) CheckForExecutionError ¶
func (eu *ErrorUtils) CheckForExecutionError(resultStr, tsPath string) error
CheckForExecutionError checks if the result string contains an execution error.
func (*ErrorUtils) CheckForTSExecutionError ¶
func (eu *ErrorUtils) CheckForTSExecutionError(resultStr, tsPath string) error
CheckForTSExecutionError checks if the result string contains a TypeScript execution error.
func (*ErrorUtils) ProcessHandleError ¶
func (eu *ErrorUtils) ProcessHandleError(errorData any, tsPath string) error
ProcessHandleError processes and formats errors from the handle function.
func (*ErrorUtils) ProcessResponseHandlerError ¶
func (eu *ErrorUtils) ProcessResponseHandlerError(errorData any, tsPath string) error
ProcessResponseHandlerError processes and formats errors from the response handler.
type EventLoopManager ¶
type EventLoopManager struct {
// contains filtered or unexported fields
}
EventLoopManager manages goja event loops for async operations.
func NewEventLoopManager ¶
func NewEventLoopManager() *EventLoopManager
NewEventLoopManager creates a new event loop manager.
func NewEventLoopManagerWithServer ¶
func NewEventLoopManagerWithServer(server interface{}) *EventLoopManager
NewEventLoopManagerWithServer creates a new event loop manager with server reference.
func (*EventLoopManager) ClearInterval ¶
func (elm *EventLoopManager) ClearInterval(interval *eventloop.Interval)
ClearInterval clears an interval.
func (*EventLoopManager) ClearTimeout ¶
func (elm *EventLoopManager) ClearTimeout(timer *eventloop.Timer)
ClearTimeout clears a timeout.
func (*EventLoopManager) InjectAsyncTurboBroadcast ¶
func (elm *EventLoopManager) InjectAsyncTurboBroadcast(rt *goja.Runtime) error
InjectAsyncTurboBroadcast injects the turboBroadcastWebSocket and turboBroadcastSSE functions.
func (*EventLoopManager) InjectAsyncTurboCache ¶
func (elm *EventLoopManager) InjectAsyncTurboCache(rt *goja.Runtime, cacheUtils *TurboCacheUtils) error
InjectAsyncTurboCache injects the async turboCache function into a runtime.
func (*EventLoopManager) InjectAsyncTurboEmail ¶
func (elm *EventLoopManager) InjectAsyncTurboEmail(rt *goja.Runtime) error
InjectAsyncTurboEmail injects the async turboEmail function into a runtime.
func (*EventLoopManager) InjectAsyncTurboJob ¶
func (elm *EventLoopManager) InjectAsyncTurboJob(rt *goja.Runtime) error
InjectAsyncTurboJob injects the async turboJob function into a runtime.
func (*EventLoopManager) InjectAsyncTurboQuery ¶
func (elm *EventLoopManager) InjectAsyncTurboQuery(rt *goja.Runtime) error
InjectAsyncTurboQuery injects the async turboQuery function into a runtime.
func (*EventLoopManager) RunAsyncWithCompletionTimeout ¶
func (elm *EventLoopManager) RunAsyncWithCompletionTimeout(tsCode string, setupFn func(*goja.Runtime), timeoutSeconds int) (any, error)
RunAsyncWithCompletionTimeout executes TypeScript code and waits for async completion with specified timeout.
func (*EventLoopManager) RunOnLoop ¶
func (elm *EventLoopManager) RunOnLoop(fn func(*goja.Runtime)) bool
RunOnLoop executes a function in the event loop context.
func (*EventLoopManager) SetDatabase ¶
func (elm *EventLoopManager) SetDatabase(db *sql.DB)
SetDatabase sets the database connection.
func (*EventLoopManager) SetDatabaseManager ¶
func (elm *EventLoopManager) SetDatabaseManager(dbManager any)
SetDatabaseManager sets the database manager for multi-connection support.
func (*EventLoopManager) SetInterval ¶
func (elm *EventLoopManager) SetInterval(fn func(*goja.Runtime), interval time.Duration) *eventloop.Interval
SetInterval provides setInterval functionality.
func (*EventLoopManager) SetServer ¶
func (elm *EventLoopManager) SetServer(server interface{})
SetServer sets the server reference for broadcasting.
func (*EventLoopManager) SetTimeout ¶
func (elm *EventLoopManager) SetTimeout(fn func(*goja.Runtime), timeout time.Duration) *eventloop.Timer
SetTimeout provides setTimeout functionality.
func (*EventLoopManager) SetTurboCacheUtils ¶
func (elm *EventLoopManager) SetTurboCacheUtils(turboCacheUtils *TurboCacheUtils)
SetTurboCacheUtils sets the turboCache utilities.
func (*EventLoopManager) SetTurboEmailUtils ¶
func (elm *EventLoopManager) SetTurboEmailUtils(turboEmailUtils *TurboEmailUtils)
SetTurboEmailUtils sets the turboEmail utilities.
func (*EventLoopManager) SetTurboJobUtils ¶
func (elm *EventLoopManager) SetTurboJobUtils(turboJobUtils *TurboJobUtils)
SetTurboJobUtils sets the turboJob utilities.
func (*EventLoopManager) Start ¶
func (elm *EventLoopManager) Start()
Start starts the event loop in background.
func (*EventLoopManager) Terminate ¶
func (elm *EventLoopManager) Terminate()
Terminate terminates the event loop and cleans up all resources.
type FileResolver ¶
type FileResolver struct {
// contains filtered or unexported fields
}
FileResolver provides intelligent file resolution for TypeScript/JavaScript files.
It automatically resolves file paths by checking for both .ts and .js extensions, with configurable preference for development (.ts) or production (.js) environments.
func GetRecommendedResolver ¶
func GetRecommendedResolver() *FileResolver
GetRecommendedResolver creates a file resolver with recommended settings based on environment.
Development: Prefers .ts files (for hot-reloading and debugging). Production: Prefers .js files (for compiled distributions).
func GetResolverFromConfig ¶
func GetResolverFromConfig(preferTS, preferJS bool) *FileResolver
GetResolverFromConfig creates a file resolver with settings from configuration.
The configuration can specify either prefer_ts or prefer_js. If prefer_ts is true, it takes precedence over prefer_js. If neither is set, it falls back to environment detection.
func NewFileResolver ¶
func NewFileResolver(preferJS bool) *FileResolver
NewFileResolver creates a new file resolver instance.
Parameters:
- preferJS: If true, prefer .js files over .ts files when both exist
func (*FileResolver) ResolveFile ¶
func (fr *FileResolver) ResolveFile(filePath string) (string, error)
ResolveFile intelligently resolves a file path to the correct TypeScript or JavaScript file.
Resolution Logic:
- If the provided path already has a .ts or .js extension, check if that file exists
- If not found or no extension provided, try both .ts and .js extensions
- Apply preference (development prefers .ts, production prefers .js)
- Return the first existing file found
Parameters:
- filePath: The file path to resolve (with or without extension)
Returns:
- The resolved absolute file path
- Error if no suitable file is found
func (*FileResolver) ResolveFileQuiet ¶
func (fr *FileResolver) ResolveFileQuiet(filePath string) (string, error)
ResolveFileQuiet is like ResolveFile but only logs at debug level to avoid noise.
type JobManager ¶
JobManager represents a job manager interface to avoid import cycles.
type ResponseUtils ¶
type ResponseUtils struct {
// contains filtered or unexported fields
}
ResponseUtils handles TypeScript handle function execution and response processing.
func NewResponseUtils ¶
func NewResponseUtils(cacheUtils *CacheUtils, runtimeUtils *RuntimeUtils, errorUtils *ErrorUtils) *ResponseUtils
NewResponseUtils creates a new response utilities instance.
func (*ResponseUtils) SetDatabase ¶
func (ru *ResponseUtils) SetDatabase(db *sql.DB)
SetDatabase sets the database connection for runQuery functionality.
func (*ResponseUtils) SetDatabaseManager ¶
func (ru *ResponseUtils) SetDatabaseManager(dbManager any)
SetDatabaseManager sets the database manager for multi-connection support.
func (*ResponseUtils) SetMarkdownBasePath ¶
func (ru *ResponseUtils) SetMarkdownBasePath(basePath string)
SetMarkdownBasePath sets the base path for turboMarkdownHtml function.
type RuntimeUtils ¶
type RuntimeUtils struct {
// contains filtered or unexported fields
}
RuntimeUtils handles JavaScript runtime pool management and module registration.
func NewRuntimeUtils ¶
func NewRuntimeUtils() *RuntimeUtils
NewRuntimeUtils creates a new runtime utilities instance.
type StackTraceFrame ¶
type StackTraceFrame struct {
Function string `json:"function"`
File string `json:"file"`
Line int `json:"line"`
Package string `json:"package"`
}
StackTraceFrame represents a single frame in a stacktrace.
type StackTraceUtils ¶
type StackTraceUtils struct{}
StackTraceUtils provides utilities for creating detailed error reports with stacktraces.
func NewStackTraceUtils ¶
func NewStackTraceUtils() *StackTraceUtils
NewStackTraceUtils creates a new stacktrace utilities instance.
func (*StackTraceUtils) LogAndWrapError ¶
func (stu *StackTraceUtils) LogAndWrapError(err error, errorType, message string, context map[string]any) *DetailedError
LogAndWrapError logs the error with full details and returns a wrapped error.
func (*StackTraceUtils) LogAndWrapErrorWithSource ¶
func (stu *StackTraceUtils) LogAndWrapErrorWithSource(err error, errorType, message, sourceLocation string, context map[string]any) *DetailedError
LogAndWrapErrorWithSource logs the error with source location and returns a wrapped error.
func (*StackTraceUtils) NewError ¶
func (stu *StackTraceUtils) NewError(errorType, message string, context map[string]any) *DetailedError
NewError creates a new detailed error without wrapping an existing error.
func (*StackTraceUtils) NewErrorf ¶
func (stu *StackTraceUtils) NewErrorf(errorType, format string, args ...any) *DetailedError
NewErrorf creates a new detailed error with formatted message.
func (*StackTraceUtils) WrapError ¶
func (stu *StackTraceUtils) WrapError(err error, errorType, message string, context map[string]any) *DetailedError
WrapError wraps an error with comprehensive debugging information.
func (*StackTraceUtils) WrapErrorWithSource ¶
func (stu *StackTraceUtils) WrapErrorWithSource(err error, errorType, message, sourceLocation string, context map[string]any) *DetailedError
WrapErrorWithSource wraps an error with source location and comprehensive debugging information.
func (*StackTraceUtils) WrapErrorf ¶
func (stu *StackTraceUtils) WrapErrorf(err error, errorType string, format string, args ...any) *DetailedError
WrapErrorf wraps an error with formatted message and debugging information.
type TSExecutor ¶
type TSExecutor struct {
// contains filtered or unexported fields
}
TSExecutor provides TypeScript code execution capabilities with modular architecture. It separates concerns into specialized utilities for better maintainability.
func NewIsolatedTSExecutor ¶
func NewIsolatedTSExecutor(preserveResponse bool) *TSExecutor
NewIsolatedTSExecutor creates a completely isolated TypeScript executor instance specifically for background jobs and email processing to prevent interference with HTTP request processing.
func NewIsolatedTSExecutorWithResolver ¶
func NewIsolatedTSExecutorWithResolver(preserveResponse bool, fileResolver *FileResolver) *TSExecutor
NewIsolatedTSExecutorWithResolver creates an isolated TypeScript executor with a custom file resolver.
func NewIsolatedTSExecutorWithResolverAndConfig ¶
func NewIsolatedTSExecutorWithResolverAndConfig(preserveResponse bool, fileResolver *FileResolver, tsConfig *config.TypeScriptCompilerConfig) *TSExecutor
NewIsolatedTSExecutorWithResolverAndConfig creates an isolated TypeScript executor with a custom file resolver and TypeScript configuration.
func (*TSExecutor) ExecuteHandleAsyncWithTimeout ¶
func (e *TSExecutor) ExecuteHandleAsyncWithTimeout(tsPath string, event map[string]any, timeoutSeconds int) (json.RawMessage, error)
ExecuteHandleAsyncWithTimeout calls the handle function with async support and configurable timeout.
func (*TSExecutor) ExecuteHandleAutoWithTimeout ¶
func (e *TSExecutor) ExecuteHandleAutoWithTimeout(tsPath string, event map[string]any, timeoutSeconds int) (json.RawMessage, error)
ExecuteHandleAutoWithTimeout automatically chooses sync or async execution with configurable timeout.
func (*TSExecutor) ResolveFile ¶
func (e *TSExecutor) ResolveFile(filePath string) (string, error)
ResolveFile resolves a TypeScript/JavaScript file path using the configured file resolver.
func (*TSExecutor) ResolveFileQuiet ¶
func (e *TSExecutor) ResolveFileQuiet(filePath string) (string, error)
ResolveFileQuiet resolves a file path quietly (minimal logging).
func (*TSExecutor) SetCacheConfig ¶
func (e *TSExecutor) SetCacheConfig(cacheConfig *config.CacheConfig)
SetCacheConfig sets the cache configuration for turboCache operations.
func (*TSExecutor) SetDatabase ¶
func (e *TSExecutor) SetDatabase(db any)
SetDatabase sets the database connection for both sync and async execution.
func (*TSExecutor) SetDatabaseManager ¶
func (e *TSExecutor) SetDatabaseManager(dbManager any)
SetDatabaseManager sets the database manager for both sync and async execution.
func (*TSExecutor) SetEmailService ¶
func (e *TSExecutor) SetEmailService(emailService *email.Service)
SetEmailService sets the email service for email sending.
func (*TSExecutor) SetJobManager ¶
func (e *TSExecutor) SetJobManager(jobManager JobManager)
SetJobManager sets the job manager for background job processing.
func (*TSExecutor) SetMarkdownBasePath ¶
func (e *TSExecutor) SetMarkdownBasePath(basePath string)
SetMarkdownBasePath sets the base path for markdown and HTML file resolution.
func (*TSExecutor) SetServer ¶
func (e *TSExecutor) SetServer(server interface{})
SetServer sets the server reference for broadcasting capabilities.
func (*TSExecutor) TerminateAsync ¶
func (e *TSExecutor) TerminateAsync()
TerminateAsync terminates the async event loop and cleans up resources.
type TSResult ¶
type TSResult struct {
Operation string `json:"operation"`
Table string `json:"table"`
RawQuery string `json:"query"`
Params []any `json:"params"`
SingleRecord bool `json:"single_record"`
ExplicitNotFound bool `json:"explicit_not_found"`
NoQueryFunction bool `json:"__no_query_function"`
}
TSResult represents the result of executing a TypeScript query function.
This structure contains the database operation details returned by TypeScript code, including the SQL query, parameters, and execution flags.
type TurboCacheUtils ¶
type TurboCacheUtils struct {
// contains filtered or unexported fields
}
TurboCacheUtils provides shared turboCache functionality and drivers.
func NewTurboCacheUtils ¶
func NewTurboCacheUtils(cacheConfig *config.CacheConfig) *TurboCacheUtils
NewTurboCacheUtils creates a new turboCache utilities instance with configuration.
func (*TurboCacheUtils) ParseTurboCacheArgs ¶
func (tcu *TurboCacheUtils) ParseTurboCacheArgs(call goja.FunctionCall, _ *goja.Runtime) (key string, value any, ttl int64, driver string, op string, err error)
ParseTurboCacheArgs parses turboCache arguments and returns key, value, ttl, driver, and operation.
type TurboEmailUtils ¶
type TurboEmailUtils struct {
// contains filtered or unexported fields
}
TurboEmailUtils provides shared turboEmail functionality.
func NewTurboEmailUtils ¶
func NewTurboEmailUtils(emailService *email.Service) *TurboEmailUtils
NewTurboEmailUtils creates a new turboEmail utilities instance.
func (*TurboEmailUtils) SendEmail ¶
func (teu *TurboEmailUtils) SendEmail(call goja.FunctionCall, rt *goja.Runtime) goja.Value
SendEmail sends an email using the configured email service. This function is used by both sync and async turboEmail implementations. It handles parameter parsing, email validation, and email sending.
Parameters:
- call: The goja function call containing email configuration
- rt: The goja runtime for error reporting
Returns:
- goja.Value: A promise that resolves when the email is sent
type TurboJobUtils ¶
type TurboJobUtils struct {
// contains filtered or unexported fields
}
TurboJobUtils provides shared turboJob functionality.
func NewTurboJobUtils ¶
func NewTurboJobUtils(jobManager JobManager) *TurboJobUtils
NewTurboJobUtils creates a new turboJob utilities instance.
func (*TurboJobUtils) ExecuteJob ¶
func (tju *TurboJobUtils) ExecuteJob(call goja.FunctionCall, rt *goja.Runtime) goja.Value
ExecuteJob dispatches a background job for processing. This function is used by both sync and async turboJob implementations. It handles parameter parsing, job validation, and job dispatching.
Parameters:
- call: The goja function call containing job path and payload
- rt: The goja runtime for error reporting
Returns:
- goja.Value: A promise that resolves when the job is queued
type TurboMarkdownUtils ¶
type TurboMarkdownUtils struct {
// contains filtered or unexported fields
}
TurboMarkdownUtils handles markdown and HTML processing for TypeScript functions.
func NewTurboMarkdownUtils ¶
func NewTurboMarkdownUtils(basePath string) *TurboMarkdownUtils
NewTurboMarkdownUtils creates a new turbo markdown utilities instance.
func (*TurboMarkdownUtils) ExecuteHTML ¶
func (tmu *TurboMarkdownUtils) ExecuteHTML(call goja.FunctionCall, rt *goja.Runtime) goja.Value
ExecuteHTML processes HTML content with template substitution and returns HTML.
func (*TurboMarkdownUtils) ExecuteMarkdownHTML ¶
func (tmu *TurboMarkdownUtils) ExecuteMarkdownHTML(call goja.FunctionCall, rt *goja.Runtime) goja.Value
ExecuteMarkdownHTML processes markdown content and returns HTML.
func (*TurboMarkdownUtils) SetBasePath ¶
func (tmu *TurboMarkdownUtils) SetBasePath(basePath string)
SetBasePath sets the base path for resolving relative file paths.
type TurboQueryUtils ¶
type TurboQueryUtils struct {
}
TurboQueryUtils provides shared turboQuery functionality.
func NewTurboQueryUtils ¶
func NewTurboQueryUtils() *TurboQueryUtils
NewTurboQueryUtils creates a new turboQuery utilities instance.
func (*TurboQueryUtils) ExecuteQuery ¶
func (tqu *TurboQueryUtils) ExecuteQuery(call goja.FunctionCall, rt *goja.Runtime, db *sql.DB, dbManager any, debugPrefix string) goja.Value
ExecuteQuery executes a database query and returns the results as a Goja value.
This method provides shared database query execution functionality for both sync and async turboQuery implementations. It handles parameter parsing, query execution, result processing, and error handling in a consistent manner.
Supports two call formats:
- Default: turboQuery(query, params) - uses default connection
- Object: turboQuery({query, bindings?, connection?}) - supports connection switching
Parameters:
- call: The Goja function call containing query and parameters
- rt: The JavaScript runtime for value conversion and error handling
- db: Default database connection to use for legacy calls or when no manager is available
- dbManager: Database manager for multi-connection support (optional)
- debugPrefix: Prefix for debug logging to distinguish call sources
Returns a Goja value containing the query results (array of objects) or throws a JavaScript error if the query fails or database is unavailable.
func (*TurboQueryUtils) ParseTurboQueryArgs ¶
func (tqu *TurboQueryUtils) ParseTurboQueryArgs(call goja.FunctionCall, _ *goja.Runtime) (string, []any, string, error)
ParseTurboQueryArgs parses turboQuery arguments and returns query, params, and connection name. Supports both legacy format turboQuery(query, params) and object format turboQuery({query, bindings?, connection?}).
Source Files
¶
- async_response_utils.go
- bcrypt_utils.go
- cache_utils.go
- compiler_utils.go
- console_utils.go
- crypto_utils.go
- error_utils.go
- eventloop_manager.go
- executor.go
- file_resolver.go
- nodejs_compat.go
- plugin_utils.go
- response_utils.go
- result.go
- runtime_utils.go
- stacktrace_utils.go
- turbocache_utils.go
- turboemail_utils.go
- turbojob_utils.go
- turbomarkdown_utils.go
- turboquery_utils.go
- types.go