Documentation
¶
Index ¶
- Constants
- func EvaluateExpr(code string) (string, error)
- func ToMap(v any) (map[string]any, bool)
- func ToNative(v any) any
- type APIRequest
- type APIResult
- type APIRouteRuntime
- type ISRCacheEntry
- type ISRPageInfo
- type MiddlewareRequest
- type MiddlewareResult
- type MiddlewareRuntime
- type Runtime
- func (r *Runtime) Call(function string, args ...any) (any, error)
- func (r *Runtime) CallValue(function string, args ...any) (quickjs.Value, error)
- func (r *Runtime) Close() error
- func (r *Runtime) DrainJobs()
- func (r *Runtime) Execute(code string) (any, error)
- func (r *Runtime) ExecuteModule(code string) (any, error)
- func (r *Runtime) GetGlobal(name string) (any, error)
- func (r *Runtime) RegisterFunc(name string, f func(args []any) (any, error)) error
- func (r *Runtime) RegisterFuncWithThis(name string, f func(this quickjs.Value, args []any) (any, error)) error
- func (r *Runtime) SetEnv(env map[string]string) error
- func (r *Runtime) SetGlobal(name string, value any) error
- func (r *Runtime) VM() *quickjs.VM
- type RuntimeComponentResult
- type RuntimeComponentRuntime
- type SSRManifest
- type SSRPageManifest
- type SSRPageRequest
- type SSRPageResponse
- type SSRRuntime
- func (s *SSRRuntime) ClearBundleCache()
- func (s *SSRRuntime) FindPageForRoute(urlPath string) (*SSRPageManifest, map[string]string)
- func (s *SSRRuntime) GetISRPages() []ISRPageInfo
- func (s *SSRRuntime) GetRuntimeJS() string
- func (s *SSRRuntime) GetStylesheet() string
- func (s *SSRRuntime) Invalidate(route string)
- func (s *SSRRuntime) IsISRPage(route string) bool
- func (s *SSRRuntime) IsRunning() bool
- func (s *SSRRuntime) IsSSRPage(route string) bool
- func (s *SSRRuntime) IsStreamingPage(route string) bool
- func (s *SSRRuntime) LoadManifest() error
- func (s *SSRRuntime) RenderPage(req SSRPageRequest) (*SSRPageResponse, error)
Constants ¶
const ( // EvalGlobal evaluates in the global scope EvalGlobal = quickjs.EvalGlobal // EvalModule evaluates as an ES module EvalModule = quickjs.EvalModule )
Variables ¶
This section is empty.
Functions ¶
func EvaluateExpr ¶
EvaluateExpr evaluates a self-contained JS expression in a fresh QuickJS VM and returns its String() representation. Because QuickJS is a full ECMAScript engine, every built-in (Date, Math, String, Number, Array, Object, ...) is available — so SSR evaluation of globals like Date.now() produces a genuine JS-engine value rather than a Go approximation. Returns an error when the expression throws (e.g. it references an identifier that isn't defined).
Types ¶
type APIRequest ¶
type APIRequest struct {
URL string `json:"url"`
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
}
APIRequest is the input to an API route handler
type APIResult ¶
type APIResult struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Error string `json:"error"`
}
APIResult is the output of an API route handler
type APIRouteRuntime ¶
type APIRouteRuntime struct {
// contains filtered or unexported fields
}
APIRouteRuntime executes compiled API routes via embedded quickjs
func NewAPIRouteRuntime ¶
func NewAPIRouteRuntime(apiDir string) *APIRouteRuntime
NewAPIRouteRuntime creates a new API route runtime
func (*APIRouteRuntime) Execute ¶
func (a *APIRouteRuntime) Execute(req APIRequest) APIResult
Execute runs the API route handler for the given path
type ISRCacheEntry ¶
ISRCacheEntry holds a cached ISR page render.
type ISRPageInfo ¶
ISRPageInfo describes an ISR page with its revalidation interval.
type MiddlewareRequest ¶
type MiddlewareRequest struct {
URL string `json:"url"`
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
}
MiddlewareRequest is the input to the middleware function
type MiddlewareResult ¶
type MiddlewareResult struct {
Action string `json:"action"`
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Error string `json:"error"`
}
MiddlewareResult is the output of the middleware function
type MiddlewareRuntime ¶
type MiddlewareRuntime struct {
// contains filtered or unexported fields
}
MiddlewareRuntime executes middleware.ts via embedded quickjs
func LoadMiddlewareRuntime ¶
func LoadMiddlewareRuntime(root string) *MiddlewareRuntime
LoadMiddlewareRuntime loads the middleware.js and returns a runtime, or nil if no middleware
func NewMiddlewareRuntime ¶
func NewMiddlewareRuntime(middlewarePath string) (*MiddlewareRuntime, error)
NewMiddlewareRuntime creates a new middleware runtime and loads the middleware.js
func (*MiddlewareRuntime) Close ¶
func (m *MiddlewareRuntime) Close()
Close releases the runtime resources
func (*MiddlewareRuntime) Execute ¶
func (m *MiddlewareRuntime) Execute(req MiddlewareRequest) MiddlewareResult
Execute runs the middleware with the given request and returns the result
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime wraps a quickjs VM with krate-specific Web API polyfills
func (*Runtime) DrainJobs ¶
func (r *Runtime) DrainJobs()
DrainJobs executes pending promise jobs (microtasks). Call after Execute to resolve promises.
func (*Runtime) ExecuteModule ¶
ExecuteModule evaluates JavaScript code as an ES module
func (*Runtime) RegisterFunc ¶
RegisterFunc registers a Go function as a global JS function
func (*Runtime) RegisterFuncWithThis ¶
func (r *Runtime) RegisterFuncWithThis(name string, f func(this quickjs.Value, args []any) (any, error)) error
RegisterFuncWithThis registers a Go function that receives the this object
type RuntimeComponentResult ¶
type RuntimeComponentResult struct {
HTML string `json:"html"`
Error string `json:"error,omitempty"`
}
RuntimeComponentResult is the output of a runtime component render.
type RuntimeComponentRuntime ¶
type RuntimeComponentRuntime struct {
// contains filtered or unexported fields
}
RuntimeComponentRuntime executes compiled runtime component bundles via embedded quickjs. Each component is a standalone IIFE that defines globalThis.__krate_render(propsJSON).
func NewRuntimeComponentRuntime ¶
func NewRuntimeComponentRuntime(componentDir string) *RuntimeComponentRuntime
NewRuntimeComponentRuntime creates a runtime for executing compiled runtime components.
func (*RuntimeComponentRuntime) ClearCache ¶
func (r *RuntimeComponentRuntime) ClearCache()
ClearCache removes all cached bundle code. Call during dev mode hot reload when a *.runtime.tsx file changes to force re-read from disk.
func (*RuntimeComponentRuntime) RenderComponent ¶
func (r *RuntimeComponentRuntime) RenderComponent(componentName, propsJSON string) RuntimeComponentResult
RenderComponent executes a compiled runtime component bundle and returns the HTML. componentName is used to locate the <name>.runtime.js file in the component directory. propsJSON is a JSON string of props to pass to the component function.
func (*RuntimeComponentRuntime) RenderComponentAsync ¶
func (r *RuntimeComponentRuntime) RenderComponentAsync(componentName, propsJSON string) RuntimeComponentResult
RenderComponentAsync is like RenderComponent but supports async components. It drains the microtask queue after execution to resolve any promises.
type SSRManifest ¶
type SSRManifest struct {
Pages []SSRPageManifest `json:"pages"`
Stylesheet string `json:"stylesheet,omitempty"`
RuntimeJS string `json:"runtimeJS,omitempty"`
RuntimeComponents []SSRPageManifest `json:"runtimeComponents,omitempty"`
}
SSRManifest is the on-disk manifest for embedded SSR.
type SSRPageManifest ¶
type SSRPageManifest struct {
Route string `json:"route"`
BundlePath string `json:"bundlePath"` // IIFE bundle relative to outDir
Mode string `json:"mode"` // ssr, isr, streaming
Revalidate int `json:"revalidate,omitempty"`
}
SSRPageManifest describes a page that can be rendered at serve time.
type SSRPageRequest ¶
type SSRPageRequest struct {
Route string `json:"route"`
URL string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
Params map[string]string `json:"params"`
Query map[string]string `json:"query"`
}
SSRPageRequest is the input for rendering a page via QuickJS.
type SSRPageResponse ¶
type SSRPageResponse struct {
HTML string `json:"html"`
HeadHTML string `json:"headHTML,omitempty"`
ScriptHTML string `json:"scriptHTML,omitempty"`
Status int `json:"status"`
Redirect string `json:"redirect,omitempty"`
NotFound bool `json:"notFound,omitempty"`
}
SSRPageResponse is the output from rendering a page via QuickJS.
type SSRRuntime ¶
type SSRRuntime struct {
// contains filtered or unexported fields
}
SSRRuntime renders pages via embedded QuickJS, replacing the Node.js sidecar.
func NewSSRRuntime ¶
func NewSSRRuntime(root, outDir string) *SSRRuntime
NewSSRRuntime creates an embedded SSR runtime from the manifest.
func (*SSRRuntime) ClearBundleCache ¶
func (s *SSRRuntime) ClearBundleCache()
ClearBundleCache removes all cached bundles. Call during dev mode hot reload.
func (*SSRRuntime) FindPageForRoute ¶
func (s *SSRRuntime) FindPageForRoute(urlPath string) (*SSRPageManifest, map[string]string)
FindPageForRoute matches a URL path against route patterns and returns the page + params.
func (*SSRRuntime) GetISRPages ¶
func (s *SSRRuntime) GetISRPages() []ISRPageInfo
GetISRPages returns all ISR pages and their revalidation intervals.
func (*SSRRuntime) GetRuntimeJS ¶
func (s *SSRRuntime) GetRuntimeJS() string
GetRuntimeJS returns the shared runtime chunk path.
func (*SSRRuntime) GetStylesheet ¶
func (s *SSRRuntime) GetStylesheet() string
GetStylesheet returns the global CSS filename.
func (*SSRRuntime) Invalidate ¶
func (s *SSRRuntime) Invalidate(route string)
Invalidate removes the ISR cache for a route.
func (*SSRRuntime) IsISRPage ¶
func (s *SSRRuntime) IsISRPage(route string) bool
IsISRPage checks if a route uses ISR.
func (*SSRRuntime) IsRunning ¶
func (s *SSRRuntime) IsRunning() bool
IsRunning returns true if the manifest is loaded.
func (*SSRRuntime) IsSSRPage ¶
func (s *SSRRuntime) IsSSRPage(route string) bool
IsSSRPage checks if a route requires server-side rendering.
func (*SSRRuntime) IsStreamingPage ¶
func (s *SSRRuntime) IsStreamingPage(route string) bool
IsStreamingPage checks if a route uses streaming SSR.
func (*SSRRuntime) LoadManifest ¶
func (s *SSRRuntime) LoadManifest() error
LoadManifest reads the SSR manifest from the output directory.
func (*SSRRuntime) RenderPage ¶
func (s *SSRRuntime) RenderPage(req SSRPageRequest) (*SSRPageResponse, error)
RenderPage renders a page via QuickJS and returns the response.